{"id":1668,"date":"2018-02-20T18:26:45","date_gmt":"2018-02-20T16:26:45","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=1668"},"modified":"2020-08-18T16:12:36","modified_gmt":"2020-08-18T14:12:36","slug":"bp-and-patch-22652097","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/bp-and-patch-22652097\/","title":{"rendered":"BP and Patch 22652097: set optimizer_adaptive_statistics to FALSE explicitly or it might not work!"},"content":{"rendered":"<blockquote><p>Update 14.03.2018: After some exchanges with Nigel Bayliss, the behaviour described here has been filed as unpublished bug 27626925: OPTIMIZER ADAPTIVE STATS DEFAULT FALSE NOT HONORED WHEN ENABLED IN OCT OR JAN BP. It will be fixed starting with April&#8217;s bundle patch.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>According to Nigel&#8217;s blog post:<\/p>\n<p><a href=\"https:\/\/blogs.oracle.com\/optimizer\/the-oracle-12102-october-2017-bp-and-the-adaptive-optimizer\">The Oracle 12.1.0.2 October 2017 BP and the Adaptive Optimizer <\/a><\/p>\n<p>if you installled the patch 22652097 prior to apply the Bundle Patch 171018, the BP apply in the database should recognize that the patch was already in place and keep it activated. This is done through the fix control 26664361.<\/p>\n<p>When fix_control <strong>26664361:0<\/strong> -&gt; Patch 22652097 is not enabled: the parameter optimizer_adaptive_features (OAF) works<\/p>\n<p>When fix_control <strong>26664361:1<\/strong> -&gt; Patch 22652097 is enabled; optimizer_adaptive_features is discarded and the two new parameters have the priority: optimizer_adaptive_plans (OAP) and optimizer_adaptive_statistics (OAS).<\/p>\n<p>But at my customer, I had another behavior.<\/p>\n<p><strong>My patching story might be very similar to yours!<\/strong><\/p>\n<p>When I started upgrading my customer&#8217;s database to 12c in early 2015, I experienced very soon the infamous problems with SQL Plan Directives (SPD) and Adaptive Dynamic Sampling (ADS) that I described in my paper:\u00a0<a href=\"http:\/\/soug.ch\/wp-content\/uploads\/2017\/04\/Ludovico_Caldara_engl_adaptive_features.pdf\">ADAPTIVE FEATURES OR: <\/a><a href=\"http:\/\/soug.ch\/wp-content\/uploads\/2017\/04\/Ludovico_Caldara_engl_adaptive_features.pdf\">HOW I LEARNED TO STOP WORRYING AND TROUBLESHOOT THE BOMB<\/a> .<\/p>\n<p><strong>Early fixes<\/strong><\/p>\n<p>When I was new to the problem, the quick fix for the problematic applications was to set OAF to FALSE.<\/p>\n<p>Later, I discovered some more details and decided to opt for setting:<\/p>\n<pre class=\"lang:plsql decode:true\">_optimizer_dsdir_usage_control=0<\/pre>\n<p>In other cases, I disabled the specific directives that were causing problems.<\/p>\n<p>But many databases did not have so many problems, and I left the defaults.<\/p>\n<p><strong>Patch 22652097 on top of BP170718\u00a0<\/strong><\/p>\n<p>At some point, me and my customer decided to apply the fix 22652097, on top of BP170718 that was our current patch level at that time.<\/p>\n<p>The patch installation on a test database was complaining about the optimizer_adaptive_feature set: this parameter was not used anymore. This issue is nicely explained by Flora in her post <a href=\"https:\/\/floobar0.wordpress.com\/2017\/10\/16\/patch-22652097-in-12-1-makes-optimizer_adaptive_features-parameter-obsolete\/\">Patch 22652097 in 12.1 makes optimizer_adaptive_features parameter obsolete.<\/a><\/p>\n<p>In order to apply that patch on the remaining databases, we did:<\/p>\n<ul>\n<li>alter system reset optimizer_adaptive_features;<\/li>\n<li>alter system reset &#8220;_optimizer_dsdir_usage_control&#8221;;<\/li>\n<li>Applied the patch on binaries and datapatch on the databases.<\/li>\n<\/ul>\n<p>The result at this point was that:<\/p>\n<ul>\n<li>optimizer_adaptive_features was not set<\/li>\n<li>optimizer_adaptive_plans was set to <strong>true<\/strong><\/li>\n<li>optimizer_adaptive_statistics was set to <strong>false<\/strong>.<\/li>\n<\/ul>\n<p>It might seems superflous to say, but it&#8217;s not, the SQL Plan Directives were not used anymore: no Adaptice Dynamic Sampling and no performance problems.<\/p>\n<p><strong>Bundle Patch 180116<\/strong><\/p>\n<p>Three weeks ago, we installled the last Bundle Patch in order to fix some Grid Infrastructure problems, and the BP, as described in Nigel&#8217;s note (and Mike Dietrich and many other bloggers :-)) contains the patch <strong>22652097<\/strong>.<\/p>\n<p>According to Nigel&#8217;s post, the patch installation should have detected that the patch 22652097 was already there and activate it.<\/p>\n<p>And indeed, after we applied the BP, the fix_control 26664361 was set to 1 (that means that the patch 22652097 is enabled). So we went live with this setup without additional checks.<\/p>\n<p>One week later, we started experiencing performance problems again. I noticed immediately that the Adaptive Dynamic Sampling was very aggressive again, and the SQL Plan Directives used again.<\/p>\n<p>But the fix was there AND ENABLED!<\/p>\n<p>After a few tests, I realized that the SPD is not used anymore if I set optimizer_adaptive_statistics EXPLICITLY to false.<\/p>\n<p><strong>optimizer_adaptive_statistics must be set explicitly, the default does not work<\/strong><\/p>\n<p>And here&#8217;s the proof:<\/p>\n<p>I use once again the great SPD example by Tim Hall (sorry Tim, it&#8217;s not the first time that I steal your work \ud83d\ude42 ) . You can find here:<\/p>\n<p><a href=\"https:\/\/oracle-base.com\/articles\/12c\/sql-plan-directives-12cr1\">SQL Plan Directives in Oracle Database 12c Release 1 (12.1)<\/a><\/p>\n<p>After applying the BP, I have the default parameter, not set explicitly, and the fix_control enabled:<\/p>\n<div class=\"dp-highlighter\">\n<pre class=\"lang:plsql decode:true\">SQL&gt; select value from v$system_fix_control where bugno = 26664361;\r\n\r\n     VALUE\r\n----------\r\n         1\r\n\r\nSQL&gt; select name, value, isdefault, ismodified from v$parameter where name='optimizer_adaptive_statistics';  \r\n  \r\nNAME                                    VALUE                          ISDEFAULT ISMODIFIED  \r\n---------------------------------------- ------------------------------ --------- ----------------------------------------  \r\noptimizer_adaptive_statistics            FALSE                          TRUE      FALSE<\/pre>\n<p>If I run the test statement (again, find it here <a class=\"jive-link-external-small\" href=\"https:\/\/oracle-base.com\/articles\/12c\/sql-plan-directives-12cr1\" rel=\"nofollow\">https:\/\/oracle-base.com\/articles\/12c\/sql-plan-directives-12cr1<\/a>) the directives are used:<\/p>\n<\/div>\n<div class=\"dp-highlighter\">\n<pre class=\"lang:plsql decode:true \">SQL&gt; SELECT \/*+ GATHER_PLAN_STATISTICS *\/  \r\n      *  \r\n  2  FROM  tab1  \r\nWHERE  gender = 'M'  \r\nAND    has_y_chromosome = 'Y';  \r\n  \r\nSET LINESIZE 200 PAGESIZE 100  \r\n  \r\n...  \r\n  \r\n10 rows selected.  \r\n  \r\nSQL&gt; SELECT * FROM TABLE(DBMS_XPLAN.display_cursor(format =&gt; 'allstats last'));  \r\n  \r\nPLAN_TABLE_OUTPUT  \r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  \r\nSQL_ID  5t8y8p5mpb99j, child number 0  \r\n-------------------------------------  \r\nSELECT \/*+ GATHER_PLAN_STATISTICS *\/        * FROM  tab1 WHERE  gender  \r\n= 'M' AND    has_y_chromosome = 'Y'  \r\n  \r\nPlan hash value: 1552452781  \r\n  \r\n-----------------------------------------------------------------------------------------------------------------  \r\n| Id  | Operation                          | Name            | Starts | E-Rows | A-Rows |  A-Time  | Buffers |  \r\n-----------------------------------------------------------------------------------------------------------------  \r\n|  0 | SELECT STATEMENT                    |                |      1 |        |    10 |00:00:00.01 |      4 |  \r\n|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TAB1            |      1 |    10 |    10 |00:00:00.01 |      4 |  \r\n|*  2 |  INDEX RANGE SCAN                  | TAB1_GENDER_IDX |      1 |    10 |    10 |00:00:00.01 |      2 |  \r\n-----------------------------------------------------------------------------------------------------------------  \r\n  \r\nPredicate Information (identified by operation id):  \r\n---------------------------------------------------  \r\n  \r\n  1 - filter(\"HAS_Y_CHROMOSOME\"='Y')  \r\n  2 - access(\"GENDER\"='M')  \r\n  \r\nNote  \r\n-----  \r\n  - dynamic statistics used: dynamic sampling (level=2)  \r\n  - 2 Sql Plan Directives used for this statement  \r\n      \r\n      \r\n    26 rows selected.<\/pre>\n<p>but then I set the parameter explicitly:<\/p>\n<pre class=\"lang:plsql decode:true \">SQL&gt; alter system flush shared_pool;  \r\n  \r\nSystem altered.  \r\n  \r\nSQL&gt; alter system set optimizer_adaptive_statistics=false;  \r\n  \r\nSystem altered.  \r\n  \r\nSQL&gt; select name, value, isdefault, ismodified from v$parameter where name='optimizer_adaptive_statistics';  \r\n  \r\nNAME                                     VALUE                          ISDEFAULT ISMODIFIED  \r\n---------------------------------------- ------------------------------ --------- ----------------------------------------  \r\noptimizer_adaptive_statistics            FALSE                          TRUE      MODIFIED<\/pre>\n<p>and the SPD usage (and consequently, ADS), are gone:<\/p>\n<pre class=\"lang:plsql decode:true \">SQL&gt; SELECT \/*+ GATHER_PLAN_STATISTICS *\/  \r\n       *  \r\nFROM   tab1  \r\nWHERE  gender = 'M'  \r\nAND    has_y_chromosome = 'Y';  \r\n  \r\nSET LINESIZE 200 PAGESIZE 100  \r\n  \r\n        ID G H  \r\n---------- - -  \r\n         1 M Y  \r\n         2 M Y  \r\n         3 M Y  \r\n         4 M Y  \r\n         5 M Y  \r\n         6 M Y  \r\n         7 M Y  \r\n         8 M Y  \r\n         9 M Y  \r\n        10 M Y  \r\n  \r\n10 rows selected.  \r\n  \r\nSQL&gt; SELECT * FROM TABLE(DBMS_XPLAN.display_cursor(format =&gt; 'allstats last'));  \r\n  \r\nPLAN_TABLE_OUTPUT  \r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  \r\nSQL_ID  5t8y8p5mpb99j, child number 0  \r\n-------------------------------------  \r\nSELECT \/*+ GATHER_PLAN_STATISTICS *\/        * FROM   tab1 WHERE  gender  \r\n= 'M' AND    has_y_chromosome = 'Y'  \r\n  \r\nPlan hash value: 1552452781  \r\n  \r\n-----------------------------------------------------------------------------------------------------------------  \r\n| Id  | Operation                           | Name            | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  \r\n-----------------------------------------------------------------------------------------------------------------  \r\n|   0 | SELECT STATEMENT                    |                 |      1 |        |     10 |00:00:00.01 |       4 |  \r\n|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TAB1            |      1 |     25 |     10 |00:00:00.01 |       4 |  \r\n|*  2 |   INDEX RANGE SCAN                  | TAB1_GENDER_IDX |      1 |     50 |     10 |00:00:00.01 |       2 |  \r\n-----------------------------------------------------------------------------------------------------------------  \r\n  \r\nPredicate Information (identified by operation id):  \r\n---------------------------------------------------  \r\n  \r\n   1 - filter(\"HAS_Y_CHROMOSOME\"='Y')  \r\n   2 - access(\"GENDER\"='M')  \r\n      \r\n      \r\n    21 rows selected.<\/pre>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Set the parameter EXPLICITLY when you apply the BP that contains the fix.<\/p>\n<p>And ALWAYS test the behavior!<\/p>\n<p>You can check how many statements use the dynamic sampling by following this short blog post by Dominic Brooks:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"xnQB1ZhLca\"><p><a href=\"https:\/\/orastory.wordpress.com\/2013\/02\/08\/which-of-my-sql-statements-are-using-dynamic-sampling\/\">Which of my sql statements are using dynamic&nbsp;sampling?<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Which of my sql statements are using dynamic&nbsp;sampling?&#8221; &#8212; OraStory\" src=\"https:\/\/orastory.wordpress.com\/2013\/02\/08\/which-of-my-sql-statements-are-using-dynamic-sampling\/embed\/#?secret=FrNCZ60D8H#?secret=xnQB1ZhLca\" data-secret=\"xnQB1ZhLca\" width=\"584\" height=\"329\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<\/div>\n<p>HTH<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update 14.03.2018: After some exchanges with Nigel Bayliss, the behaviour described here has been filed as unpublished bug 27626925: OPTIMIZER ADAPTIVE STATS DEFAULT FALSE NOT HONORED WHEN ENABLED IN OCT OR JAN BP. It will be fixed starting with April&#8217;s &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bp-and-patch-22652097\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[321,326,3,52,6,132],"tags":[],"class_list":["post-1668","post","type-post","status-publish","format-standard","hentry","category-aced","category-oracle","category-oracledb","category-12c","category-perf","category-triblog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=1668"}],"version-history":[{"count":6,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1668\/revisions"}],"predecessor-version":[{"id":1681,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1668\/revisions\/1681"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=1668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=1668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=1668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}