{"id":72010,"date":"2017-08-07T06:25:22","date_gmt":"2017-08-07T06:25:22","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=72010"},"modified":"2021-08-24T13:39:23","modified_gmt":"2021-08-24T13:39:23","slug":"monitoring-unmatchedindexes-warning","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/monitoring-unmatchedindexes-warning\/","title":{"rendered":"Monitoring UnmatchedIndexes Warning"},"content":{"rendered":"<p>If you are using filtered indexes in SQL Server, it worthwhile monitoring the <strong>UnmatchedIndexes<\/strong> warning, it can give us very interesting insights.<\/p>\n<p>Filtered indexes and parameterized queries are terrible enemies. I explained a bit about parameterized queries in my article about <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/database-administration\/query-store-parameterization-problems\/\">how to identify them using query store<\/a>, you can read it <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/database-administration\/query-store-parameterization-problems\/\">here<\/a>.<\/p>\n<p>When a parameterized query is compiled, <strong>SQL Server<\/strong> is unable to take into account the value of the parameter. Of course, it&#8217;s a bit more complicated than that, but I will not dig into all the details in this blog. The main problem is that, because it cannot take into account the parameter value, the query plan has to be optimized for every value.<\/p>\n<p>Filtered indexes, on the other hand, doesn&#8217;t contain all the possible values of a key, because they are filtered. The obvious result of this is that parameterized queries can&#8217;t use filtered indexes because they don&#8217;t fit any possible value.<\/p>\n<p>Here comes the warning: When a filtered index could be used for a query if it wasn&#8217;t parameterized, the warning appears in the execution plan. Due to that, this warning advises us that a parameterized query could perform better if it wasn&#8217;t parameterized.<\/p>\n<p>Let&#8217;s illustrate with an example using the <em>&#8216;adventureworks&#8217;<\/em> sample database: You can download this database <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=49502\">here<\/a>.<\/p>\n<p>The table <strong>production.transactionhistory<\/strong> is very good for our example. There are three different types of transactions, specified by the <em>&#8216;TransactionType&#8217;<\/em> field, making this a good candidate for a filtered index. Let&#8217;s create one:<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">USE<\/span>\u00a0<span style=\"color: maroon;\">adventureworks2016<\/span> <br \/>\n <span style=\"color: maroon;\">go<\/span> <\/p>\n<p> <span style=\"color: blue;\">CREATE<\/span>\u00a0<span style=\"color: blue;\">NONCLUSTERED<\/span>\u00a0<span style=\"color: blue;\">INDEX<\/span>\u00a0<span style=\"color: maroon;\">indquantityfilter<\/span> <br \/>\n \u00a0\u00a0<span style=\"color: blue;\">ON<\/span>\u00a0<span style=\"color: maroon;\">production<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">transactionhistory<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">quantity<\/span><span style=\"color: maroon;\">)<\/span> <br \/>\n \u00a0\u00a0<span style=\"color: maroon;\">include<\/span>\u00a0<span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">transactiondate<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">transactiontype<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: blue;\">WHERE<\/span>\u00a0<span style=\"color: maroon;\">transactiontype<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: red;\">&#8216;P&#8217;<\/span> <br \/>\n <span style=\"color: maroon;\">go<\/span>\u00a0 <\/span><\/div>\n<p>&nbsp;<\/p>\n<p>Now we can test some queries, one by one, checking their query plans:<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">SELECT<\/span>\u00a0<span style=\"color: maroon;\">transactionid<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">transactiondate<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span> <br \/>\n <span style=\"color: blue;\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon;\">production<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">transactionhistory<\/span> <br \/>\n <span style=\"color: blue;\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span>\u00a0<span style=\"color: silver;\">&lt;<\/span>\u00a0<span style=\"color: black;\">10<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue;\">AND<\/span>\u00a0<span style=\"color: maroon;\">transactiontype<\/span>\u00a0<span style=\"color: silver;\">=<\/span>\u00a0<span style=\"color: red;\">N&#8217;P&#8217;<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72011\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/08\/UnmatchedIndexes1.png\" alt=\"query with filtered index\" width=\"538\" height=\"177\" \/><\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">SELECT<\/span>\u00a0<span style=\"color: maroon;\">transactionid<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">transactiondate<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span> <br \/>\n <span style=\"color: blue;\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon;\">production<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">transactionhistory<\/span> <br \/>\n <span style=\"color: blue;\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span>\u00a0<span style=\"color: silver;\">&lt;<\/span>\u00a0<span style=\"color: black;\">10<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue;\">AND<\/span>\u00a0<span style=\"color: maroon;\">transactiontype<\/span>\u00a0<span style=\"color: silver;\">=<\/span>\u00a0<span style=\"color: red;\">N&#8217;S&#8217;<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72012\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/08\/UnmatchedIndexes2.png\" alt=\"query without filtered index\" width=\"511\" height=\"201\" \/><\/p>\n<p>The first query will use the filtered index, the second won&#8217;t, because of the predicate value. None of these queries are parameterized.<\/p>\n<p>Let&#8217;s try with a parameterized query:<\/p>\n<p>&nbsp;<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">DECLARE<\/span>\u00a0<span style=\"color: #8000ff;\">@value<\/span>\u00a0<span style=\"color: black; font-style: italic;\">NCHAR<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: red;\">&#8216;P&#8217;<\/span> <\/p>\n<p> <span style=\"color: blue;\">SELECT<\/span>\u00a0<span style=\"color: maroon;\">transactionid<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">transactiondate<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span> <br \/>\n <span style=\"color: blue;\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon;\">production<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">transactionhistory<\/span> <br \/>\n <span style=\"color: blue;\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span>\u00a0<span style=\"color: silver;\">&lt;<\/span>\u00a0<span style=\"color: black;\">10<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue;\">AND<\/span>\u00a0<span style=\"color: maroon;\">transactiontype<\/span>\u00a0<span style=\"color: silver;\">=<\/span>\u00a0<span style=\"color: #8000ff;\">@value<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72013\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/08\/UnmatchedIndexes3.png\" alt=\"query with warning\" width=\"483\" height=\"194\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72014\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/08\/UnmatchedIndexes4.png\" alt=\"warning in property window\" width=\"424\" height=\"208\" \/><\/p>\n<p>This time the filtered index isn&#8217;t used, although it could, and we get a warning, exactly the <strong>UnmatchedIndexes<\/strong> warning.<\/p>\n<p>If we include the <strong>Recompile<\/strong> hint, <strong>SQL Server<\/strong> will be able to consider the parameter value and use the filtered index, like below:<\/p>\n<p>&nbsp;<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">DECLARE<\/span>\u00a0<span style=\"color: #8000ff;\">@valor<\/span>\u00a0<span style=\"color: black; font-style: italic;\">NCHAR<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: red;\">&#8216;P&#8217;<\/span> <\/p>\n<p> <span style=\"color: blue;\">SELECT<\/span>\u00a0<span style=\"color: maroon;\">transactionid<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">transactiondate<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span> <br \/>\n <span style=\"color: blue;\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon;\">production<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">transactionhistory<\/span> <br \/>\n <span style=\"color: blue;\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon;\">quantity<\/span>\u00a0<span style=\"color: silver;\">&lt;<\/span>\u00a0<span style=\"color: black;\">10<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue;\">AND<\/span>\u00a0<span style=\"color: maroon;\">transactiontype<\/span>\u00a0<span style=\"color: silver;\">=<\/span>\u00a0<span style=\"color: #8000ff;\">@valor<\/span> <br \/>\n <span style=\"color: blue;\">OPTION<\/span>\u00a0<span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">recompile<\/span><span style=\"color: maroon;\">)<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72015\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/08\/UnmatchedIndexes5.png\" alt=\"query with recompile\" width=\"490\" height=\"175\" \/><\/p>\n<p>Hints such as <strong>Recompile<\/strong> can be used even with <strong>Entity Framework<\/strong>, I explained this in a recent article, you can read <a href=\"https:\/\/www.red-gate.com\/simple-talk\/dotnet\/net-development\/using-sql-server-query-hints-entity-framework\/\">here<\/a>.<\/p>\n<p>The question is how to identify the queries that could be improved with a hint. Again, I already explained how to find query plan warnings in a previous article (<a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/t-sql-programming\/checking-the-plan-cache-warnings-for-a-sql-server-database\/\">here<\/a>), but this one is different, it needs a different query.<\/p>\n<p>While other warnings appear in the XML query plan as an element below the\u00a0<em>&#8216;Warnings&#8217;<\/em> element, this one appears as an attribute of the <em>&#8216;Warnings&#8217;<\/em> element, so the query I exposed in my previous article can&#8217;t catch this one.<\/p>\n<p>Making some slight changes and we are ready to go and find these warnings:<\/p>\n<p>&nbsp;<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">WITH<\/span>\u00a0<span style=\"color: maroon;\">xmlnamespaces<\/span>\u00a0<span style=\"color: maroon;\">(<\/span><span style=\"color: blue;\">DEFAULT<\/span> <br \/>\n <span style=\"color: red;\">&#8216;http:\/\/schemas.microsoft.com\/sqlserver\/2004\/07\/showplan&#8217;<\/span><span style=\"color: maroon;\">)<\/span> <\/p>\n<p> <span style=\"color: blue;\">SELECT<\/span> <br \/>\n <span style=\"color: maroon;\">[text]<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n <span style=\"color: maroon;\">query_plan<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: #ff0080; font-weight: bold;\">value<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: red;\">&#8216;((\/\/UnmatchedIndexes)[1]\/Parameterization\/Object\/@Schema)[1]&#8217;<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: red;\">&#8216;varchar(100)&#8217;<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: blue;\">AS<\/span>\u00a0<span style=\"color: maroon;\">[Schema]<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n <span style=\"color: maroon;\">query_plan<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: #ff0080; font-weight: bold;\">value<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: red;\">&#8216;((\/\/UnmatchedIndexes)[1]\/Parameterization\/Object\/@Table)[1]&#8217;<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: red;\">&#8216;varchar(100)&#8217;<\/span><span style=\"color: maroon;\">)<\/span>\u00a0\u00a0<span style=\"color: blue;\">AS<\/span>\u00a0<span style=\"color: maroon;\">[Table]<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n <span style=\"color: maroon;\">query_plan<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: #ff0080; font-weight: bold;\">value<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: red;\">&#8216;((\/\/UnmatchedIndexes)[1]\/Parameterization\/Object\/@Index)[1]&#8217;<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: red;\">&#8216;varchar(100)&#8217;<\/span><span style=\"color: maroon;\">)<\/span>\u00a0\u00a0<span style=\"color: blue;\">AS<\/span>\u00a0<span style=\"color: maroon;\">[Index]<\/span> <br \/>\n <span style=\"color: blue;\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon;\">dbo<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: #ff0080; font-weight: bold;\">Plancachefromdatabase<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: red;\">&#8216;AdventureWorks2016&#8217;<\/span><span style=\"color: maroon;\">)<\/span> <br \/>\n <span style=\"color: blue;\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon;\">query_plan<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: #ff0080; font-weight: bold;\">exist<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: red;\">&#8216;\/\/UnmatchedIndexes&#8217;<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: silver;\">=<\/span>\u00a0<span style=\"color: black;\">1<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72016\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/08\/UnmatchedIndexes6.png\" alt=\"UnmatchedIndexes from plan cache\" width=\"715\" height=\"110\" \/><\/p>\n<p>I&#8217;m using the &#8216;planCacheFromDatabase&#8217; function that I explained in a previous article, the code of this function is the following:<\/p>\n<p>&nbsp;<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">CREATE<\/span>\u00a0<span style=\"color: blue;\">FUNCTION<\/span>\u00a0<span style=\"color: maroon;\">[dbo]<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">[planCachefromDatabase]<\/span>\u00a0<span style=\"color: maroon;\">(<\/span> <br \/>\n <span style=\"color: green;\"><i>&#8212;\u00a0Add\u00a0the\u00a0parameters\u00a0for\u00a0the\u00a0function\u00a0here<\/i><\/span> <br \/>\n <span style=\"color: #8000ff;\">@DatabaseName<\/span>\u00a0<span style=\"color: black;\"><i>VARCHAR<\/i><\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: black;\">50<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: maroon;\">)<\/span> <br \/>\n <span style=\"color: maroon;\">returns<\/span>\u00a0<span style=\"color: blue;\">TABLE<\/span>\u00a0<span style=\"color: blue;\">AS<\/span> <br \/>\n <span style=\"color: blue;\">RETURN<\/span>\u00a0<span style=\"color: maroon;\">(<\/span>\u00a0<span style=\"color: blue;\">WITH<\/span>\u00a0<span style=\"color: maroon;\">xmlnamespaces<\/span>\u00a0<span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">default<\/span>\u00a0<span style=\"color: red;\">&#8216;http:\/\/schemas.microsoft.com\/sqlserver\/2004\/07\/showplan&#8217;<\/span><span style=\"color: maroon;\">)<\/span> <br \/>\n <span style=\"color: blue;\">SELECT<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">qp<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">query_plan<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">qt<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">text<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">statement_start_offset<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">statement_end_offset<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">creation_time<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">last_execution_time<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">execution_count<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">total_worker_time<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">last_worker_time<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">min_worker_time<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">max_worker_time<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">total_physical_reads<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">last_physical_reads<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">min_physical_reads<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">max_physical_reads<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">total_logical_writes<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">last_logical_writes<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">min_logical_writes<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">max_logical_writes<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">total_logical_reads<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">last_logical_reads<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">min_logical_reads<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">max_logical_reads<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">total_elapsed_time<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">last_elapsed_time<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">min_elapsed_time<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">max_elapsed_time<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">total_rows<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">last_rows<\/span><span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">min_rows<\/span><span style=\"color: silver;\">,<\/span> <br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">max_rows<\/span> <br \/>\n <span style=\"color: blue;\">FROM<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">sys<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">dm_exec_query_stats<\/span> <br \/>\n <span style=\"color: blue;\">CROSS<\/span>\u00a0<span style=\"color: maroon;\">apply<\/span>\u00a0<span style=\"color: maroon;\">sys<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">dm_exec_sql_text<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">sql_handle<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: maroon;\">qt<\/span> <br \/>\n <span style=\"color: blue;\">CROSS<\/span>\u00a0<span style=\"color: maroon;\">apply<\/span>\u00a0<span style=\"color: maroon;\">sys<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">dm_exec_query_plan<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">plan_handle<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: maroon;\">qp<\/span> <br \/>\n <span style=\"color: blue;\">WHERE<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon;\">qp<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">dbid<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: maroon;\">db_id<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: #8000ff;\">@DatabaseName<\/span><span style=\"color: maroon;\">)<\/span>\u00a0<span style=\"color: maroon;\">)<\/span> <\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are using filtered indexes in SQL Server, it worthwhile monitoring the UnmatchedIndexes warning, it can give us very interesting insights. Filtered indexes and parameterized queries are terrible enemies. I explained a bit about parameterized queries in my article about how to identify them using query store, you can read it here. When a&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,143527],"tags":[4364],"coauthors":[6810],"class_list":["post-72010","post","type-post","status-publish","format-standard","hentry","category-blogs","category-database-administration-sql-server","tag-monitoring"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/72010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=72010"}],"version-history":[{"count":3,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/72010\/revisions"}],"predecessor-version":[{"id":72236,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/72010\/revisions\/72236"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=72010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=72010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=72010"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=72010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}