Missing Indexes in the Query Store

I’ve shown before how to use the DMVs that read the plan cache as a way to connect the missing indexes suggestions with specific queries, but the other place to find missing index suggestions is the Query Store.

Pulling from the Query Store

The plans stored in the Query Store are exactly the same as the plans stored within the plan cache. This means that the XML is available and you can try to retrieve information from it directly, just as we did with the missing index queries against the DMVs. Here’s the query modified for the Query Store:

A couple of notes on the query. I cast the query_plan as xml so that I can use the XQuery to pull out the information. It is possible that the plan might be so large that you get an error because of the limit on nesting levels within XML. Also, I aggregate the information from the sys.query_store_runttime_stats. You may want to modify this to only look at limited ranges. I’ll leave that to you as an exercise.

Conclusion

If you take that query as written and run it on a production database, it’s likely to cause some problems since there is no filtering in place. So, I strongly recommend before using this, you plan on filtering by query, object or text. However, once you do, this returns the query, the plan, and the missing indexes information.


If you want to learn more about how the Query Store works, I have an opportunity for you. I have a couple of upcoming all day seminars that include the Query Store as well as other tools built into SQL Server, all focused around making it easier for your to identify and tune queries:

SQL Day, May 13, 2019, Wroclaw, Poland
SQLSaturday Columbus Precon, June 7 2019, Columbus OH

2 thoughts on “Missing Indexes in the Query Store

Please let me know what you think about this article or any questions:

This site uses Akismet to reduce spam. Learn how your comment data is processed.