{"id":322,"date":"2009-07-23T16:28:23","date_gmt":"2009-07-23T21:28:23","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=322"},"modified":"2013-01-04T19:01:44","modified_gmt":"2013-01-05T00:01:44","slug":"how-to-gather-stats-for-a-single-column","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2009\/07\/23\/how-to-gather-stats-for-a-single-column\/","title":{"rendered":"How to gather stats for a single column"},"content":{"rendered":"<p>I needed to gather stats for only a single column.  For whatever reason, the auto stats job was not getting it, but we actually found our execution plans were much better when we had it.<\/p>\n<p>I ran what is below to generate a HEIGHT BALANCED histogram with 254 evenly divided buckets.  We have five years of data, so assuming the data is evenly distributed (ours roughly is), I would expect buckets such as&#8230;<\/p>\n<pre lang=\"text\">\r\nBUCKET     LOW           HIGH\r\n1          JUL-21-2004   JUL-28-2004\r\n2          JUL-29-2004   AUG-4-2004\r\n3          AUG-5-2004    AUG-12-2004\r\n...\r\n254        JUL-14-2009   JUL-21-2009\r\n<\/pre>\n<p>This will allow the optimizer to take the value and decide whether the number of rows found on average in that bucket is low enough to produce a good execution plan by using its index.<\/p>\n<pre lang=\"plsql\" line=\"1\">\r\nbegin\r\n    dbms_stats.gather_table_stats('RSPROD_ARCH', \r\n                                  'REQUEST',\r\n                                   ESTIMATE_PERCENT => 0.1, \r\n                                   METHOD_OPT => 'FOR COLUMNS CLOSEDDATE SIZE 254');\r\nend;\r\n\/\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I needed to gather stats for only a single column. For whatever reason, the auto stats job was not getting it, but we actually found our execution plans were much better when we had it. I ran what is below&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2009\/07\/23\/how-to-gather-stats-for-a-single-column\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,22],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/322"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=322"}],"version-history":[{"count":19,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"predecessor-version":[{"id":2703,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/322\/revisions\/2703"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}