Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Server 2019: dm_db_missing_index_group_stats_query DMV #2185

Closed
erikdarlingdata opened this issue Nov 5, 2019 · 12 comments · Fixed by #2861
Closed

SQL Server 2019: dm_db_missing_index_group_stats_query DMV #2185

erikdarlingdata opened this issue Nov 5, 2019 · 12 comments · Fixed by #2861

Comments

@erikdarlingdata
Copy link
Contributor

Is your feature request related to a problem? Please describe.
SQL Server 2019 introduced a new DMV, called dm_db_missing_index_group_stats_query that includes some interesting columns. It's not documented so far, but it provides some information that can be used to tie missing index requests to queries.

image

Describe the solution you'd like
I'd like to get this added, but I'm not sure which script it makes more sense in, because it involves a crossover.

Either:

  • BlitzCache would have to peep in missing index DMVs, or
  • BlitzIndex would have to peep at the plan cache for query bits.

Describe alternatives you've considered

  • This isn't a replacement for dm_db_missing_index_group_stats because it clears out when query plans go away
  • Adding a query_more_info column to BlitzIndex is simple but maybe feels incomplete
  • Tying it to how BlitzCache parses plan XML to produce missing indexes would be ugly
  • Extending the @Mode = 3 output of BlitzIndex to run a simple plan cache query would probably be doable, but it'd have to either be entirely dynamic, or dump into a #temp table with a dynamic update

Are you ready to build the code for the feature?
Yes, when there's a decision on approach.

@erikdarlingdata
Copy link
Contributor Author

Any feedback on this from out there in the world?

@EmanueleMeazzo
Copy link
Contributor

Better late than ever, but I would add it to BlitzIndex in order to quickly get an idea about the queries that boop the index

@BrentOzar
Copy link
Member

Erik - do you still wanna do this? If not, I'll close it.

@erikdarlingdata
Copy link
Contributor Author

Yeah, totally. I was hoping for some more feedback on it from the community, but I'll figure something out.

BrentOzar added a commit that referenced this issue Oct 16, 2020
Adds a sample query plan to Mode 3 out put and table-level output. Working on #2185.
BrentOzar added a commit that referenced this issue Oct 16, 2020
…g_index_query_plans

#2185 sp_BlitzIndex missing index plans
@BrentOzar
Copy link
Member

I added a first step on it. The #MissingIndexes table now has a sample_query_plan column. I'm taking the:

  • Top 1 row from sys.dm_db_missing_index_group_stats_query order by (q.user_seeks + q.user_scans) desc
  • Top 1 row from sys.dm_exec_query_stats order by total_logical_reads desc

This particular PLAN may not actually be the one that's producing the missing index request - but the QUERY should be the same. If you've got multiple queries producing the plan, this isn't going to give you all of them either, just one as a starting point.

If you call sp_Blitz @TableName = 'Users', the missing index section has this sample plan at the far right.

If you call sp_Blitz @mode = 3, this is a new column on the far right.

Things left that someone else can do if they want:

  • Add it to Mode 0 & 4
  • Add an sp_BlitzCache call with the query plan hashes (rather than just getting the one top plan)

@BrentOzar
Copy link
Member

Just making a note in here in case anybody tries to test this - the current state is a disaster, and it almost never shows the right query. I have fixing to do in there.

@BrentOzar
Copy link
Member

Just FYI for readers - Erik asked Microsoft to document the DMV: https://github.com/MicrosoftDocs/sql-docs/issues/5862

@erikdarlingdata
Copy link
Contributor Author

It's going really well, too 😔

@BrentOzar
Copy link
Member

@erikdarlingdata
Copy link
Contributor Author

I was reviewing this and think I found the issue.

Everything was okay, except where the outer correlation is:

image

If I change it to this, it seems to bring back the correct query plan:

image

But I'm willing to concede that it has been a long Sunday and I'm missing something obvious.

@erikdarlingdata
Copy link
Contributor Author

oh, wait, the inner correlation is correct. if we just get rid of the outer one all together it's fine.

@BrentOzar
Copy link
Member

Eureka! That's it. Nice work, sir. Merging into the dev branch, will be in the April release with credit to you in the release notes.

@BrentOzar BrentOzar linked a pull request Apr 12, 2021 that will close this issue
@BrentOzar BrentOzar added this to the 2021-04 Release milestone Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants