{"id":581,"date":"2008-02-05T08:06:00","date_gmt":"2008-02-05T08:06:00","guid":{"rendered":"\/blogs\/kimberly\/post\/Statistics-query-plans-and-are-you-reading-Conors-blog.aspx"},"modified":"2013-01-11T23:12:08","modified_gmt":"2013-01-12T07:12:08","slug":"statistics-query-plans-and-are-you-reading-conors-blog","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/statistics-query-plans-and-are-you-reading-conors-blog\/","title":{"rendered":"Statistics, query plans, and are you reading Conor&#8217;s blog?"},"content":{"rendered":"<p>\nI know that Paul and I recommended that you subscribe to <a href=\"http:\/\/www.SQLskills.com\/blogs\/conor\/\" class=\"broken_link\">Conor&#39;s blog<\/a>&#8230; but have you? He&#39;s posted some great details on Partitioning (<a href=\"https:\/\/www.sqlskills.com\/blogs\/conor\/2008\/02\/01\/anintroductiontopartitionelimination.aspx\">Part 1<\/a> and <a href=\"https:\/\/www.sqlskills.com\/blogs\/conor\/2008\/02\/02\/partitionelimination202.aspx\">Part 2<\/a>)&nbsp;as well as <a href=\"https:\/\/www.sqlskills.com\/blogs\/conor\/2008\/01\/27\/sqlserverqueryoptimizationanddatawarehouses.aspx\">statistics<\/a> and it always reminds me of how much I can learn from other people&#39;s perspectives!\n<\/p>\n<p>\nAnd, just to dove-tail on some of his statistics comments&#8230; I, too, have found that as tables get significantly larger AND have non-standard distributions of more than 200 distinct values (and un-even distribution between those values as well), that the optimizer just cannot possibly do a <em>perfect<\/em> job. The only way an optimizer can be good is when it can &quot;<em><strong>find a <u>good<\/u> plan <u>fast<\/u><\/strong><\/em>&quot; (which I first heard from Nigel Ellis (former Development Manager of the Query Processor team)&nbsp;&#8211; back when he delivered a Pacific Northwest SQL Server User Group meeting many moons ago). The most important thing to realize is that it&#39;s just not possible to waste time to find <em>the absolutely best plan<\/em>&#8230; mathematically analyzing all permutations would be prohibitive &#8211; you&#39;d have to take a vacation between query executions (<em>wait, that&#39;s not a bad idea&#8230; I digress <\/em>:).\n<\/p>\n<p>\nThe point:\n<\/p>\n<ol>\n<li>Make sure that statistics are up-to-date (either through the database option: auto update stats OR by manually updating statistics)<\/li>\n<li>Consider re-evaluating statistics over large tables (and, when poor performance occurs&nbsp;&#8211; look at the estimated rows v. the actual rows &#8211; if the estimate\/actual are off by a fact of 10, then it <em>could <\/em>be the statistics). I&#39;d try updating stats first and then if that doesn&#39;t work, updating with a fullscan. If neither of those work, I&#39;d also re-evaluate other possible indexes (there are some distributions between tables being joined that just can&#39;t show a correct correlation between the values when in multiple indexes&#8230; sometimes the best index is a multi-column (ie. composite index)).&nbsp;<\/li>\n<li>Consider breaking very large tables down into smaller chunks (not <em>just <\/em>table index partitioning but possibly Partitioned Tables <strong><u>AND<\/u> <\/strong>Partitioned Views) as this&nbsp;can give the optimizer additional details about partiticularly interesting data sets. Even in SQL Server 2008, statistics are still table-level (filtered indexes can provide <em>some,<\/em> but not <em>complete,<\/em> relief&#8230; I&#39;ll give more details in a later post) but I&#39;d often argue that some of the best table designs are not just for a single table. Consider the statistical, locking, and indexing implications for mixed workloads against a single table (and the tremendous amount of blocking that could occur in addition to varying access patterns). And, even while <a href=\"https:\/\/www.sqlskills.com\/blogs\/kimberly\/sql-server-2008-offers-partition-level-lock-escalation-excellent-but\/\">2008 will offer Partition-level lock escalation<\/a>, well-designed tables may not need it! I know I&#39;ve mentioned this before but different perspectives on statistics, optimizers and the fact that a good optimizer has to be efficient in-and-of itself, remind me of some of the most basic things that are also the most common problems contributing to poor query performance. <\/li>\n<\/ol>\n<p>\nReturning to the basics and optimizing a system from the ground up always leads to better scalability!\n<\/p>\n<p>\nEnjoy!<br \/>\nkt\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know that Paul and I recommended that you subscribe to Conor&#39;s blog&#8230; but have you? He&#39;s posted some great details on Partitioning (Part 1 and Part 2)&nbsp;as well as statistics and it always reminds me of how much I can learn from other people&#39;s perspectives! And, just to dove-tail on some of his statistics [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,36,58,66,72],"tags":[],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-design","category-indexes","category-resources","category-sql-server-2008","category-statistics"],"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}