I am trying to run some analysis on missing indexes on a server (I haven't ever done it on this server before). I was running sp_blitzindex and it would hang up on "Inserting data into #MissingIndexes." I dug into the query and found where it hits sys.dm_db_missing_index_details.
Trying to select from sys.dm_db_missing_index_details will return about 300 records, and then it'll sit and spin. I didn't want to let it keep going to see how long it would take to finish, but I let it run for over two minutes and it didn't complete.
Why would this take a long time to return? What would cause this?
Best Answer
This sounds like other sessions are blocking the dynamic management view.
CREATE TABLE
andDROP TABLE
force an update to the internal tables maintained for thesys.dm_db_missing_index_details
.I was able to recreate a blocking scenario where an open transaction prevents reads against
sys.dm_db_missing_index_details
. Run this in an SSMS window on your development machine:Now, in another SSMS window, run the following (you may need to run it several times depending on how quick you are!)
For me, the above query blocks until I either commit or rollback the transaction started in the first query window, with:
or
Unfortunately, running
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
prior to queryingsys.dm_db_missing_index_details
does not help; it still blocks until the open transaction commits or rolls back.