{"id":9522,"date":"2016-12-07T10:48:55","date_gmt":"2016-12-07T09:48:55","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/"},"modified":"2016-12-07T10:48:55","modified_gmt":"2016-12-07T09:48:55","slug":"oracle-12cr2-statistics-advisor","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/","title":{"rendered":"Oracle 12cR2: Statistics Advisor"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nToday at #ukoug_tech16 12:30 in hall 11A I&#8217;ll talk about <a href=\"http:\/\/www.tech16.ukoug.org\/default.asp?p=14778&amp;dlgact=shwprs&amp;prs_prsid=11948&amp;day_dayid=102\" target=\"_blank\" rel=\"noopener noreferrer\">Statistics Gathering Best Practice &amp; 12cR2 Statistics Advisor<\/a><br \/>\nRather than taking the Optimizer Statistics Advisor rules one by one I&#8217;ll show the things to take care (some people may call it best practices) when  gathering statistics and they mention the Statistics Advisor Rule.<br \/>\nIf you need a reference about all rules, you can get it from V$STATS_ADVISOR_RULES<br \/>\n<!--more--><\/p>\n<pre><code>09:41:19 SQL&gt; select to_char(rule_id,99)||' '||description||' ('||name||')' from V$STATS_ADVISOR_RULES where rule_id&gt;0 order by rule_id;\n&amp;nbsp\nTO_CHAR(RULE_ID,99)||''||DESCRIPTION||'('||NAME||')'\n----------------------------------------------------------------------------------------------------<\/code><\/pre>\n<p>I&#8217;ll explain them briefly here.<\/p>\n<p>You should always enable to automatic statistic gathering job. You may manage special cases manually, but do not disable it.<\/p>\n<pre><code>  1 Use Auto Job for Statistics Collection (UseAutoJob)<\/code><\/pre>\n<p>For sure if the job does not complete successfully, the advisor detects the probable cause.<\/p>\n<pre><code>  2 Auto Statistics Gather Job should complete successfully (CompleteAutoJob)<\/code><\/pre>\n<p>Statistics history may save your life in case of a regression. But be sure the retention is not too large and purge occurs or SYSAUX will grow<\/p>\n<pre><code>  3 Maintain Statistics History (MaintainStatsHistory)<\/code><\/pre>\n<p>The faster the statistics gathering run, the more statistics you can gather. Use all your server resources for it.<\/p>\n<pre><code>  4 Use Concurrent preference for Statistics Collection (UseConcurrent)<\/code><\/pre>\n<p>Default options for global preferences are what the optimizer developers think are the best for most cases.<\/p>\n<pre><code>  5 Use Default Preference for Stats Collection (UseDefaultPreference)<\/code><\/pre>\n<p>Humm.. this one was introduced before the decision not to activate SPD by default<br \/>\n(see <a href=\"http:\/\/dbi-services.com\/blog\/oracle-12cr2-optimizer-adaptive-statistics\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/dbi-services.com\/blog\/oracle-12cr2-optimizer-adaptive-statistics\/<\/a>)<\/p>\n<pre><code>  6 SQL Plan Directives should not be disabled (TurnOnSQLPlanDirective)<\/code><\/pre>\n<p>Setting statistics manually may be used as a workaround but not the general case<\/p>\n<pre><code>  7 Avoid Set Statistics Procedures (AvoidSetProcedures)<\/code><\/pre>\n<p>When you run dbms_stats.gather_&#8230;_stats manually, default options are what the optimizer developers think are the best for most cases.<\/p>\n<pre><code>  8 Use Default Parameters in Statistics Collection Procedures (UseDefaultParams)<\/code><\/pre>\n<p>And in those cases, better to run it for a schema so that you are sure to include newly created tables<\/p>\n<pre><code>  9 Use gather_schema_stats procedure (UseGatherSchemaStats)<\/code><\/pre>\n<p>You waste time and ressources if you gather statistics in a addition to what is done with online statistics gathering<\/p>\n<pre><code> 10 Avoid inefficient statistics operation sequences (AvoidInefficientStatsOprSeq)<\/code><\/pre>\n<p>You waste time and ressources if you gather statistics when nothing has changed<\/p>\n<pre><code> 11 Avoid unnecessary statistics collection (AvoidUnnecessaryStatsCollection)<\/code><\/pre>\n<p>You need statistics for all tables<\/p>\n<pre><code> 12 Avoid objects with stale or no statistics (AvoidStaleStats)<\/code><\/pre>\n<p>Statistics gathered before bulk inserts will be immediately stale<\/p>\n<pre><code> 13 Do not gather statistics right before bulk DML (GatherStatsAfterBulkDML)<\/code><\/pre>\n<p>You don&#8217;t want the automatic statistics gathering run on a table between a truncate and an insert<\/p>\n<pre><code> 14 Statistics for objects with volatile data should be locked (LockVolatileTable)<\/code><\/pre>\n<p>But let it run for tables with no massive change<\/p>\n<pre><code> 15 Statistics for objects with non-volatile should not be locked (UnlockNonVolatileTable)\n 16 Statistics of dependent objects should be consistent (MaintainStatsConsistency)<\/code><\/pre>\n<p>Better truncate, make indexes unusable, and insert \/*+ append *\/ than drop and recreate the table (which removes statistics).<\/p>\n<pre><code> 17 Avoid drop and recreate object seqauences (AvoidDropRecreate)<\/code><\/pre>\n<p>Statistics advisor may detect when incremental statistics gathering is me efficient for partitioned tables<\/p>\n<pre><code> 18 Statistics should be maintained incrementally when it is beneficial (UseIncremental)\n 19 Statistics should not be maintained incrementally when it is not beneficial (NotUseIncremental)<\/code><\/pre>\n<p>Stale statistics may lead to under-estimation because of linear decay<\/p>\n<pre><code> 20 Avoid Out of Range Histogram endpoints (AvoidOutOfRange)<\/code><\/pre>\n<p>Large tables can be scanned in parallel, recommendation is default degree<\/p>\n<pre><code> 21 Use Auto Degree for statistics collection (UseAutoDegree)<\/code><\/pre>\n<p>As we have seen about global preferences, table preference should be default for most cases (rolling invalidation, auto sample size, auto histogram size)<\/p>\n<pre><code> 22 Use Default Object Preference for statistics collection (UseDefaultObjectPreference)<\/code><\/pre>\n<p>And for sure dbms_stats is the way to gather statistics for the optimizer. ANALYZE is deprecated for that since 91<\/p>\n<pre><code> 23 Avoid using analyze table commands for statistics collection (AvoidAnalyzeTable)<\/code><\/pre>\n<p>Those are only my interpretation. 12.2 is new (and cloud first) and I&#8217;ve not observed all those recommandations yet. But there are properly described by the advisor.<br \/>\nThis is the kind of output we can get:<\/p>\n<pre><code>\n----------------------------------------------------------------------------------------------------\nGENERAL INFORMATION\n-------------------------------------------------------------------------------\n&nbsp;\n Task Name       : MY_TASK\n Execution Name  : EXEC_52\n Created         : 12-07-16 11:31:40\n Last Modified   : 12-07-16 11:32:37\n-------------------------------------------------------------------------------\nSUMMARY\n-------------------------------------------------------------------------------\n For execution EXEC_52 of task MY_TASK, the Statistics Advisor has 6\n finding(s). The findings are related to the following rules: USECONCURRENT,\n AVOIDSETPROCEDURES, USEDEFAULTPARAMS, USEGATHERSCHEMASTATS, AVOIDSTALESTATS,\n UNLOCKNONVOLATILETABLE. Please refer to the finding section for detailed\n information.\n-------------------------------------------------------------------------------\nFINDINGS\n-------------------------------------------------------------------------------\n Rule Name:         UseConcurrent\n Rule Description:  Use Concurrent preference for Statistics Collection\n Finding:  The CONCURRENT preference is not used.\n&nbsp;\n Recommendation:  Set the CONCURRENT preference.\n Example:\n dbms_stats.set_global_prefs('CONCURRENT', 'ALL');\n Rationale:  The system's condition satisfies the use of concurrent statistics\n             gathering. Using CONCURRENT increases the efficiency of statistics\n             gathering.\n----------------------------------------------------\n...\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . Today at #ukoug_tech16 12:30 in hall 11A I&#8217;ll talk about Statistics Gathering Best Practice &amp; 12cR2 Statistics Advisor Rather than taking the Optimizer Statistics Advisor rules one by one I&#8217;ll show the things to take care (some people may call it best practices) when gathering statistics and they mention the Statistics [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[349,988],"type_dbi":[],"class_list":["post-9522","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-optimizer","tag-oracle-12-2"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Oracle 12cR2: Statistics Advisor - dbi Blog<\/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.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle 12cR2: Statistics Advisor\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . Today at #ukoug_tech16 12:30 in hall 11A I&#8217;ll talk about Statistics Gathering Best Practice &amp; 12cR2 Statistics Advisor Rather than taking the Optimizer Statistics Advisor rules one by one I&#8217;ll show the things to take care (some people may call it best practices) when gathering statistics and they mention the Statistics [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-07T09:48:55+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Oracle 12cR2: Statistics Advisor\",\"datePublished\":\"2016-12-07T09:48:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\"},\"wordCount\":469,\"commentCount\":0,\"keywords\":[\"Optimizer\",\"Oracle 12.2\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\",\"name\":\"Oracle 12cR2: Statistics Advisor - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2016-12-07T09:48:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle 12cR2: Statistics Advisor\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Oracle 12cR2: Statistics Advisor - dbi Blog","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.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/","og_locale":"en_US","og_type":"article","og_title":"Oracle 12cR2: Statistics Advisor","og_description":"By Franck Pachot . Today at #ukoug_tech16 12:30 in hall 11A I&#8217;ll talk about Statistics Gathering Best Practice &amp; 12cR2 Statistics Advisor Rather than taking the Optimizer Statistics Advisor rules one by one I&#8217;ll show the things to take care (some people may call it best practices) when gathering statistics and they mention the Statistics [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/","og_site_name":"dbi Blog","article_published_time":"2016-12-07T09:48:55+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Oracle 12cR2: Statistics Advisor","datePublished":"2016-12-07T09:48:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/"},"wordCount":469,"commentCount":0,"keywords":["Optimizer","Oracle 12.2"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/","url":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/","name":"Oracle 12cR2: Statistics Advisor - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2016-12-07T09:48:55+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-12cr2-statistics-advisor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Oracle 12cR2: Statistics Advisor"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/9522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=9522"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/9522\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=9522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=9522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=9522"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=9522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}