<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Execution Plan Changes when the OPTIMIZER_FEATURES_ENABLED Parameter is Changed, But Why?</title>
	<atom:link href="http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/</link>
	<description>Miscellaneous Random Oracle Topics: Stop, Think, ... Understand</description>
	<lastBuildDate>Mon, 13 May 2013 14:10:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4739</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 13 Jun 2012 10:33:13 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4739</guid>
		<description><![CDATA[Tony,

I was thinking something similar regarding the hint.  Without seeing the actual number of rows returned by the operations, it is difficult to see at what point the plan becomes wrong.  The OP stated the following about attempting to use the hint:
&lt;blockquote&gt;
4) i had to cancel execution in 11.2.0.2 after 10 min. Thats the reason why i did not put ‘GATHER_PLAN_STATISTICS’ plan for 11.2.0.2
&lt;/blockquote&gt;
Unfortunately, the query must complete for the GATHER_PLAN_STATISTICS hint and &#039;ALLSTATS LAST&#039; formatted DBMS_XPLAN to work properly.

I was under the impression that if the optimizer estimated that 0 rows would be returned, that the optimizer would use a value of 1 so that multiplication of the estimated cardinality would not cause the calculated cost to become 0 - thinking about it, avoiding infinity (division by 0) could be a possibility too.]]></description>
		<content:encoded><![CDATA[<p>Tony,</p>
<p>I was thinking something similar regarding the hint.  Without seeing the actual number of rows returned by the operations, it is difficult to see at what point the plan becomes wrong.  The OP stated the following about attempting to use the hint:</p>
<blockquote><p>
4) i had to cancel execution in 11.2.0.2 after 10 min. Thats the reason why i did not put ‘GATHER_PLAN_STATISTICS’ plan for 11.2.0.2
</p></blockquote>
<p>Unfortunately, the query must complete for the GATHER_PLAN_STATISTICS hint and &#8216;ALLSTATS LAST&#8217; formatted DBMS_XPLAN to work properly.</p>
<p>I was under the impression that if the optimizer estimated that 0 rows would be returned, that the optimizer would use a value of 1 so that multiplication of the estimated cardinality would not cause the calculated cost to become 0 &#8211; thinking about it, avoiding infinity (division by 0) could be a possibility too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Sleight</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4738</link>
		<dc:creator><![CDATA[Tony Sleight]]></dc:creator>
		<pubDate>Wed, 13 Jun 2012 09:54:14 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4738</guid>
		<description><![CDATA[Charles,
Would this query benefit from the GATHER_PLAN_STATISTICS hint and an &#039;ALLSTATS LAST&#039;, it might be useful to see the correlation between estimated and actual rows returned.
The prediction that only a single row in the GC_TRANSACTIONS table has a GC_TRANSACTION_TYPE_ID of 11 might not be a true representation. As I understand, the optimzer will return an estimated number of rows as 1 if it determines that there are no rows to be returned. I think that might be to eliminate the possibility of divide by zero errors in the CBO calculations. If there are expected to be no rows returned, that would strengthen your argument around the cost not being adjusted for table access. It may be that a histogram for the GC_TRANSACTION_TYPE_ID column may indicate a better data distribution for that column and hence change the index cost.]]></description>
		<content:encoded><![CDATA[<p>Charles,<br />
Would this query benefit from the GATHER_PLAN_STATISTICS hint and an &#8216;ALLSTATS LAST&#8217;, it might be useful to see the correlation between estimated and actual rows returned.<br />
The prediction that only a single row in the GC_TRANSACTIONS table has a GC_TRANSACTION_TYPE_ID of 11 might not be a true representation. As I understand, the optimzer will return an estimated number of rows as 1 if it determines that there are no rows to be returned. I think that might be to eliminate the possibility of divide by zero errors in the CBO calculations. If there are expected to be no rows returned, that would strengthen your argument around the cost not being adjusted for table access. It may be that a histogram for the GC_TRANSACTION_TYPE_ID column may indicate a better data distribution for that column and hence change the index cost.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Log Buffer #274, A Carnival of the Vanities for DBAs &#124; The Pythian Blog</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4729</link>
		<dc:creator><![CDATA[Log Buffer #274, A Carnival of the Vanities for DBAs &#124; The Pythian Blog]]></dc:creator>
		<pubDate>Fri, 01 Jun 2012 07:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4729</guid>
		<description><![CDATA[[...] Plan Changes when the OPTIMIZER_FEATURES_ENABLED Parameter is Changed, But Why? Charles Hooper [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Plan Changes when the OPTIMIZER_FEATURES_ENABLED Parameter is Changed, But Why? Charles Hooper [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4727</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Thu, 31 May 2012 20:46:01 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4727</guid>
		<description><![CDATA[Bhavik,

Thank you for posting the above information.  

The posted execution plan with the LEADING HINT is interesting.  Notice that the optimizer has introduced a HASH JOIN operation in place of the two NESTED LOOPS operation, and that it is predicting that only a single row in the GC_TRANSACTIONS table has a GC_TRANSACTION_TYPE_ID of 11 based on the row in the plan with an ID of 7 - usage of that index appears to be quite inefficient due to the calculated cost of 9541.

You may also notice a bug in the execution plan, where the cost of accessing the I_GCT_CUSMKTLSTUPD index is the same cost as that of the parent operation (the table GC_TRANSACTIONS) - the optimizer is NOT taking into account the cost of the table access which should increase the calculated cost by at least 1 per expected row returned.  I think that I have a blog article on this site that describes this problem which seemed to be related to collecting statistics for the indexes and tables when the tables contain no rows (and thus do not have a data segment yet by default due to deferred segment creation), one that was identified by Randolf Geist - I will have to do some searching to find the article.

The decision to use the INDEX SKIP SCAN operation on the I_GCT_CUSMKTLSTUPD index may be either due to a bug, adjusted skip scan costing in 11.2.0.2, or the setting of optimizer_index_cost_adj=10 that essentially causes the optimizer to take the calculated cost of the index skip scan at 95,410, multiply that value by 0.10, and determine that the index skip scan is efficient.  The cardinality estimate of 1 is the reason why, by default, that row source is selected as the driving table in the join.

It appears that both of the database instances are using NOWORKLOAD system statistics (although with a different value in the FLAGS column), with one of the instances having an estimated calculated CPU processing speed that is roughly 3 times faster than the other - that is enough of a change by itself to affect the decisions made by the optimizer.  Randolf Geist has a very good series of articles that describe the affects of NOWORKLOAD and WORKLOAD system statistics, and he also shows how to alter those system statistics. You will need to force a hard parse by modifying the SQL statement (with a comment or additional white space) to see if adjusting the CPUSPEEDNW system statistic to a value of 522 in the 11.2.0.2 database causes a desired change in the execution plan (keep in mind, that like the OPTIMIZER_INDEX_COST_ADJ parameter, that this is a global change that could negatively affect other SQL statements).  You can access Randolf&#039;s article series here:
http://oracle-randolf.blogspot.com/2009/05/understanding-different-modes-of-system.html

Randolf&#039;s blog also contains an article that describes costing calculation changes that were introduced in Oracle Database 11.2.0.1 and 11.2.0.2 - these changes &lt;i&gt;may&lt;/i&gt; still affect the 11.2.0.2 database when the OPTIMIZER_FEATURES_ENABLE parameter is set to 11.1.0.7:
http://oracle-randolf.blogspot.com/2011/07/cost-is-time-next-generation.html]]></description>
		<content:encoded><![CDATA[<p>Bhavik,</p>
<p>Thank you for posting the above information.  </p>
<p>The posted execution plan with the LEADING HINT is interesting.  Notice that the optimizer has introduced a HASH JOIN operation in place of the two NESTED LOOPS operation, and that it is predicting that only a single row in the GC_TRANSACTIONS table has a GC_TRANSACTION_TYPE_ID of 11 based on the row in the plan with an ID of 7 &#8211; usage of that index appears to be quite inefficient due to the calculated cost of 9541.</p>
<p>You may also notice a bug in the execution plan, where the cost of accessing the I_GCT_CUSMKTLSTUPD index is the same cost as that of the parent operation (the table GC_TRANSACTIONS) &#8211; the optimizer is NOT taking into account the cost of the table access which should increase the calculated cost by at least 1 per expected row returned.  I think that I have a blog article on this site that describes this problem which seemed to be related to collecting statistics for the indexes and tables when the tables contain no rows (and thus do not have a data segment yet by default due to deferred segment creation), one that was identified by Randolf Geist &#8211; I will have to do some searching to find the article.</p>
<p>The decision to use the INDEX SKIP SCAN operation on the I_GCT_CUSMKTLSTUPD index may be either due to a bug, adjusted skip scan costing in 11.2.0.2, or the setting of optimizer_index_cost_adj=10 that essentially causes the optimizer to take the calculated cost of the index skip scan at 95,410, multiply that value by 0.10, and determine that the index skip scan is efficient.  The cardinality estimate of 1 is the reason why, by default, that row source is selected as the driving table in the join.</p>
<p>It appears that both of the database instances are using NOWORKLOAD system statistics (although with a different value in the FLAGS column), with one of the instances having an estimated calculated CPU processing speed that is roughly 3 times faster than the other &#8211; that is enough of a change by itself to affect the decisions made by the optimizer.  Randolf Geist has a very good series of articles that describe the affects of NOWORKLOAD and WORKLOAD system statistics, and he also shows how to alter those system statistics. You will need to force a hard parse by modifying the SQL statement (with a comment or additional white space) to see if adjusting the CPUSPEEDNW system statistic to a value of 522 in the 11.2.0.2 database causes a desired change in the execution plan (keep in mind, that like the OPTIMIZER_INDEX_COST_ADJ parameter, that this is a global change that could negatively affect other SQL statements).  You can access Randolf&#8217;s article series here:<br />
<a href="http://oracle-randolf.blogspot.com/2009/05/understanding-different-modes-of-system.html" rel="nofollow">http://oracle-randolf.blogspot.com/2009/05/understanding-different-modes-of-system.html</a></p>
<p>Randolf&#8217;s blog also contains an article that describes costing calculation changes that were introduced in Oracle Database 11.2.0.1 and 11.2.0.2 &#8211; these changes <i>may</i> still affect the 11.2.0.2 database when the OPTIMIZER_FEATURES_ENABLE parameter is set to 11.1.0.7:<br />
<a href="http://oracle-randolf.blogspot.com/2011/07/cost-is-time-next-generation.html" rel="nofollow">http://oracle-randolf.blogspot.com/2011/07/cost-is-time-next-generation.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhavik Desai</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4726</link>
		<dc:creator><![CDATA[Bhavik Desai]]></dc:creator>
		<pubDate>Thu, 31 May 2012 18:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4726</guid>
		<description><![CDATA[Charles/Tony

I ran Charles&#039;s test on my both instances and it gave exactly the same plan as Charles&#039;s had mentioned here. I got same plan for both opt_feat versions in each db.]]></description>
		<content:encoded><![CDATA[<p>Charles/Tony</p>
<p>I ran Charles&#8217;s test on my both instances and it gave exactly the same plan as Charles&#8217;s had mentioned here. I got same plan for both opt_feat versions in each db.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhavik Desai</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4725</link>
		<dc:creator><![CDATA[Bhavik Desai]]></dc:creator>
		<pubDate>Thu, 31 May 2012 17:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4725</guid>
		<description><![CDATA[Thanks Charles.
I have 6845871=ENABLE in both dbs. I have confirmed this by looking 10053 in both.

1) Histograms on GC_TRANSACTIONS.TRANSACTION_DATE_UTC exists (254 buckets) on both dbs.
2)
11.1.0.7
&lt;pre&gt;
PNAME                PVAL1 PVAL2
--------------- ---------- --------------------
STATUS                     COMPLETED
DSTART                     06-28-2005 01:18
DSTOP                      06-28-2005 01:18
FLAGS                    1
CPUSPEEDNW      522.482014
IOSEEKTIM               10
IOTFRSPEED            4096
&lt;/pre&gt;

11.2.0.2
&lt;pre&gt;
PNAME                PVAL1 PVAL2
--------------- ---------- --------------------
STATUS                     COMPLETED
DSTART                     07-29-2011 09:37
DSTOP                      07-29-2011 09:37
FLAGS                    0
CPUSPEEDNW        1738.625
IOSEEKTIM               10
IOTFRSPEED            4096
&lt;/pre&gt;

3) I played arround with _push_join_union_view and _gby_hash_aggregation_enabled to produce good plan but it did not help.
4) i had to cancel execution in 11.2.0.2 after 10 min. Thats the reason why i did not put &#039;GATHER_PLAN_STATISTICS&#039; plan for 11.2.0.2
5) With leading hint ( /*+leading(giftcertif0_) */ ) in 11.2.0.2 i got below plan

&lt;pre&gt;
Plan hash value: 437649658

-------------------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation                      &#124; Name               &#124; Rows  &#124; Bytes &#124;TempSpc&#124; Cost (%CPU)&#124; Time     &#124;
-------------------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT               &#124;                    &#124;     1 &#124;   148 &#124;       &#124;  9722   (1)&#124; 00:01:57 &#124;
&#124;*  1 &#124;  COUNT STOPKEY                 &#124;                    &#124;       &#124;       &#124;       &#124;            &#124;          &#124;
&#124;*  2 &#124;   FILTER                       &#124;                    &#124;       &#124;       &#124;       &#124;            &#124;          &#124;
&#124;*  3 &#124;    HASH JOIN                   &#124;                    &#124;     1 &#124;   148 &#124;  2176K&#124;  9722   (1)&#124; 00:01:57 &#124;
&#124;   4 &#124;     TABLE ACCESS BY INDEX ROWID&#124; GIFT_CERTIFICATES  &#124; 16955 &#124;  1970K&#124;       &#124;    74   (0)&#124; 00:00:01 &#124;
&#124;*  5 &#124;      INDEX RANGE SCAN          &#124; I_GC_GCSID         &#124; 16955 &#124;       &#124;       &#124;     9   (0)&#124; 00:00:01 &#124;
&#124;*  6 &#124;     TABLE ACCESS BY INDEX ROWID&#124; GC_TRANSACTIONS    &#124;     1 &#124;    29 &#124;       &#124;  9541   (1)&#124; 00:01:55 &#124;
&#124;*  7 &#124;      INDEX SKIP SCAN           &#124; I_GCT_CUSMKTLSTUPD &#124;     1 &#124;       &#124;       &#124;  9541   (1)&#124; 00:01:55 &#124;
-------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM&lt;=1000)
   2 - filter(SYSDATE@!-300.0 AND &quot;GCTRANSACT1_&quot;.&quot;TRANSACTION_DATE_UTC&quot;&gt;SYSDATE@!-30 AND
              &quot;GCTRANSACT1_&quot;.&quot;TRANSACTION_DATE_UTC&quot;&lt;SYSDATE@!-.5)
   7 - access(&quot;GCTRANSACT1_&quot;.&quot;GC_TRANSACTION_TYPE_ID&quot;=11)
       filter(&quot;GCTRANSACT1_&quot;.&quot;GC_TRANSACTION_TYPE_ID&quot;=11)
&lt;/pre&gt;

I had to put additional index(gctransact1_,I_GCT_GC_ID)  hint with leading hint to produe 11.1.0.7 (good) plan
I will definitly read all_rows optimization. It did not change the plan in my case though.]]></description>
		<content:encoded><![CDATA[<p>Thanks Charles.<br />
I have 6845871=ENABLE in both dbs. I have confirmed this by looking 10053 in both.</p>
<p>1) Histograms on GC_TRANSACTIONS.TRANSACTION_DATE_UTC exists (254 buckets) on both dbs.<br />
2)<br />
11.1.0.7</p>
<pre>
PNAME                PVAL1 PVAL2
--------------- ---------- --------------------
STATUS                     COMPLETED
DSTART                     06-28-2005 01:18
DSTOP                      06-28-2005 01:18
FLAGS                    1
CPUSPEEDNW      522.482014
IOSEEKTIM               10
IOTFRSPEED            4096
</pre>
<p>11.2.0.2</p>
<pre>
PNAME                PVAL1 PVAL2
--------------- ---------- --------------------
STATUS                     COMPLETED
DSTART                     07-29-2011 09:37
DSTOP                      07-29-2011 09:37
FLAGS                    0
CPUSPEEDNW        1738.625
IOSEEKTIM               10
IOTFRSPEED            4096
</pre>
<p>3) I played arround with _push_join_union_view and _gby_hash_aggregation_enabled to produce good plan but it did not help.<br />
4) i had to cancel execution in 11.2.0.2 after 10 min. Thats the reason why i did not put &#8216;GATHER_PLAN_STATISTICS&#8217; plan for 11.2.0.2<br />
5) With leading hint ( /*+leading(giftcertif0_) */ ) in 11.2.0.2 i got below plan</p>
<pre>
Plan hash value: 437649658

-------------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                    |     1 |   148 |       |  9722   (1)| 00:01:57 |
|*  1 |  COUNT STOPKEY                 |                    |       |       |       |            |          |
|*  2 |   FILTER                       |                    |       |       |       |            |          |
|*  3 |    HASH JOIN                   |                    |     1 |   148 |  2176K|  9722   (1)| 00:01:57 |
|   4 |     TABLE ACCESS BY INDEX ROWID| GIFT_CERTIFICATES  | 16955 |  1970K|       |    74   (0)| 00:00:01 |
|*  5 |      INDEX RANGE SCAN          | I_GC_GCSID         | 16955 |       |       |     9   (0)| 00:00:01 |
|*  6 |     TABLE ACCESS BY INDEX ROWID| GC_TRANSACTIONS    |     1 |    29 |       |  9541   (1)| 00:01:55 |
|*  7 |      INDEX SKIP SCAN           | I_GCT_CUSMKTLSTUPD |     1 |       |       |  9541   (1)| 00:01:55 |
-------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM&lt;=1000)
   2 - filter(SYSDATE@!-300.0 AND "GCTRANSACT1_"."TRANSACTION_DATE_UTC"&gt;SYSDATE@!-30 AND
              "GCTRANSACT1_"."TRANSACTION_DATE_UTC"&lt;SYSDATE@!-.5)
   7 - access(&quot;GCTRANSACT1_&quot;.&quot;GC_TRANSACTION_TYPE_ID&quot;=11)
       filter(&quot;GCTRANSACT1_&quot;.&quot;GC_TRANSACTION_TYPE_ID&quot;=11)
</pre>
<p>I had to put additional index(gctransact1_,I_GCT_GC_ID)  hint with leading hint to produe 11.1.0.7 (good) plan<br />
I will definitly read all_rows optimization. It did not change the plan in my case though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4723</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Thu, 31 May 2012 11:29:14 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4723</guid>
		<description><![CDATA[Regarding the ROWNUM bug, see Metalink (MOS) Doc ID 6845871.8, Bug 6845871 &quot;Suboptimal plan from ROWNUM predicate&quot;:
https://supporthtml.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_afrLoop=4081001352865000&amp;type=DOCUMENT&amp;id=6845871.8

You can see the effects of that bug in the following OTN forum thread:
https://forums.oracle.com/forums/thread.jspa?threadID=934895&amp;start=0&amp;tstart=0

If you look through a 10053 trace, you should see &quot;&lt;b&gt;fix  6845871 = enabled&lt;/b&gt;&quot; in the &quot;Bug Fix Control Environment&quot; list - that is the fix for the ROWNUM cardinality bug.  In theory, setting OPTIMIZER_FEATURES_ENABLED to 11.1.0.7 should change &quot;&lt;b&gt;fix  6845871 = enabled&lt;/b&gt;&quot; to &quot;&lt;b&gt;fix  6845871 = disabled&lt;/b&gt;&quot; to be consistent with the behavior of the 11.1.0.7 optimizer, but that does not seem to happen.

If I am reading your OTN post correctly, you are attempting to compare performance between two entirely different databases (and of course database instances).
1. The statistics (table and/or index) statistics could be different - something as simple as a histogram on the GC_TRANSACTIONS.TRANSACTION_DATE_UTC column in one of the databases but not the other could be the cause.
2. Different system statistics for the two databases could be a secondary cause, you can check with:
&lt;pre&gt;
COLUMN PNAME FORMAT A15
COLUMN PVAL2 FORMAT A20
SELECT
  PNAME,
  PVAL1,
  PVAL2
FROM
  SYS.AUX_STATS$; 
&lt;/pre&gt;
3. The optimizer parameters are different for the two databases.  _push_join_union_view and _gby_hash_aggregation_enabled are set to non-default values in the 11.2.0.2 test, while still set to their defaults in the 11.1.0.7 test.  There may be other parameter differences that are not obvious.
4. How did you make the execution plan show the &quot;A-Rows&quot; and &quot;A-Time&quot; columns in one database, but not in the other?  Was the STATISTICS_LEVEL parameter changed from TYPICAL to ALL in one of the databases, but not the other - that change can impact performance, I suggest verifying that the STATISTICS_LEVEL is set to TYPICAL in both databases.

To make certain that we are comparing consistent information, add a GATHER_PLAN_STATISTICS hint immediately after the first SELECT keyword, like this:
&lt;pre&gt;
  select /*+ GATHER_PLAN_STATISTICS +/  * 
    from
        ( select
giftcertif0
&lt;/pre&gt;
Execute the SQL statement twice (that way we pre-load the buffer cache for the second execution, or to Tony&#039;s point, you can flush the BUFFER_CACHE and execute the SQL statement a single time), then display the execution plan with the following commands:
&lt;pre&gt;
SET LINESIZE 150
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,&#039;ALLSTATS LAST +COST +OUTLINE&#039;));
&lt;/pre&gt;

While not a good starting point, keep in mind that you can hint the order of the tables with the LEADING hint (this hint would need to appear after the second SELECT keyword in this SQL statement) and you can hint the OPTIMIZER_FEATURES_ENABLED parameter (this hint would need to appear after the first SELECT keyword in this SQL statement).

Why are you using OPTIMIZER_MODE=FIRST_ROWS_10 rather than ALL_ROWS?  Please see the following article: http://jonathanlewis.wordpress.com/2008/11/11/first_rows_n/]]></description>
		<content:encoded><![CDATA[<p>Regarding the ROWNUM bug, see Metalink (MOS) Doc ID 6845871.8, Bug 6845871 &#8220;Suboptimal plan from ROWNUM predicate&#8221;:<br />
<a href="https://supporthtml.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_afrLoop=4081001352865000&#038;type=DOCUMENT&#038;id=6845871.8" rel="nofollow">https://supporthtml.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_afrLoop=4081001352865000&#038;type=DOCUMENT&#038;id=6845871.8</a></p>
<p>You can see the effects of that bug in the following OTN forum thread:<br />
<a href="https://forums.oracle.com/forums/thread.jspa?threadID=934895&#038;start=0&#038;tstart=0" rel="nofollow">https://forums.oracle.com/forums/thread.jspa?threadID=934895&#038;start=0&#038;tstart=0</a></p>
<p>If you look through a 10053 trace, you should see &#8220;<b>fix  6845871 = enabled</b>&#8221; in the &#8220;Bug Fix Control Environment&#8221; list &#8211; that is the fix for the ROWNUM cardinality bug.  In theory, setting OPTIMIZER_FEATURES_ENABLED to 11.1.0.7 should change &#8220;<b>fix  6845871 = enabled</b>&#8221; to &#8220;<b>fix  6845871 = disabled</b>&#8221; to be consistent with the behavior of the 11.1.0.7 optimizer, but that does not seem to happen.</p>
<p>If I am reading your OTN post correctly, you are attempting to compare performance between two entirely different databases (and of course database instances).<br />
1. The statistics (table and/or index) statistics could be different &#8211; something as simple as a histogram on the GC_TRANSACTIONS.TRANSACTION_DATE_UTC column in one of the databases but not the other could be the cause.<br />
2. Different system statistics for the two databases could be a secondary cause, you can check with:</p>
<pre>
COLUMN PNAME FORMAT A15
COLUMN PVAL2 FORMAT A20
SELECT
  PNAME,
  PVAL1,
  PVAL2
FROM
  SYS.AUX_STATS$; 
</pre>
<p>3. The optimizer parameters are different for the two databases.  _push_join_union_view and _gby_hash_aggregation_enabled are set to non-default values in the 11.2.0.2 test, while still set to their defaults in the 11.1.0.7 test.  There may be other parameter differences that are not obvious.<br />
4. How did you make the execution plan show the &#8220;A-Rows&#8221; and &#8220;A-Time&#8221; columns in one database, but not in the other?  Was the STATISTICS_LEVEL parameter changed from TYPICAL to ALL in one of the databases, but not the other &#8211; that change can impact performance, I suggest verifying that the STATISTICS_LEVEL is set to TYPICAL in both databases.</p>
<p>To make certain that we are comparing consistent information, add a GATHER_PLAN_STATISTICS hint immediately after the first SELECT keyword, like this:</p>
<pre>
  select /*+ GATHER_PLAN_STATISTICS +/  * 
    from
        ( select
giftcertif0
</pre>
<p>Execute the SQL statement twice (that way we pre-load the buffer cache for the second execution, or to Tony&#8217;s point, you can flush the BUFFER_CACHE and execute the SQL statement a single time), then display the execution plan with the following commands:</p>
<pre>
SET LINESIZE 150
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,'ALLSTATS LAST +COST +OUTLINE'));
</pre>
<p>While not a good starting point, keep in mind that you can hint the order of the tables with the LEADING hint (this hint would need to appear after the second SELECT keyword in this SQL statement) and you can hint the OPTIMIZER_FEATURES_ENABLED parameter (this hint would need to appear after the first SELECT keyword in this SQL statement).</p>
<p>Why are you using OPTIMIZER_MODE=FIRST_ROWS_10 rather than ALL_ROWS?  Please see the following article: <a href="http://jonathanlewis.wordpress.com/2008/11/11/first_rows_n/" rel="nofollow">http://jonathanlewis.wordpress.com/2008/11/11/first_rows_n/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Sleight</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4722</link>
		<dc:creator><![CDATA[Tony Sleight]]></dc:creator>
		<pubDate>Thu, 31 May 2012 10:15:35 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4722</guid>
		<description><![CDATA[I think the OP has not supplied the full story.

The OP should run your test case and validate the results.

Your test case didn&#039;t flush the buffer cache for the second run, so it may be that in your test the data was already in the cache.  A flush of the buffer cache prior to the second run would answer that question.]]></description>
		<content:encoded><![CDATA[<p>I think the OP has not supplied the full story.</p>
<p>The OP should run your test case and validate the results.</p>
<p>Your test case didn&#8217;t flush the buffer cache for the second run, so it may be that in your test the data was already in the cache.  A flush of the buffer cache prior to the second run would answer that question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhavik Desai</title>
		<link>http://hoopercharles.wordpress.com/2012/05/30/execution-plan-changes-when-the-optimizer_features_enabled-parameter-is-changed-but-why/#comment-4719</link>
		<dc:creator><![CDATA[Bhavik Desai]]></dc:creator>
		<pubDate>Thu, 31 May 2012 06:14:48 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6372#comment-4719</guid>
		<description><![CDATA[Thanks Charles for putting my OTN thread here. I am sure it will catch some interesting eye.
Today i tried setting optimizer_features_enable=11.2.0.2 on 11gr1 db and got index skip scan plan (bad plan in 11.2.0.2)

Giving you sql
&lt;pre&gt;
  select  * 
    from
        ( select
giftcertif0_.GC_ID as GC1_2_,giftcertif0_.RECORD_VERSION_NUMBER as RECORD2_2_,giftcertif0_.GC_ORDER_ID as GC3_2_,giftcertif0_.EXTERNAL_GC_ITEM_ID as EXTERNAL4_2_,
giftcertif0_.CLAIMING_CUSTOMER_ID as CLAIMING5_2_,giftcertif0_.GC_STATUS_ID as GC6_2_,giftcertif0_.MARKETPLACE_ID as MARKETPL7_2_,giftcertif0_.GC_BALANCE_SHARING_ID as GC8_2_,
giftcertif0_.ENCRYPTED_CLAIM_CODE as ENCRYPTED9_2_,giftcertif0_.DENOMINATION_AMOUNT as DENOMIN10_2_,giftcertif0_.BASE_CURRENCY_CODE as BASE11_2_,
giftcertif0_.REMAINING_AMOUNT as REMAINING12_2_,giftcertif0_.EXPIRATION_DATE as EXPIRATION13_2_,giftcertif0_.PURCHASING_CUSTOMER_ID as PURCHASING14_2_,
giftcertif0_.PURCHASER_IP_ADDRESS as PURCHASER15_2_,giftcertif0_.IS_LOCKED as IS16_2_,giftcertif0_.IS_BREAKAGE as IS17_2_,giftcertif0_.LOCK_CHANGED_BY as LOCK18_2_,
giftcertif0_.LOCK_CHANGED_DATE_UTC as LOCK19_2_,giftcertif0_.GC_ORDER_ITEM_LINE_NUMBER as GC20_2_,giftcertif0_.CLAIM_CODE_TYPE_ID as CLAIM21_2_,giftcertif0_.LAST_UPDATED as LAST22_2_,
giftcertif0_.CREATION_DATE as CREATION23_2_ 
        from
            GIFT_CERTIFICATES giftcertif0_,
            GC_TRANSACTIONS gctransact1_ 
        where
 giftcertif0_.GC_STATUS_ID=7 
 and giftcertif0_.GC_ID=gctransact1_.GC_ID  
 and gctransact1_.GC_TRANSACTION_TYPE_ID=11  and gctransact1_.AMOUNT&gt;0.0 
 and (gctransact1_.EXTERNAL_GC_EXECUTION_ID like &#039;csc-r-%&#039; ) 
 and gctransact1_.TRANSACTION_DATE_UTC&gt;sysdate-30.0 
 and gctransact1_.TRANSACTION_DATE_UTC&lt;sysdate-0.5 
 ) 
where rownum &lt;= 1000;
&lt;/pre&gt;
GC_STATUS_ID=7  is ~ 13k in both db.

I am trying to understand what is causing GC_TRANSACTIONS as leading table during join with optimizer_features_enable= 11.2.0.2.

Can you shed more details on ROWNUM bug you have mentioned initially ?
I changed optimizer_mode=first_rows_1000 in 11.2.0.2 but could not get good plan

10053 trace on 11.2.0.2 says following :
&lt;pre&gt;
Best:: AccessPath: IndexRange
  Index: I_GC_GCSID
         Cost: 74.39  Degree: 1  Resp: 74.39  Card: 16954.64  Bytes: 0
&lt;/pre&gt;

Even though it selects PK_GIFT_CERTIFICATES index in execution plan.]]></description>
		<content:encoded><![CDATA[<p>Thanks Charles for putting my OTN thread here. I am sure it will catch some interesting eye.<br />
Today i tried setting optimizer_features_enable=11.2.0.2 on 11gr1 db and got index skip scan plan (bad plan in 11.2.0.2)</p>
<p>Giving you sql</p>
<pre>
  select  * 
    from
        ( select
giftcertif0_.GC_ID as GC1_2_,giftcertif0_.RECORD_VERSION_NUMBER as RECORD2_2_,giftcertif0_.GC_ORDER_ID as GC3_2_,giftcertif0_.EXTERNAL_GC_ITEM_ID as EXTERNAL4_2_,
giftcertif0_.CLAIMING_CUSTOMER_ID as CLAIMING5_2_,giftcertif0_.GC_STATUS_ID as GC6_2_,giftcertif0_.MARKETPLACE_ID as MARKETPL7_2_,giftcertif0_.GC_BALANCE_SHARING_ID as GC8_2_,
giftcertif0_.ENCRYPTED_CLAIM_CODE as ENCRYPTED9_2_,giftcertif0_.DENOMINATION_AMOUNT as DENOMIN10_2_,giftcertif0_.BASE_CURRENCY_CODE as BASE11_2_,
giftcertif0_.REMAINING_AMOUNT as REMAINING12_2_,giftcertif0_.EXPIRATION_DATE as EXPIRATION13_2_,giftcertif0_.PURCHASING_CUSTOMER_ID as PURCHASING14_2_,
giftcertif0_.PURCHASER_IP_ADDRESS as PURCHASER15_2_,giftcertif0_.IS_LOCKED as IS16_2_,giftcertif0_.IS_BREAKAGE as IS17_2_,giftcertif0_.LOCK_CHANGED_BY as LOCK18_2_,
giftcertif0_.LOCK_CHANGED_DATE_UTC as LOCK19_2_,giftcertif0_.GC_ORDER_ITEM_LINE_NUMBER as GC20_2_,giftcertif0_.CLAIM_CODE_TYPE_ID as CLAIM21_2_,giftcertif0_.LAST_UPDATED as LAST22_2_,
giftcertif0_.CREATION_DATE as CREATION23_2_ 
        from
            GIFT_CERTIFICATES giftcertif0_,
            GC_TRANSACTIONS gctransact1_ 
        where
 giftcertif0_.GC_STATUS_ID=7 
 and giftcertif0_.GC_ID=gctransact1_.GC_ID  
 and gctransact1_.GC_TRANSACTION_TYPE_ID=11  and gctransact1_.AMOUNT&gt;0.0 
 and (gctransact1_.EXTERNAL_GC_EXECUTION_ID like 'csc-r-%' ) 
 and gctransact1_.TRANSACTION_DATE_UTC&gt;sysdate-30.0 
 and gctransact1_.TRANSACTION_DATE_UTC&lt;sysdate-0.5 
 ) 
where rownum &lt;= 1000;
</pre>
<p>GC_STATUS_ID=7  is ~ 13k in both db.</p>
<p>I am trying to understand what is causing GC_TRANSACTIONS as leading table during join with optimizer_features_enable= 11.2.0.2.</p>
<p>Can you shed more details on ROWNUM bug you have mentioned initially ?<br />
I changed optimizer_mode=first_rows_1000 in 11.2.0.2 but could not get good plan</p>
<p>10053 trace on 11.2.0.2 says following :</p>
<pre>
Best:: AccessPath: IndexRange
  Index: I_GC_GCSID
         Cost: 74.39  Degree: 1  Resp: 74.39  Card: 16954.64  Bytes: 0
</pre>
<p>Even though it selects PK_GIFT_CERTIFICATES index in execution plan.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
