Skip to content

sp_BlitzCache @SlowlySearchPlansFor not producing reliable results when looking for missing indexes #2202

Closed
@BrentOzar

Description

@BrentOzar

Version of the script
SELECT @Version = '7.9', @VersionDate = '20191024';

What is the current behavior?
If I search for the exact plans producing a missing index recommendation, I'm not getting them. Logging where I'm at so far in the troubleshooting process:

DBCC FREEPROCCACHE;
GO
SELECT Id FROM dbo.Users WHERE DisplayName = 'Brent Ozar';
GO 5

/* The missing index hint in the plan will look like this: */
<MissingIndex Database="[StackOverflow]" Schema="[dbo]" Table="[Users]">
                  <ColumnGroup Usage="EQUALITY">
                    <Column Name="[DisplayName]" ColumnId="5" />



/* This search produces results: */
sp_BlitzCache @SlowlySearchPlansFor = '<MissingIndex Database="[StackOverflow]" Schema="[dbo]" Table="[Users]">%<ColumnGroup Usage="EQUALITY">%<Column Name="[DisplayName]" ColumnId="5"', @Debug = 1
GO

/* But as soon as you add the space after the ColumnId number, it doesn't: */
sp_BlitzCache @SlowlySearchPlansFor = '<MissingIndex Database="[StackOverflow]" Schema="[dbo]" Table="[Users]">%<ColumnGroup Usage="EQUALITY">%<Column Name="[DisplayName]" ColumnId="5" ', @Debug = 1
GO



/* It doesn't appear to be a search string length problem either - here, I'm using a different column & length: */
DBCC FREEPROCCACHE;
GO
SELECT Id FROM dbo.Users WHERE Location = 'Brent Ozar';
GO 5

/* The missing index hint in the plan will look like this: */
<MissingIndex Database="[StackOverflow]" Schema="[dbo]" Table="[Users]">
                  <ColumnGroup Usage="EQUALITY">
                    <Column Name="[Location]" ColumnId="9" />



/* This search produces results: */
sp_BlitzCache @SlowlySearchPlansFor = '<MissingIndex Database="[StackOverflow]" Schema="[dbo]" Table="[Users]">%<ColumnGroup Usage="EQUALITY">%<Column Name="[Location]" ColumnId="9"', @Debug = 1
GO

/* But as soon as you add the space after the ColumnId number, it doesn't: */
sp_BlitzCache @SlowlySearchPlansFor = '<MissingIndex Database="[StackOverflow]" Schema="[dbo]" Table="[Users]">%<ColumnGroup Usage="EQUALITY">%<Column Name="[Location]" ColumnId="9" ', @Debug = 1
GO

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions