{"id":909,"date":"2009-03-27T07:28:00","date_gmt":"2009-03-27T07:28:00","guid":{"rendered":"\/blogs\/paul\/post\/Index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds!.aspx"},"modified":"2013-01-01T23:56:14","modified_gmt":"2013-01-02T07:56:14","slug":"index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/","title":{"rendered":"Index rebuilds depend on stats, which are updated by index rebuilds?!?"},"content":{"rendered":"<p>\n<font face=\"verdana,geneva\" size=\"2\">Jack Li, one of the Senior Escalation Engineers in Product Support, just posted details of an interesting case over on the <\/font><a href=\"http:\/\/blogs.msdn.com\/b\/psssql\/\"><font face=\"verdana,geneva\" size=\"2\">CSS blog<\/font><\/a><font face=\"verdana,geneva\" size=\"2\">&nbsp;&#8211; his article is <\/font><a href=\"http:\/\/blogs.msdn.com\/b\/psssql\/archive\/2009\/03\/18\/be-aware-of-parallel-index-creation-performance-issues.aspx\"><font face=\"verdana,geneva\" size=\"2\">here<\/font><\/a><font face=\"verdana,geneva\" size=\"2\">. It talks about index builds and rebuilds, but the issue is the same for both, so I&#39;ll just talk about rebuilds. <\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">The jist of the problem is that index rebuilds can parallelize, but sometimes they don&#39;t parallelize vey well. Each thread gets a certain range of the index to rebuild, using the existing index statistics to divide the ranges equally between the threads. If there&#39;s massive data skew, then one thread can end up doing the majority of the work, leading to a long run-time. The case in Jack&#39;s post involved a 250 million row index where 150 million rows had the same (NULL) key value. This range has to be processed by a single thread &#8211; a single value can&#39;t be divided between two+ threads. <\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">Now, this is understandable behavior by the database engine, but it relies on the statistics being up-to-date. That&#39;s a bit of a catch-22 &#8211; rebuilding an index updates the statistics, but if the statistics aren&#39;t up-to-date then the index rebuild might parallelize badly! I guess the solution is that if you know that you have massive data skew in your large indexes, update statistics BEFORE doing an index rebuild. And given what I&#39;ve been hearing this week at SQL Connections about how badly statistics keep biting people,&nbsp;I&#39;m leaning towards a different recommendation for those people who have lots of perf trouble caused by statistics and the potential for skewed data&nbsp;&#8211; rebuild all your statistics regularly, and only rebuild\/reorganize fragmented indexes. Statistics just cause so many problems it seems. <\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">Thanks <\/font>\n<\/p>\n<p>\n<font size=\"2\">PS Kimberly has a lot more info about statistics over on her blog &#8211; I&#39;m just starting to venture into that mine-field<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jack Li, one of the Senior Escalation Engineers in Product Support, just posted details of an interesting case over on the CSS blog&nbsp;&#8211; his article is here. It talks about index builds and rebuilds, but the issue is the same for both, so I&#39;ll just talk about rebuilds. The jist of the problem is that [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,42,47,52,90],"tags":[],"class_list":["post-909","post","type-post","status-publish","format-standard","hentry","category-database-maintenance","category-fragmentation","category-indexes-from-every-angle","category-involuntary-dba","category-statistics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Index rebuilds depend on stats, which are updated by index rebuilds?!? - Paul S. Randal<\/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\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Index rebuilds depend on stats, which are updated by index rebuilds?!? - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"Jack Li, one of the Senior Escalation Engineers in Product Support, just posted details of an interesting case over on the CSS blog&nbsp;&#8211; his article is here. It talks about index builds and rebuilds, but the issue is the same for both, so I&#039;ll just talk about rebuilds. The jist of the problem is that [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2009-03-27T07:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-02T07:56:14+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/\",\"name\":\"Index rebuilds depend on stats, which are updated by index rebuilds?!? - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2009-03-27T07:28:00+00:00\",\"dateModified\":\"2013-01-02T07:56:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Index rebuilds depend on stats, which are updated by index rebuilds?!?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Index rebuilds depend on stats, which are updated by index rebuilds?!? - Paul S. Randal","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\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/","og_locale":"en_US","og_type":"article","og_title":"Index rebuilds depend on stats, which are updated by index rebuilds?!? - Paul S. Randal","og_description":"Jack Li, one of the Senior Escalation Engineers in Product Support, just posted details of an interesting case over on the CSS blog&nbsp;&#8211; his article is here. It talks about index builds and rebuilds, but the issue is the same for both, so I&#39;ll just talk about rebuilds. The jist of the problem is that [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/","og_site_name":"Paul S. Randal","article_published_time":"2009-03-27T07:28:00+00:00","article_modified_time":"2013-01-02T07:56:14+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/","name":"Index rebuilds depend on stats, which are updated by index rebuilds?!? - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2009-03-27T07:28:00+00:00","dateModified":"2013-01-02T07:56:14+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/index-rebuilds-depend-on-stats-which-are-updated-by-index-rebuilds\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Index rebuilds depend on stats, which are updated by index rebuilds?!?"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=909"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/909\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}