<?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: Give Me a Hint &#8211; How were These Autotrace Execution Statistics Achieved?</title>
	<atom:link href="http://hoopercharles.wordpress.com/2011/06/27/give-me-a-hint-how-were-these-autotrace-execution-statistics-achieved/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2011/06/27/give-me-a-hint-how-were-these-autotrace-execution-statistics-achieved/</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/2011/06/27/give-me-a-hint-how-were-these-autotrace-execution-statistics-achieved/#comment-3576</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Fri, 01 Jul 2011 12:05:06 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5048#comment-3576</guid>
		<description><![CDATA[Randolf Geist is quite knowledgeable about this topic - I suspect that he probably could have covered the topic in less than 100 slides in his presentation (I have only made it about 1/3 the way through the presentation slides this time).  :-)  Thanks for providing another useful link.

Considering the following in the OP&#039;s email:
* The execution plans were (apparently, but not necessarily) the same
* The FIRST_ROWS hinted version of the query completed 24 seconds faster (1.79 times faster) than then FIRST_ROWS(100) hinted version of the query
* The calculated cost of FIRST_ROWS hinted version of the query is 8591 times greater than the calculated cost of the  FIRST_ROWS(100) hinted version of the query

I think that it is safe to say that the FIRST_ROWS hint (and optimizer mode) does not cause something magic to happen in the database instance, where 8591 times as much work is accomplished in 55.86% of the amount of time - just in case someone was confused, and attempting to tune by the calculated cost that appears in execution plans.]]></description>
		<content:encoded><![CDATA[<p>Randolf Geist is quite knowledgeable about this topic &#8211; I suspect that he probably could have covered the topic in less than 100 slides in his presentation (I have only made it about 1/3 the way through the presentation slides this time).  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Thanks for providing another useful link.</p>
<p>Considering the following in the OP&#8217;s email:<br />
* The execution plans were (apparently, but not necessarily) the same<br />
* The FIRST_ROWS hinted version of the query completed 24 seconds faster (1.79 times faster) than then FIRST_ROWS(100) hinted version of the query<br />
* The calculated cost of FIRST_ROWS hinted version of the query is 8591 times greater than the calculated cost of the  FIRST_ROWS(100) hinted version of the query</p>
<p>I think that it is safe to say that the FIRST_ROWS hint (and optimizer mode) does not cause something magic to happen in the database instance, where 8591 times as much work is accomplished in 55.86% of the amount of time &#8211; just in case someone was confused, and attempting to tune by the calculated cost that appears in execution plans.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Preiss</title>
		<link>http://hoopercharles.wordpress.com/2011/06/27/give-me-a-hint-how-were-these-autotrace-execution-statistics-achieved/#comment-3572</link>
		<dc:creator><![CDATA[Martin Preiss]]></dc:creator>
		<pubDate>Thu, 30 Jun 2011 15:37:37 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5048#comment-3572</guid>
		<description><![CDATA[Charles,
thank you for providing the interesting details: obviously the topic is much more difficult than I thougth ... - even for FIRST_ROWS.
I published a sligthly expanded version of my test in my (german) blog and got a comment from (your apress co-author) Randolf Geist, who explained that the costing for FIRST_ROWS and FIRST_ROWS(n) is quite complex and added a link to his UKOUG 2009 (130 page) presentation &quot;Everything You Wanted To Know About FIRST_ROWS_n But Were Afraid To Ask&quot;: http://www.sqltools-plusplus.org:7676/media/FIRST_ROWS_n%20presentation%20UKOUG%202009%20notes.pdf. It&#039;s amazing what you can find out about Oracle and the cbo if you look close enough.

Regards

Martin]]></description>
		<content:encoded><![CDATA[<p>Charles,<br />
thank you for providing the interesting details: obviously the topic is much more difficult than I thougth &#8230; &#8211; even for FIRST_ROWS.<br />
I published a sligthly expanded version of my test in my (german) blog and got a comment from (your apress co-author) Randolf Geist, who explained that the costing for FIRST_ROWS and FIRST_ROWS(n) is quite complex and added a link to his UKOUG 2009 (130 page) presentation &#8220;Everything You Wanted To Know About FIRST_ROWS_n But Were Afraid To Ask&#8221;: <a href="http://www.sqltools-plusplus.org:7676/media/FIRST_ROWS_n%20presentation%20UKOUG%202009%20notes.pdf" rel="nofollow">http://www.sqltools-plusplus.org:7676/media/FIRST_ROWS_n%20presentation%20UKOUG%202009%20notes.pdf</a>. It&#8217;s amazing what you can find out about Oracle and the cbo if you look close enough.</p>
<p>Regards</p>
<p>Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/06/27/give-me-a-hint-how-were-these-autotrace-execution-statistics-achieved/#comment-3571</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Thu, 30 Jun 2011 11:14:06 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5048#comment-3571</guid>
		<description><![CDATA[Martin,

Thanks for noticing and pointing out the costing difference between the FIRST_ROWS and FIRST_ROWS(100) - sorry for the delayed response (and thanks for finding the related article).  I repeated your test case and obtained similar results on Oracle Database 11.2.0.2:
&lt;pre&gt;
SET AUTOTRACE TRACEONLY EXPLAIN
 
select /*+ first_rows */ * from test_first_rows_hint;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 3818872010
 
------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation         &#124; Name                 &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT  &#124;                      &#124;  1000K&#124;  4882K&#124;   427   (1)&#124; 00:00:06 &#124;
&#124;   1 &#124;  TABLE ACCESS FULL&#124; TEST_FIRST_ROWS_HINT &#124;  1000K&#124;  4882K&#124;   427   (1)&#124; 00:00:06 &#124;
------------------------------------------------------------------------------------------
&lt;/pre&gt;

Then I went through the sequence of FIRST_ROW(n) hints:
&lt;pre&gt;
select /*+ first_rows(1) */ * from test_first_rows_hint;
&lt;/pre&gt;

These are my results:
- first_rows: 427 (same as without a hint)
- first_rows(1): 2
- first_rows(1000): 2
- first_rows(10000): 6
- first_rows(100000): 44
- first_rows(500000): 216

Now let&#039;s add an index into the test case to see what happens:
&lt;pre&gt;
CREATE INDEX IND_TEST_FIRST ON TEST_FIRST_ROWS_HINT(ID);
 
EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=&gt;USER, TABNAME=&gt;&#039;TEST_FIRST_ROWS_HINT&#039;, CASCADE=&gt;TRUE, ESTIMATE_PERCENT=&gt;100)
&lt;/pre&gt;

Making a small modification to add a WHERE clause:
&lt;pre&gt;
select * from test_first_rows_hint WHERE ID&lt;=500000;
  
Execution Plan
----------------------------------------------------------
Plan hash value: 3818872010
 
------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation         &#124; Name                 &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT  &#124;                      &#124;   500K&#124;  2441K&#124;   429   (2)&#124; 00:00:06 &#124;
&#124;*  1 &#124;  TABLE ACCESS FULL&#124; TEST_FIRST_ROWS_HINT &#124;   500K&#124;  2441K&#124;   429   (2)&#124; 00:00:06 &#124;
------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(&quot;ID&quot;&lt;=500000)
&lt;/pre&gt;

Interestingly, the cost of the unhinted plan increased by 2 after adding the index - a minor change, but still something that is interesting.

Let&#039;s go through the various FIRST_ROWS and FIRST_ROWS(n) hints:
&lt;pre&gt;
select /*+ first_rows */ * from test_first_rows_hint WHERE ID&lt;=500000;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 230930807
 
-----------------------------------------------------------------------------------
&#124; Id  &#124; Operation        &#124; Name           &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
-----------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT &#124;                &#124;   500K&#124;  2441K&#124;  1119   (1)&#124; 00:00:14 &#124;
&#124;*  1 &#124;  INDEX RANGE SCAN&#124; IND_TEST_FIRST &#124;   500K&#124;  2441K&#124;  1119   (1)&#124; 00:00:14 &#124;
-----------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access(&quot;ID&quot;&lt;=500000)
&lt;/pre&gt;

- first_rows: 1119 (more than twice without a hint)
- first_rows(1): 3
- first_rows(1000): 5
- first_rows(10000): 25
- first_rows(100000): 227
- first_rows(500000): 429 (full table scan)

Note in the above that there is a bit of logic in the FIRST_ROWS(n) optimizer mode, the optimizer switched from an index range scan to a full table scan when it sensed that we *promised* to retrieve all rows in the result set.  It *almost* appears that the optimizer switched based on the calculated cost of the access path.

Let&#039;s try again, bumping up the 500,000 number to 1,000,000:
&lt;pre&gt;
select /*+ first_rows */ * from test_first_rows_hint WHERE ID&lt;=1000000;
  
Execution Plan
----------------------------------------------------------
Plan hash value: 230930807

-----------------------------------------------------------------------------------
&#124; Id  &#124; Operation        &#124; Name           &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
-----------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT &#124;                &#124;  1000K&#124;  4882K&#124;  2234   (1)&#124; 00:00:27 &#124;
&#124;*  1 &#124;  INDEX RANGE SCAN&#124; IND_TEST_FIRST &#124;  1000K&#124;  4882K&#124;  2234   (1)&#124; 00:00:27 &#124;
-----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access(&quot;ID&quot;&lt;=1000000)
&lt;/pre&gt;

The above suggests that the FIRST_ROWS hint calculates the cost such that we will work all the way through the data, yet the optimizer selects the index access path even though the WHERE clause tells the optimizer that according to the statistics we will be taking all rows in the table.

- first_rows: 2234 (more than twice without a hint)
- first_rows(1): 3
- first_rows(1000): 5
- first_rows(10000): 25
- first_rows(100000): 226
- first_rows(500000): 1118 (still an index range scan)
- first_rows(1000000): 429 (full table scan)

The FIRST_ROWS(n) optimizer mode sensed that we *promised* to take only the specified number of rows.  An interesting thing happened when 500000 was specified in the hint - the optimizer did not switch to a full table scan based on a cost comparison (maybe that only happens when the index contains all of the data, thus avoiding the need to directly access the table?).

Just a quick experiment:
&lt;pre&gt;
SQL&gt; select /*+ first_rows(999999) */ * from test_first_rows_hint WHERE ID&lt;=1000000;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 230930807
 
-----------------------------------------------------------------------------------
&#124; Id  &#124; Operation        &#124; Name           &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
-----------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT &#124;                &#124;  1000K&#124;  4882K&#124;  2234   (1)&#124; 00:00:27 &#124;
&#124;*  1 &#124;  INDEX RANGE SCAN&#124; IND_TEST_FIRST &#124;  1000K&#124;  4882K&#124;  2234   (1)&#124; 00:00:27 &#124;
-----------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access(&quot;ID&quot;&lt;=1000000)
&lt;/pre&gt;
 
&lt;pre&gt;
SQL&gt; select /*+ first_rows(1000000) */ * from test_first_rows_hint WHERE ID&lt;=1000000;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 3818872010
 
------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation         &#124; Name                 &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT  &#124;                      &#124;  1000K&#124;  4882K&#124;   429   (2)&#124; 00:00:06 &#124;
&#124;*  1 &#124;  TABLE ACCESS FULL&#124; TEST_FIRST_ROWS_HINT &#124;  1000K&#124;  4882K&#124;   429   (2)&#124; 00:00:06 &#124;
------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(&quot;ID&quot;&lt;=1000000)
&lt;/pre&gt;

As shown by the above, the tipping point in this test case appears to be right at the point where the hint&#039;s &lt;i&gt;n&lt;/i&gt; value matches the expected number of rows to be returned.]]></description>
		<content:encoded><![CDATA[<p>Martin,</p>
<p>Thanks for noticing and pointing out the costing difference between the FIRST_ROWS and FIRST_ROWS(100) &#8211; sorry for the delayed response (and thanks for finding the related article).  I repeated your test case and obtained similar results on Oracle Database 11.2.0.2:</p>
<pre>
SET AUTOTRACE TRACEONLY EXPLAIN
 
select /*+ first_rows */ * from test_first_rows_hint;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 3818872010
 
------------------------------------------------------------------------------------------
| Id  | Operation         | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                      |  1000K|  4882K|   427   (1)| 00:00:06 |
|   1 |  TABLE ACCESS FULL| TEST_FIRST_ROWS_HINT |  1000K|  4882K|   427   (1)| 00:00:06 |
------------------------------------------------------------------------------------------
</pre>
<p>Then I went through the sequence of FIRST_ROW(n) hints:</p>
<pre>
select /*+ first_rows(1) */ * from test_first_rows_hint;
</pre>
<p>These are my results:<br />
- first_rows: 427 (same as without a hint)<br />
- first_rows(1): 2<br />
- first_rows(1000): 2<br />
- first_rows(10000): 6<br />
- first_rows(100000): 44<br />
- first_rows(500000): 216</p>
<p>Now let&#8217;s add an index into the test case to see what happens:</p>
<pre>
CREATE INDEX IND_TEST_FIRST ON TEST_FIRST_ROWS_HINT(ID);
 
EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=&gt;USER, TABNAME=&gt;'TEST_FIRST_ROWS_HINT', CASCADE=&gt;TRUE, ESTIMATE_PERCENT=&gt;100)
</pre>
<p>Making a small modification to add a WHERE clause:</p>
<pre>
select * from test_first_rows_hint WHERE ID&lt;=500000;
  
Execution Plan
----------------------------------------------------------
Plan hash value: 3818872010
 
------------------------------------------------------------------------------------------
| Id  | Operation         | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                      |   500K|  2441K|   429   (2)| 00:00:06 |
|*  1 |  TABLE ACCESS FULL| TEST_FIRST_ROWS_HINT |   500K|  2441K|   429   (2)| 00:00:06 |
------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("ID"&lt;=500000)
</pre>
<p>Interestingly, the cost of the unhinted plan increased by 2 after adding the index &#8211; a minor change, but still something that is interesting.</p>
<p>Let&#8217;s go through the various FIRST_ROWS and FIRST_ROWS(n) hints:</p>
<pre>
select /*+ first_rows */ * from test_first_rows_hint WHERE ID&lt;=500000;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 230930807
 
-----------------------------------------------------------------------------------
| Id  | Operation        | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                |   500K|  2441K|  1119   (1)| 00:00:14 |
|*  1 |  INDEX RANGE SCAN| IND_TEST_FIRST |   500K|  2441K|  1119   (1)| 00:00:14 |
-----------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("ID"&lt;=500000)
</pre>
<p>- first_rows: 1119 (more than twice without a hint)<br />
- first_rows(1): 3<br />
- first_rows(1000): 5<br />
- first_rows(10000): 25<br />
- first_rows(100000): 227<br />
- first_rows(500000): 429 (full table scan)</p>
<p>Note in the above that there is a bit of logic in the FIRST_ROWS(n) optimizer mode, the optimizer switched from an index range scan to a full table scan when it sensed that we *promised* to retrieve all rows in the result set.  It *almost* appears that the optimizer switched based on the calculated cost of the access path.</p>
<p>Let&#8217;s try again, bumping up the 500,000 number to 1,000,000:</p>
<pre>
select /*+ first_rows */ * from test_first_rows_hint WHERE ID&lt;=1000000;
  
Execution Plan
----------------------------------------------------------
Plan hash value: 230930807

-----------------------------------------------------------------------------------
| Id  | Operation        | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                |  1000K|  4882K|  2234   (1)| 00:00:27 |
|*  1 |  INDEX RANGE SCAN| IND_TEST_FIRST |  1000K|  4882K|  2234   (1)| 00:00:27 |
-----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("ID"&lt;=1000000)
</pre>
<p>The above suggests that the FIRST_ROWS hint calculates the cost such that we will work all the way through the data, yet the optimizer selects the index access path even though the WHERE clause tells the optimizer that according to the statistics we will be taking all rows in the table.</p>
<p>- first_rows: 2234 (more than twice without a hint)<br />
- first_rows(1): 3<br />
- first_rows(1000): 5<br />
- first_rows(10000): 25<br />
- first_rows(100000): 226<br />
- first_rows(500000): 1118 (still an index range scan)<br />
- first_rows(1000000): 429 (full table scan)</p>
<p>The FIRST_ROWS(n) optimizer mode sensed that we *promised* to take only the specified number of rows.  An interesting thing happened when 500000 was specified in the hint &#8211; the optimizer did not switch to a full table scan based on a cost comparison (maybe that only happens when the index contains all of the data, thus avoiding the need to directly access the table?).</p>
<p>Just a quick experiment:</p>
<pre>
SQL&gt; select /*+ first_rows(999999) */ * from test_first_rows_hint WHERE ID&lt;=1000000;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 230930807
 
-----------------------------------------------------------------------------------
| Id  | Operation        | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                |  1000K|  4882K|  2234   (1)| 00:00:27 |
|*  1 |  INDEX RANGE SCAN| IND_TEST_FIRST |  1000K|  4882K|  2234   (1)| 00:00:27 |
-----------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("ID"&lt;=1000000)
</pre>
<pre>
SQL&gt; select /*+ first_rows(1000000) */ * from test_first_rows_hint WHERE ID&lt;=1000000;
 
Execution Plan
----------------------------------------------------------
Plan hash value: 3818872010
 
------------------------------------------------------------------------------------------
| Id  | Operation         | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                      |  1000K|  4882K|   429   (2)| 00:00:06 |
|*  1 |  TABLE ACCESS FULL| TEST_FIRST_ROWS_HINT |  1000K|  4882K|   429   (2)| 00:00:06 |
------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("ID"&lt;=1000000)
</pre>
<p>As shown by the above, the tipping point in this test case appears to be right at the point where the hint&#8217;s <i>n</i> value matches the expected number of rows to be returned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Preiss</title>
		<link>http://hoopercharles.wordpress.com/2011/06/27/give-me-a-hint-how-were-these-autotrace-execution-statistics-achieved/#comment-3550</link>
		<dc:creator><![CDATA[Martin Preiss]]></dc:creator>
		<pubDate>Mon, 27 Jun 2011 21:05:07 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5048#comment-3550</guid>
		<description><![CDATA[Charles,
interesting questions - to which I have no answers. The minimized window seems to me a plausible option - but I think it&#039;s almost impossible to solve this riddle based on the given data.

I was a little bit surprised to see the big differences in costing for FIRST_ROWS and FIRST_ROWS(100) - it seems that FIRST_ROWS has no impact on the cost, but FIRST_ROWS(100) reduces the cost to approximately (100/number_of_rows_in_table) * initial_cost. With a simple test table I get:
[code]
create table test_first_rows_hint
as
select rownum id
  from dual
connect by level &lt;= 1000000;

exec dbms_stats.gather_table_stats(user, &#039;TEST_FIRST_ROWS_HINT&#039;, estimate_percent =&gt; 100)

select * from test_first_rows_hint;

1000000 Zeilen ausgewõhlt.

Abgelaufen: 00:00:03.96

Ausf³hrungsplan
----------------------------------------------------------
Plan hash value: 3818872010

------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation         &#124; Name                 &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT  &#124;                      &#124;  1000K&#124;  4882K&#124;   780   (0)&#124; 00:00:04 &#124;
&#124;   1 &#124;  TABLE ACCESS FULL&#124; TEST_FIRST_ROWS_HINT &#124;  1000K&#124;  4882K&#124;   780   (0)&#124; 00:00:04 &#124;
------------------------------------------------------------------------------------------
[/code]
With Hints I get the following cost results:
- first_rows: 780 (same as without a hint)
- first_rows(1): 2
- first_rows(1000): 3
- first_rows(10000): 9
- first_rows(100000): 80
- first_rows(500000): 391

After I made this simple test I found your article http://hoopercharles.wordpress.com/2011/03/10/what-is-the-difference-between-the-first_rows-hint-and-rownum-in-the-where-clause/ - seems that I missed that one...

Regards

Martin]]></description>
		<content:encoded><![CDATA[<p>Charles,<br />
interesting questions &#8211; to which I have no answers. The minimized window seems to me a plausible option &#8211; but I think it&#8217;s almost impossible to solve this riddle based on the given data.</p>
<p>I was a little bit surprised to see the big differences in costing for FIRST_ROWS and FIRST_ROWS(100) &#8211; it seems that FIRST_ROWS has no impact on the cost, but FIRST_ROWS(100) reduces the cost to approximately (100/number_of_rows_in_table) * initial_cost. With a simple test table I get:</p>
<pre class="brush: plain; title: ; notranslate">
create table test_first_rows_hint
as
select rownum id
  from dual
connect by level &lt;= 1000000;

exec dbms_stats.gather_table_stats(user, 'TEST_FIRST_ROWS_HINT', estimate_percent =&gt; 100)

select * from test_first_rows_hint;

1000000 Zeilen ausgewõhlt.

Abgelaufen: 00:00:03.96

Ausf³hrungsplan
----------------------------------------------------------
Plan hash value: 3818872010

------------------------------------------------------------------------------------------
| Id  | Operation         | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                      |  1000K|  4882K|   780   (0)| 00:00:04 |
|   1 |  TABLE ACCESS FULL| TEST_FIRST_ROWS_HINT |  1000K|  4882K|   780   (0)| 00:00:04 |
------------------------------------------------------------------------------------------
</pre>
<p>With Hints I get the following cost results:<br />
- first_rows: 780 (same as without a hint)<br />
- first_rows(1): 2<br />
- first_rows(1000): 3<br />
- first_rows(10000): 9<br />
- first_rows(100000): 80<br />
- first_rows(500000): 391</p>
<p>After I made this simple test I found your article <a href="http://hoopercharles.wordpress.com/2011/03/10/what-is-the-difference-between-the-first_rows-hint-and-rownum-in-the-where-clause/" rel="nofollow">http://hoopercharles.wordpress.com/2011/03/10/what-is-the-difference-between-the-first_rows-hint-and-rownum-in-the-where-clause/</a> &#8211; seems that I missed that one&#8230;</p>
<p>Regards</p>
<p>Martin</p>
]]></content:encoded>
	</item>
</channel>
</rss>