Press "Enter" to skip to content

Query Store And Dropped Objects

Grant Fritchey gives us a potential nightmare scenario with Query Store:

Along comes our aggressive junior DBA who decides that there are “too many” indexes on the server. No, I don’t know what that means either, but they evidently read it on the internet or something so they drop the index we created before:

1
DROP INDEX TransactionOccurredWhenNCI ON Warehouse.StockItemTransactions;

What now happens to our lovely execution plan and the plan forcing? We’ll take a look at two events in Extended Events, sql_statement_recompile and query_store_plan_forcing_failed. Nothing happens immediately on dropping the index. The plans associated with that object, if any, are marked as invalid in the cache. The next time we call the query it’s going to recompile and we can see the event:

The result is a bit happier than I would have expected; I was looking forward to a “and the world came crashing down” conclusion.

2 Comments

  1. Grant Fritchey
    Grant Fritchey2016-08-16

    I’d say that overall it was a very happy conclusion. It shows good architecture and approach by Microsoft. I really thought we might see a recompile for every execution. That would have been horrifying.

    • Kevin Feasel
      Kevin Feasel2016-08-16

      Recompilation for each execution would have been terrible, I agree. My first thought when reading your post, though, was that dropping the index would have resulted in every execution of the query failing, sort of like when you have a procedure with an index hint specified.

Comments are closed.