{"id":4093,"date":"2014-11-08T19:48:24","date_gmt":"2014-11-08T18:48:24","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/"},"modified":"2014-11-08T19:48:24","modified_gmt":"2014-11-08T18:48:24","slug":"oracle-sql-profile-why-multiple-optestimate","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/","title":{"rendered":"Oracle SQL Profile: why multiple OPT_ESTIMATE?"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nIn a <a href=\"https:\/\/www.dbi-services.com\/index.php\/blog\/entry\/oracle-sql-profiles-check-what-they-do-before-accepting-them-blindly\">previous blog<\/a> I&#8217;v shared my script to retrieve the OPT_ESTIMATE hints from a SQL Profile. In the example I made, I had two lines for each table:<\/p>\n<pre>--- PROFILE HINTS from dbiInSite (1) statement 4fz1vtn0w8aak:\n\/*+\nOPT_ESTIMATE(@\"SEL$2CBA5DDD\", TABLE, \"EMPLOYEES\"@\"SEL$1\", SCALE_ROWS=2)\nOPT_ESTIMATE(@\"SEL$58A6D7F6\", TABLE, \"EMPLOYEES\"@\"SEL$1\", SCALE_ROWS=2)\nOPT_ESTIMATE(@\"SEL$6AE97DF7\", TABLE, \"DEPARTMENTS\"@\"SEL$1\", SCALE_ROWS=5.185185185)\nOPT_ESTIMATE(@\"SEL$58A6D7F6\", TABLE, \"DEPARTMENTS\"@\"SEL$1\", SCALE_ROWS=5.185185185)\n*\/\n<\/pre>\n<p>The reason is that when the optimizer do some transformations to the query, then the query block identifiers can change. And when you adjust a cardinality estimation, you must do it for all transformations or you will completely mess up the optimizer choice.<\/p>\n<p>When I do an explain plan which show the query blocks, I have only the SEL$58A6D7F6 one:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">SQL&gt; explain plan for\n  2  select distinct DEPARTMENT_NAME  from DEPARTMENTS join EMPLOYEES\n  3  using(DEPARTMENT_ID)  where DEPARTMENT_NAME like '%ing' and SALARY&gt;20000 ;\n\nExplained.\n\nSQL&gt; select * from table(dbms_xplan.display(format=&gt;'basic +alias'));\n\nPLAN_TABLE_OUTPUT\n-------------------------------------------------------------------\nPlan hash value: 3041748347\n-------------------------------------------------------------------\n| Id  | Operation                             | Name              |\n-------------------------------------------------------------------\n|   0 | SELECT STATEMENT                      |                   |\n|   1 |  HASH UNIQUE                          |                   |\n|   2 |   NESTED LOOPS SEMI                   |                   |\n|   3 |    TABLE ACCESS FULL                  | DEPARTMENTS       |\n|   4 |    TABLE ACCESS BY INDEX ROWID BATCHED| EMPLOYEES         |\n|   5 |     INDEX RANGE SCAN                  | EMP_DEPARTMENT_IX |\n-------------------------------------------------------------------\n\nQuery Block Name \/ Object Alias (identified by operation id):\n-------------------------------------------------------------\n\n   1 - SEL$58A6D7F6\n   3 - SEL$58A6D7F6 \/ DEPARTMENTS@SEL$1\n   4 - SEL$58A6D7F6 \/ EMPLOYEES@SEL$1\n   5 - SEL$58A6D7F6 \/ EMPLOYEES@SEL$1\n\n<\/pre>\n<p>In order to confirm that the duplicate OPT_ESTIMATE are coming from different transformations, I&#8217;ve generated a 10053 trace and searched for SEL$6AE97DF7:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">Registered qb: SEL$6AE97DF7 0x851d8eb8 (DISTINCT PLACEMENT SEL$58A6D7F6; SEL$58A6D7F6; \"EMPLOYEES\"@\"SEL$1\")\n---------------------\nQUERY BLOCK SIGNATURE\n---------------------\n  signature (): qb_name=SEL$6AE97DF7 nbfros=2 flg=0\n    fro(0): flg=0 objn=92595 hint_alias=\"DEPARTMENTS\"@\"SEL$1\"\n    fro(1): flg=1 objn=0 hint_alias=\"VW_DTP_43B5398E\"@\"SEL$43B5398E\"\n\n<\/pre>\n<p>that&#8217;s the Distinct Placement.<br \/>\nlet&#8217;s try the PLACE_DISTINCT hint:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">SQL&gt; explain plan for\n  2  select \/*+ PLACE_DISTINCT(EMPLOYEES) *\/ distinct DEPARTMENT_NAME  from DEPARTMENTS join EMPLOYEES\n  3  using(DEPARTMENT_ID)  where DEPARTMENT_NAME like '%ing' and SALARY&gt;20000 ;\n\nExplained.\n\nSQL&gt; select * from table(dbms_xplan.display(format=&gt;'basic +alias'));\n\nPLAN_TABLE_OUTPUT\n--------------------------------------------------------------------\nPlan hash value: 2901355344\n\n--------------------------------------------------------------------\n| Id  | Operation                              | Name              |\n--------------------------------------------------------------------\n|   0 | SELECT STATEMENT                       |                   |\n|   1 |  HASH UNIQUE                           |                   |\n|   2 |   NESTED LOOPS SEMI                    |                   |\n|   3 |    TABLE ACCESS FULL                   | DEPARTMENTS       |\n|   4 |    VIEW PUSHED PREDICATE               | VW_DTP_43B5398E   |\n|   5 |     TABLE ACCESS BY INDEX ROWID BATCHED| EMPLOYEES         |\n|   6 |      INDEX RANGE SCAN                  | EMP_DEPARTMENT_IX |\n--------------------------------------------------------------------\n\nQuery Block Name \/ Object Alias (identified by operation id):\n-------------------------------------------------------------\n\n   1 - SEL$6AE97DF7\n   3 - SEL$6AE97DF7 \/ DEPARTMENTS@SEL$1\n   4 - SEL$9B757045 \/ VW_DTP_43B5398E@SEL$43B5398E\n   5 - SEL$9B757045 \/ EMPLOYEES@SEL$1\n   6 - SEL$9B757045 \/ EMPLOYEES@SEL$1\n\n<\/pre>\n<p>Here is where the<\/p>\n<pre>OPT_ESTIMATE(@\"SEL$6AE97DF7\", TABLE, \"DEPARTMENTS\"@\"SEL$1\", SCALE_ROWS=5.185185185)<\/pre>\n<p>makes sense. The same cardinality adjustment must be done for each transformation that the optimizer is evaluating.<\/p>\n<p>That observation brings me to the following: what happens to your profiles when you upgrade to a version that brings new optimizer transformations? The optimizer will compare some plans with adjusted cardinalities, compared with some plans with non-adjusted cardinalites. And that is probably not a good idea.<\/p>\n<p>In my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . In a previous blog I&#8217;v shared my script to retrieve the OPT_ESTIMATE hints from a SQL Profile. In the example I made, I had two lines for each table: &#8212; PROFILE HINTS from dbiInSite (1) statement 4fz1vtn0w8aak: \/*+ OPT_ESTIMATE(@&#8221;SEL$2CBA5DDD&#8221;, TABLE, &#8220;EMPLOYEES&#8221;@&#8221;SEL$1&#8243;, SCALE_ROWS=2) OPT_ESTIMATE(@&#8221;SEL$58A6D7F6&#8221;, TABLE, &#8220;EMPLOYEES&#8221;@&#8221;SEL$1&#8243;, SCALE_ROWS=2) OPT_ESTIMATE(@&#8221;SEL$6AE97DF7&#8221;, TABLE, &#8220;DEPARTMENTS&#8221;@&#8221;SEL$1&#8243;, SCALE_ROWS=5.185185185) OPT_ESTIMATE(@&#8221;SEL$58A6D7F6&#8221;, [&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":[198,59],"tags":[349,96],"type_dbi":[],"class_list":["post-4093","post","type-post","status-publish","format-standard","hentry","category-database-management","category-oracle","tag-optimizer","tag-oracle"],"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 SQL Profile: why multiple OPT_ESTIMATE? - dbi Blog<\/title>\n<meta name=\"description\" content=\"Why, in my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.\" \/>\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-sql-profile-why-multiple-optestimate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle SQL Profile: why multiple OPT_ESTIMATE?\" \/>\n<meta property=\"og:description\" content=\"Why, in my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-08T18:48:24+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=\"3 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-sql-profile-why-multiple-optestimate\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Oracle SQL Profile: why multiple OPT_ESTIMATE?\",\"datePublished\":\"2014-11-08T18:48:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/\"},\"wordCount\":231,\"commentCount\":0,\"keywords\":[\"Optimizer\",\"Oracle\"],\"articleSection\":[\"Database management\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/\",\"name\":\"Oracle SQL Profile: why multiple OPT_ESTIMATE? - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2014-11-08T18:48:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"description\":\"Why, in my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle SQL Profile: why multiple OPT_ESTIMATE?\"}]},{\"@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 SQL Profile: why multiple OPT_ESTIMATE? - dbi Blog","description":"Why, in my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.","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-sql-profile-why-multiple-optestimate\/","og_locale":"en_US","og_type":"article","og_title":"Oracle SQL Profile: why multiple OPT_ESTIMATE?","og_description":"Why, in my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.","og_url":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/","og_site_name":"dbi Blog","article_published_time":"2014-11-08T18:48:24+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Oracle SQL Profile: why multiple OPT_ESTIMATE?","datePublished":"2014-11-08T18:48:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/"},"wordCount":231,"commentCount":0,"keywords":["Optimizer","Oracle"],"articleSection":["Database management","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/","url":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/","name":"Oracle SQL Profile: why multiple OPT_ESTIMATE? - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2014-11-08T18:48:24+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"description":"Why, in my opinion, SQL Profiles are just like hints: a short term workaround that must be documented and re-evaluated at each upgrade.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-sql-profile-why-multiple-optestimate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Oracle SQL Profile: why multiple OPT_ESTIMATE?"}]},{"@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\/4093","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=4093"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/4093\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=4093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=4093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=4093"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=4093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}