{"id":497,"date":"2012-04-26T07:32:00","date_gmt":"2012-04-26T07:32:00","guid":{"rendered":"\/blogs\/joe\/post\/Exceptionse28093what-sysdm_db_index_usage_stats-doesnt-tell-you-(Part-II).aspx"},"modified":"2013-01-02T20:31:57","modified_gmt":"2013-01-03T04:31:57","slug":"exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/","title":{"rendered":"Exceptions\u2013what sys.dm_db_index_usage_stats doesn&#8217;t tell you (Part II)"},"content":{"rendered":"<p>\nLast November I blogged about how index usage stats don&rsquo;t get updated when the <a href=\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you\/\" target=\"_blank\">associated index statistics (but not index) are used<\/a>.\n<\/p>\n<p>\nThis post will describe another scenario that you should be aware of (the topic came up today in class while Kimberly was teaching &ndash; as we were trying to recall tricks to clearing stats for sys.dm_db_index_usage_stats)&hellip;\n<\/p>\n<p>\nImagine that I&rsquo;ve queried a specific table as follows:\n<\/p>\n<blockquote>\n<p>\n\tSELECT member_no, lastname, firstname, middleinitial, street, city, state_prov, country <br \/>\n\tFROM dbo.member <br \/>\n\tWHERE member_no = 1;\n\t<\/p>\n<\/blockquote>\n<p>\nIf I check sys.dm_db_index_usage_stats for any reference to the member table, I&rsquo;ll see the following:\n<\/p>\n<blockquote>\n<p>\n\tSELECT i.index_id, i.name, u.user_seeks, u.user_lookups, u.user_scans <br \/>\n\tFROM sys.dm_db_index_usage_stats u <br \/>\n\tINNER JOIN sys.indexes i ON <br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; u.object_id = i.object_id AND <br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; u.index_id = i.index_id <br \/>\n\tWHERE u.object_id=object_id(&#39;dbo.member&#39;)\n\t<\/p>\n<\/blockquote>\n<p>\nThis returns:\n<\/p>\n<p>\n<a href=\"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/windows-live-writer\/exc.dm_db_index_usage_stats-doesnt-tell-\/601c8650\/image.png\"><img decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px\" src=\"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/windows-live-writer\/exc.dm_db_index_usage_stats-doesnt-tell-\/6a0177bb\/image_thumb.png\" border=\"0\" alt=\"image\" title=\"image\" width=\"548\" height=\"38\" \/><\/a>\n<\/p>\n<p>\nNow let&rsquo;s say that you have a weekly rebuild of specific indexes (for example):\n<\/p>\n<blockquote>\n<p>\n\tALTER INDEX member_ident <br \/>\n\tON dbo.member REBUILD\n\t<\/p>\n<\/blockquote>\n<p>\nIf I check for usage stats after rebuilding the query (and before anyone has accessed the member table specifically) &ndash; the stats have been cleared out for that table.&nbsp;\n<\/p>\n<p>\n<a href=\"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/windows-live-writer\/exc.dm_db_index_usage_stats-doesnt-tell-\/502d418c\/image.png\"><img decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px\" src=\"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/windows-live-writer\/exc.dm_db_index_usage_stats-doesnt-tell-\/768f24d7\/image_thumb.png\" border=\"0\" alt=\"image\" title=\"image\" width=\"518\" height=\"43\" \/><\/a>\n<\/p>\n<p>\nWhy does this matter?&nbsp;\n<\/p>\n<p>\nIf you&rsquo;re using the sys.dm_db_index_usage_stats to determine which indexes should be removed, you&rsquo;re running the risk of making decisions based on recently cleared out statistics.&nbsp; This is similar to the case where a SQL Server instance has been recently restarted.&nbsp; You should not be dropping indexes without knowing whether the accumulated statistics represent the full set of critical workloads.&nbsp;\n<\/p>\n<p>\nFor tables with frequent index rebuilds, be sure to capture data from sys.dm_db_index_usage_stats before these jobs run.&nbsp; This DMV is definitely a useful tool, but if you&rsquo;re not careful, you could be dropping indexes based on missing information.\n<\/p>\n<p>\nA few other noteworthy items:\n<\/p>\n<ul>\n<li>Rebuilding an index only clears the stats for the index involved.&nbsp; For example &ndash; if I have two rows in the DMV for two different indexes on the same object, rebuilding one index will only clear stats for that object.<\/li>\n<li>Reorganizing the index does NOT clear the stats from sys.dm_db_index_usage_stats.<\/li>\n<li>This is not the only circumstance where the stats will clear.<\/li>\n<li>I have only tested this recently on SQL Server 2008 R2 and SQL Server 2012.&nbsp; At one point when I was at Microsoft I blogged about seeing the stats persist after a REBUILD (more in the context of REBUILD itself &ndash; and I had mentioned the DMV in passing).&nbsp; Which makes me think that perhaps this behavior wasn&rsquo;t always the case.&nbsp; If you&rsquo;ve found a different behavior on different versions, please post your comment here.<\/li>\n<\/ul>\n<p>\nThanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last November I blogged about how index usage stats don&rsquo;t get updated when the associated index statistics (but not index) are used. This post will describe another scenario that you should be aware of (the topic came up today in class while Kimberly was teaching &ndash; as we were trying to recall tricks to clearing [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,28],"tags":[],"class_list":["post-497","post","type-post","status-publish","format-standard","hentry","category-indexing","category-performance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Exceptions\u2013what sys.dm_db_index_usage_stats doesn&#039;t tell you (Part II) - Joe Sack<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exceptions\u2013what sys.dm_db_index_usage_stats doesn&#039;t tell you (Part II) - Joe Sack\" \/>\n<meta property=\"og:description\" content=\"Last November I blogged about how index usage stats don&rsquo;t get updated when the associated index statistics (but not index) are used. This post will describe another scenario that you should be aware of (the topic came up today in class while Kimberly was teaching &ndash; as we were trying to recall tricks to clearing [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/\" \/>\n<meta property=\"og:site_name\" content=\"Joe Sack\" \/>\n<meta property=\"article:published_time\" content=\"2012-04-26T07:32:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-03T04:31:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/windows-live-writer\/exc.dm_db_index_usage_stats-doesnt-tell-\/6a0177bb\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Joseph Sack\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph Sack\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/\",\"name\":\"Exceptions\u2013what sys.dm_db_index_usage_stats doesn't tell you (Part II) - Joe Sack\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#website\"},\"datePublished\":\"2012-04-26T07:32:00+00:00\",\"dateModified\":\"2013-01-03T04:31:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Indexing\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/category\/indexing\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Exceptions\u2013what sys.dm_db_index_usage_stats doesn&#8217;t tell you (Part II)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/\",\"name\":\"Joe Sack\",\"description\":\"SQL Server Performance Tuning, High Availability and Disaster Recovery Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648\",\"name\":\"Joseph Sack\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g\",\"caption\":\"Joseph Sack\"},\"description\":\"Joe Sack is a Principal Consultant with SQLskills. He has worked as a SQL Server professional since 1997 and has supported and developed for SQL Server environments in financial services, IT consulting, manufacturing, retail and the real estate industry. Prior to joining SQLskills he worked at Microsoft as a Premier Field Engineer supporting very large enterprise customer environments. He was responsible for providing deep SQL Server advisory services, training, troubleshooting and ongoing solutions guidance. His areas of expertise include performance tuning, scalability, T-SQL development and high-availability. In 2006 Joe earned the \u201cMicrosoft Certified Master: SQL Server 2005\u201d certification and in 2008 he earned the \u201cMicrosoft Certified Master: SQL Server 2008\u201d certification. In 2009 he took over responsibility for the entire SQL Server Microsoft Certified Master program and held that post until 2011. He was given the SQL Server MVP award in 2013.\",\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/joe\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/josephsack\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/author\/joe\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Exceptions\u2013what sys.dm_db_index_usage_stats doesn't tell you (Part II) - Joe Sack","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/","og_locale":"en_US","og_type":"article","og_title":"Exceptions\u2013what sys.dm_db_index_usage_stats doesn't tell you (Part II) - Joe Sack","og_description":"Last November I blogged about how index usage stats don&rsquo;t get updated when the associated index statistics (but not index) are used. This post will describe another scenario that you should be aware of (the topic came up today in class while Kimberly was teaching &ndash; as we were trying to recall tricks to clearing [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/","og_site_name":"Joe Sack","article_published_time":"2012-04-26T07:32:00+00:00","article_modified_time":"2013-01-03T04:31:57+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/windows-live-writer\/exc.dm_db_index_usage_stats-doesnt-tell-\/6a0177bb\/image_thumb.png"}],"author":"Joseph Sack","twitter_misc":{"Written by":"Joseph Sack","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/","url":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/","name":"Exceptions\u2013what sys.dm_db_index_usage_stats doesn't tell you (Part II) - Joe Sack","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#website"},"datePublished":"2012-04-26T07:32:00+00:00","dateModified":"2013-01-03T04:31:57+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/exceptions-what-sys-dm_db_index_usage_stats-doesnt-tell-you-part-ii\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/joe\/"},{"@type":"ListItem","position":2,"name":"Indexing","item":"https:\/\/www.sqlskills.com\/blogs\/joe\/category\/indexing\/"},{"@type":"ListItem","position":3,"name":"Exceptions\u2013what sys.dm_db_index_usage_stats doesn&#8217;t tell you (Part II)"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/joe\/","name":"Joe Sack","description":"SQL Server Performance Tuning, High Availability and Disaster Recovery Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/joe\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648","name":"Joseph Sack","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g","caption":"Joseph Sack"},"description":"Joe Sack is a Principal Consultant with SQLskills. He has worked as a SQL Server professional since 1997 and has supported and developed for SQL Server environments in financial services, IT consulting, manufacturing, retail and the real estate industry. Prior to joining SQLskills he worked at Microsoft as a Premier Field Engineer supporting very large enterprise customer environments. He was responsible for providing deep SQL Server advisory services, training, troubleshooting and ongoing solutions guidance. His areas of expertise include performance tuning, scalability, T-SQL development and high-availability. In 2006 Joe earned the \u201cMicrosoft Certified Master: SQL Server 2005\u201d certification and in 2008 he earned the \u201cMicrosoft Certified Master: SQL Server 2008\u201d certification. In 2009 he took over responsibility for the entire SQL Server Microsoft Certified Master program and held that post until 2011. He was given the SQL Server MVP award in 2013.","sameAs":["http:\/\/3.209.169.194\/blogs\/joe","https:\/\/twitter.com\/https:\/\/twitter.com\/josephsack"],"url":"https:\/\/www.sqlskills.com\/blogs\/joe\/author\/joe\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/posts\/497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/comments?post=497"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/posts\/497\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/media?parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/categories?post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/tags?post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}