<?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: Quiz Night</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sat, 18 May 2013 11:04:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34571</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 04 Oct 2009 10:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34571</guid>
		<description><![CDATA[Wolfgang,

The prize is the warm glow of satisfaction in a job well done that I have just conferred on you.

;)]]></description>
		<content:encoded><![CDATA[<p>Wolfgang,</p>
<p>The prize is the warm glow of satisfaction in a job well done that I have just conferred on you.</p>
<p>;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wolfgang</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34568</link>
		<dc:creator><![CDATA[Wolfgang]]></dc:creator>
		<pubDate>Sat, 03 Oct 2009 17:55:57 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34568</guid>
		<description><![CDATA[Thanks a lot Jonathan. By the way - what did you say was the price? A signed book of the upcoming Cost Based II? Very generous ;)

Regards
Wolfgang]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot Jonathan. By the way &#8211; what did you say was the price? A signed book of the upcoming Cost Based II? Very generous ;)</p>
<p>Regards<br />
Wolfgang</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34566</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 03 Oct 2009 15:23:40 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34566</guid>
		<description><![CDATA[And the prize goes to .... (roll of drums, long pause that gets people irritated and does nothing to raise the atmosphere) Wolfgang.

This was just a simple example to demonstrate how easy it can be to think that &quot;something&#039;s gone wrong&quot; because what you&#039;re looking at isn&#039;t 100% vanilla flavoured.

I am, however, impressed with the ingenuity used to come up with alternative reasons. I particularly liked the idea of the offline tablespace.  (I tested it, it didn&#039;t work because Oracle tried to obey the hint - but the optimizer can find a path that gets the right answer even when the &quot;real&quot; data happens to be offline.)

]]></description>
		<content:encoded><![CDATA[<p>And the prize goes to &#8230;. (roll of drums, long pause that gets people irritated and does nothing to raise the atmosphere) Wolfgang.</p>
<p>This was just a simple example to demonstrate how easy it can be to think that &#8220;something&#8217;s gone wrong&#8221; because what you&#8217;re looking at isn&#8217;t 100% vanilla flavoured.</p>
<p>I am, however, impressed with the ingenuity used to come up with alternative reasons. I particularly liked the idea of the offline tablespace.  (I tested it, it didn&#8217;t work because Oracle tried to obey the hint &#8211; but the optimizer can find a path that gets the right answer even when the &#8220;real&#8221; data happens to be offline.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34563</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Sat, 03 Oct 2009 13:27:11 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34563</guid>
		<description><![CDATA[The index creation, view creation, and statistics gathering statements were lost in my previous post &lt;em&gt;[Now fixed: JPL]&lt;/em&gt;.  The view contained an INDEX() hint.  Changing that hint to an INDEX_FFS() will result in an INDEX FAST FULL SCAN operation appearing in the plan.

Another possibility uses two schemas, with a view potentially created to implement security that also contains hints, and a public synonym.

In schema 1:
&lt;code&gt;
CREATE TABLE T1 AS
SELECT
 &#160;ROWNUM C1,
 &#160;ROWNUM*2 C2,
 &#160;LPAD(&#039; &#039;,500,&#039; &#039;) C3
FROM
 &#160;DUAL
CONNECT BY
 &#160;LEVEL &lt;= 48000;

CREATE UNIQUE INDEX T1_PK ON T1(C1);
CREATE UNIQUE INDEX T1_N2 ON T1(C1,C2);

ALTER TABLE T1 MODIFY (
 &#160;C1 NOT NULL,
 &#160;C2 NOT NULL);

EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=&gt;USER,TABNAME=&gt;&#039;T1&#039;)

CREATE OR REPLACE VIEW T1_VIEW AS
SELECT /*+ INDEX_FFS(T1_V) */
 &#160;C1,
 &#160;C2
FROM
 &#160;(SELECT
 &#160; &#160;*
 &#160;FROM
 &#160; &#160;T1) T1_V;

CREATE OR REPLACE PUBLIC SYNONYM T1 FOR T1_VIEW;

GRANT SELECT ON T1_VIEW TO PUBLIC;
GRANT SELECT ON T1 TO PUBLIC;
&lt;/code&gt;

In schema 2:
&lt;code&gt;
select /*+ full(t) */ count(*) from t1 t;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); 

Plan hash value: 1018460547

-----------------------------------------------------------------------
&#124; Id &#160;&#124; Operation &#160; &#160; &#160; &#160; &#160; &#160; &#124; Name &#160;&#124; Rows &#160;&#124; Cost (%CPU)&#124; Time &#160; &#160; &#124;
-----------------------------------------------------------------------
&#124; &#160; 0 &#124; SELECT STATEMENT &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#124; &#160; &#160; &#160; &#124; &#160; &#160;29 (100)&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 1 &#124; &#160;SORT AGGREGATE &#160; &#160; &#160; &#124; &#160; &#160; &#160; &#124; &#160; &#160; 1 &#124; &#160; &#160; &#160; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 2 &#124; &#160; INDEX FAST FULL SCAN&#124; T1_PK &#124; 48000 &#124; &#160; &#160;29 &#160; (0)&#124; 00:00:01 &#124;
-----------------------------------------------------------------------
&lt;/code&gt;

In schema 1:
&lt;code&gt;
DROP INDEX T1_PK;
&lt;/code&gt;

In schema 2:
&lt;code&gt;
select /*+ full(t) no_index(t) */ count(*) from t1 t;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); 

Plan hash value: 177081169

-----------------------------------------------------------------------
&#124; Id &#160;&#124; Operation &#160; &#160; &#160; &#160; &#160; &#160; &#124; Name &#160;&#124; Rows &#160;&#124; Cost (%CPU)&#124; Time &#160; &#160; &#124;
-----------------------------------------------------------------------
&#124; &#160; 0 &#124; SELECT STATEMENT &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#124; &#160; &#160; &#160; &#124; &#160; &#160;38 (100)&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 1 &#124; &#160;SORT AGGREGATE &#160; &#160; &#160; &#124; &#160; &#160; &#160; &#124; &#160; &#160; 1 &#124; &#160; &#160; &#160; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 2 &#124; &#160; INDEX FAST FULL SCAN&#124; T1_N2 &#124; 48000 &#124; &#160; &#160;38 &#160; (0)&#124; 00:00:01 &#124;
-----------------------------------------------------------------------
&lt;/code&gt;

In schema 1:
&lt;code&gt;
DROP INDEX T1_N2;
&lt;/code&gt;

In schema 2:
&lt;code&gt;
select /*+ full(t) */ count(*) from t1 t;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); 

Plan hash value: 3724264953

-------------------------------------------------------------------
&#124; Id &#160;&#124; Operation &#160; &#160; &#160; &#160; &#160;&#124; Name &#124; Rows &#160;&#124; Cost (%CPU)&#124; Time &#160; &#160; &#124;
-------------------------------------------------------------------
&#124; &#160; 0 &#124; SELECT STATEMENT &#160; &#124; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#124; &#160;1015 (100)&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 1 &#124; &#160;SORT AGGREGATE &#160; &#160;&#124; &#160; &#160; &#160;&#124; &#160; &#160; 1 &#124; &#160; &#160; &#160; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 2 &#124; &#160; TABLE ACCESS FULL&#124; T1 &#160; &#124; 48000 &#124; &#160;1015 &#160; (1)&#124; 00:00:13 &#124;
-------------------------------------------------------------------
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>The index creation, view creation, and statistics gathering statements were lost in my previous post <em>[Now fixed: JPL]</em>.  The view contained an INDEX() hint.  Changing that hint to an INDEX_FFS() will result in an INDEX FAST FULL SCAN operation appearing in the plan.</p>
<p>Another possibility uses two schemas, with a view potentially created to implement security that also contains hints, and a public synonym.</p>
<p>In schema 1:<br />
<code><br />
CREATE TABLE T1 AS<br />
SELECT<br />
 &nbsp;ROWNUM C1,<br />
 &nbsp;ROWNUM*2 C2,<br />
 &nbsp;LPAD(' ',500,' ') C3<br />
FROM<br />
 &nbsp;DUAL<br />
CONNECT BY<br />
 &nbsp;LEVEL &lt;= 48000;</p>
<p>CREATE UNIQUE INDEX T1_PK ON T1(C1);<br />
CREATE UNIQUE INDEX T1_N2 ON T1(C1,C2);</p>
<p>ALTER TABLE T1 MODIFY (<br />
 &nbsp;C1 NOT NULL,<br />
 &nbsp;C2 NOT NULL);</p>
<p>EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=&gt;USER,TABNAME=&gt;'T1')</p>
<p>CREATE OR REPLACE VIEW T1_VIEW AS<br />
SELECT /*+ INDEX_FFS(T1_V) */<br />
 &nbsp;C1,<br />
 &nbsp;C2<br />
FROM<br />
 &nbsp;(SELECT<br />
 &nbsp; &nbsp;*<br />
 &nbsp;FROM<br />
 &nbsp; &nbsp;T1) T1_V;</p>
<p>CREATE OR REPLACE PUBLIC SYNONYM T1 FOR T1_VIEW;</p>
<p>GRANT SELECT ON T1_VIEW TO PUBLIC;<br />
GRANT SELECT ON T1 TO PUBLIC;<br />
</code></p>
<p>In schema 2:<br />
<code><br />
select /*+ full(t) */ count(*) from t1 t;</p>
<p>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); </p>
<p>Plan hash value: 1018460547</p>
<p>-----------------------------------------------------------------------<br />
| Id &nbsp;| Operation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Name &nbsp;| Rows &nbsp;| Cost (%CPU)| Time &nbsp; &nbsp; |<br />
-----------------------------------------------------------------------<br />
| &nbsp; 0 | SELECT STATEMENT &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp;29 (100)| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 1 | &nbsp;SORT AGGREGATE &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; 1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 2 | &nbsp; INDEX FAST FULL SCAN| T1_PK | 48000 | &nbsp; &nbsp;29 &nbsp; (0)| 00:00:01 |<br />
-----------------------------------------------------------------------<br />
</code></p>
<p>In schema 1:<br />
<code><br />
DROP INDEX T1_PK;<br />
</code></p>
<p>In schema 2:<br />
<code><br />
select /*+ full(t) no_index(t) */ count(*) from t1 t;</p>
<p>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); </p>
<p>Plan hash value: 177081169</p>
<p>-----------------------------------------------------------------------<br />
| Id &nbsp;| Operation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Name &nbsp;| Rows &nbsp;| Cost (%CPU)| Time &nbsp; &nbsp; |<br />
-----------------------------------------------------------------------<br />
| &nbsp; 0 | SELECT STATEMENT &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp;38 (100)| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 1 | &nbsp;SORT AGGREGATE &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; 1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 2 | &nbsp; INDEX FAST FULL SCAN| T1_N2 | 48000 | &nbsp; &nbsp;38 &nbsp; (0)| 00:00:01 |<br />
-----------------------------------------------------------------------<br />
</code></p>
<p>In schema 1:<br />
<code><br />
DROP INDEX T1_N2;<br />
</code></p>
<p>In schema 2:<br />
<code><br />
select /*+ full(t) */ count(*) from t1 t;</p>
<p>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); </p>
<p>Plan hash value: 3724264953</p>
<p>-------------------------------------------------------------------<br />
| Id &nbsp;| Operation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Name | Rows &nbsp;| Cost (%CPU)| Time &nbsp; &nbsp; |<br />
-------------------------------------------------------------------<br />
| &nbsp; 0 | SELECT STATEMENT &nbsp; | &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp;1015 (100)| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 1 | &nbsp;SORT AGGREGATE &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; 1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 2 | &nbsp; TABLE ACCESS FULL| T1 &nbsp; | 48000 | &nbsp;1015 &nbsp; (1)| 00:00:13 |<br />
-------------------------------------------------------------------<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34561</link>
		<dc:creator><![CDATA[Gary]]></dc:creator>
		<pubDate>Sat, 03 Oct 2009 00:53:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34561</guid>
		<description><![CDATA[Unless you are tricking us with the names, I&#039;ll assume t1 is a table that had a separate t1_pk primary key index, which would discount an IOT. It would be interesting if the tablespace for t1 was offline and Oracle decided to override the hint and use an index on an available tablespace rather than fail the query.]]></description>
		<content:encoded><![CDATA[<p>Unless you are tricking us with the names, I&#8217;ll assume t1 is a table that had a separate t1_pk primary key index, which would discount an IOT. It would be interesting if the tablespace for t1 was offline and Oracle decided to override the hint and use an index on an available tablespace rather than fail the query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34560</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 20:09:34 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34560</guid>
		<description><![CDATA[What if T1 is not a table, but is actually a view with embedded hints?

&lt;code&gt;
CREATE TABLE T2 AS
SELECT
 &#160;ROWNUM C1,
 &#160;ROWNUM*2 C2,
 &#160;LPAD(&#039; &#039;,500,&#039; &#039;) C3
FROM
 &#160;DUAL
CONNECT BY
 &#160;LEVEL &lt;= 48000;

CREATE UNIQUE INDEX T1_PK ON T2(C1);
CREATE UNIQUE INDEX T1_N2 ON T2(C1,C2);

ALTER TABLE T2 MODIFY (
 &#160;C1 NOT NULL,
 &#160;C2 NOT NULL);

CREATE OR REPLACE VIEW T1 AS
SELECT /*+ INDEX(T2) */
 &#160;C1,
 &#160;C2
FROM
 &#160;(SELECT
 &#160; &#160;*
 &#160;FROM
 &#160; &#160;T2) T2;

EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=&gt;USER,TABNAME=&gt;&#039;T2&#039;)

select /*+ full(t) */ count(*) from t1 t;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); 

Plan hash value: 1213398864

------------------------------------------------------------------
&#124; Id &#160;&#124; Operation &#160; &#160; &#160; &#160;&#124; Name &#160;&#124; Rows &#160;&#124; Cost (%CPU)&#124; Time &#160; &#160; &#124;
------------------------------------------------------------------
&#124; &#160; 0 &#124; SELECT STATEMENT &#124; &#160; &#160; &#160; &#124; &#160; &#160; &#160; &#124; &#160; 101 (100)&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 1 &#124; &#160;SORT AGGREGATE &#160;&#124; &#160; &#160; &#160; &#124; &#160; &#160; 1 &#124; &#160; &#160; &#160; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 2 &#124; &#160; INDEX FULL SCAN&#124; T1_PK &#124; 48000 &#124; &#160; 101 &#160; (1)&#124; 00:00:02 &#124;
------------------------------------------------------------------

DROP INDEX T1_PK;

select /*+ full(t) */ count(*) from t1 t;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); 

Plan hash value: 824454759

------------------------------------------------------------------
&#124; Id &#160;&#124; Operation &#160; &#160; &#160; &#160;&#124; Name &#160;&#124; Rows &#160;&#124; Cost (%CPU)&#124; Time &#160; &#160; &#124;
------------------------------------------------------------------
&#124; &#160; 0 &#124; SELECT STATEMENT &#124; &#160; &#160; &#160; &#124; &#160; &#160; &#160; &#124; &#160; 134 (100)&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 1 &#124; &#160;SORT AGGREGATE &#160;&#124; &#160; &#160; &#160; &#124; &#160; &#160; 1 &#124; &#160; &#160; &#160; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 2 &#124; &#160; INDEX FULL SCAN&#124; T1_N2 &#124; 48000 &#124; &#160; 134 &#160; (1)&#124; 00:00:02 &#124;
------------------------------------------------------------------

DROP INDEX T1_N2;

select /*+ full(t) */ count(*) from t1 t;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); 

Plan hash value: 3321871023

-------------------------------------------------------------------
&#124; Id &#160;&#124; Operation &#160; &#160; &#160; &#160; &#160;&#124; Name &#124; Rows &#160;&#124; Cost (%CPU)&#124; Time &#160; &#160; &#124;
-------------------------------------------------------------------
&#124; &#160; 0 &#124; SELECT STATEMENT &#160; &#124; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#124; &#160;1015 (100)&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 1 &#124; &#160;SORT AGGREGATE &#160; &#160;&#124; &#160; &#160; &#160;&#124; &#160; &#160; 1 &#124; &#160; &#160; &#160; &#160; &#160; &#160;&#124; &#160; &#160; &#160; &#160; &#160;&#124;
&#124; &#160; 2 &#124; &#160; TABLE ACCESS FULL&#124; T2 &#160; &#124; 48000 &#124; &#160;1015 &#160; (1)&#124; 00:00:13 &#124;
-------------------------------------------------------------------
&lt;/code&gt;
]]></description>
		<content:encoded><![CDATA[<p>What if T1 is not a table, but is actually a view with embedded hints?</p>
<p><code><br />
CREATE TABLE T2 AS<br />
SELECT<br />
 &nbsp;ROWNUM C1,<br />
 &nbsp;ROWNUM*2 C2,<br />
 &nbsp;LPAD(' ',500,' ') C3<br />
FROM<br />
 &nbsp;DUAL<br />
CONNECT BY<br />
 &nbsp;LEVEL &lt;= 48000;</p>
<p>CREATE UNIQUE INDEX T1_PK ON T2(C1);<br />
CREATE UNIQUE INDEX T1_N2 ON T2(C1,C2);</p>
<p>ALTER TABLE T2 MODIFY (<br />
 &nbsp;C1 NOT NULL,<br />
 &nbsp;C2 NOT NULL);</p>
<p>CREATE OR REPLACE VIEW T1 AS<br />
SELECT /*+ INDEX(T2) */<br />
 &nbsp;C1,<br />
 &nbsp;C2<br />
FROM<br />
 &nbsp;(SELECT<br />
 &nbsp; &nbsp;*<br />
 &nbsp;FROM<br />
 &nbsp; &nbsp;T2) T2;</p>
<p>EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=&gt;USER,TABNAME=&gt;'T2')</p>
<p>select /*+ full(t) */ count(*) from t1 t;</p>
<p>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); </p>
<p>Plan hash value: 1213398864</p>
<p>------------------------------------------------------------------<br />
| Id &nbsp;| Operation &nbsp; &nbsp; &nbsp; &nbsp;| Name &nbsp;| Rows &nbsp;| Cost (%CPU)| Time &nbsp; &nbsp; |<br />
------------------------------------------------------------------<br />
| &nbsp; 0 | SELECT STATEMENT | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; 101 (100)| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 1 | &nbsp;SORT AGGREGATE &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; 1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 2 | &nbsp; INDEX FULL SCAN| T1_PK | 48000 | &nbsp; 101 &nbsp; (1)| 00:00:02 |<br />
------------------------------------------------------------------</p>
<p>DROP INDEX T1_PK;</p>
<p>select /*+ full(t) */ count(*) from t1 t;</p>
<p>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); </p>
<p>Plan hash value: 824454759</p>
<p>------------------------------------------------------------------<br />
| Id &nbsp;| Operation &nbsp; &nbsp; &nbsp; &nbsp;| Name &nbsp;| Rows &nbsp;| Cost (%CPU)| Time &nbsp; &nbsp; |<br />
------------------------------------------------------------------<br />
| &nbsp; 0 | SELECT STATEMENT | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; 134 (100)| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 1 | &nbsp;SORT AGGREGATE &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; 1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 2 | &nbsp; INDEX FULL SCAN| T1_N2 | 48000 | &nbsp; 134 &nbsp; (1)| 00:00:02 |<br />
------------------------------------------------------------------</p>
<p>DROP INDEX T1_N2;</p>
<p>select /*+ full(t) */ count(*) from t1 t;</p>
<p>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL)); </p>
<p>Plan hash value: 3321871023</p>
<p>-------------------------------------------------------------------<br />
| Id &nbsp;| Operation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Name | Rows &nbsp;| Cost (%CPU)| Time &nbsp; &nbsp; |<br />
-------------------------------------------------------------------<br />
| &nbsp; 0 | SELECT STATEMENT &nbsp; | &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp;1015 (100)| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 1 | &nbsp;SORT AGGREGATE &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; 1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
| &nbsp; 2 | &nbsp; TABLE ACCESS FULL| T2 &nbsp; | 48000 | &nbsp;1015 &nbsp; (1)| 00:00:13 |<br />
-------------------------------------------------------------------<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mwidlake</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34559</link>
		<dc:creator><![CDATA[mwidlake]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 19:27:22 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34559</guid>
		<description><![CDATA[Is it due to a &quot;trick&quot; that the CBO recognises that a count(*) is an attempt to simply know how many rows are in the table, and so the statement is re-written into a scan of the smallest index that contains a value for all rows (usually a unique index on mandatory columns, such as the PK index, or a bitmap index if one exists). Count(*), count(1) etc are so commonly used that it is worth the CBO having a specific check for it and conversion to the fastest wat to satisfy the query.

But I like Coskan&#039;s answer too :-) 

Martin]]></description>
		<content:encoded><![CDATA[<p>Is it due to a &#8220;trick&#8221; that the CBO recognises that a count(*) is an attempt to simply know how many rows are in the table, and so the statement is re-written into a scan of the smallest index that contains a value for all rows (usually a unique index on mandatory columns, such as the PK index, or a bitmap index if one exists). Count(*), count(1) etc are so commonly used that it is worth the CBO having a specific check for it and conversion to the fastest wat to satisfy the query.</p>
<p>But I like Coskan&#8217;s answer too :-) </p>
<p>Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: coskan</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34558</link>
		<dc:creator><![CDATA[coskan]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 19:19:02 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34558</guid>
		<description><![CDATA[Can it be this parameter ?
[sourcecode]
SQL&gt; alter session set &quot;_optimizer_ignore_hints&quot;=TRUE;

Session altered.

SQL&gt; select /*+ full(t1)*/ count(object_id) from t1;

COUNT(OBJECT_ID)
----------------
           65665


Execution Plan
----------------------------------------------------------
Plan hash value: 4103104450

-------------------------------------------------------------------------------
&#124; Id  &#124; Operation             &#124; Name  &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
-------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT      &#124;       &#124;     1 &#124;     5 &#124;    41   (0)&#124; 00:00:01 &#124;
&#124;   1 &#124;  SORT AGGREGATE       &#124;       &#124;     1 &#124;     5 &#124;            &#124;          &#124;
&#124;   2 &#124;   INDEX FAST FULL SCAN&#124; T1_IX &#124; 65668 &#124;   320K&#124;    41   (0)&#124; 00:00:01 &#124;
-------------------------------------------------------------------------------
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Can it be this parameter ?</p>
<pre class="brush: plain; title: ; notranslate">
SQL&amp;gt; alter session set &quot;_optimizer_ignore_hints&quot;=TRUE;

Session altered.

SQL&amp;gt; select /*+ full(t1)*/ count(object_id) from t1;

COUNT(OBJECT_ID)
----------------
           65665


Execution Plan
----------------------------------------------------------
Plan hash value: 4103104450

-------------------------------------------------------------------------------
| Id  | Operation             | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |       |     1 |     5 |    41   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE       |       |     1 |     5 |            |          |
|   2 |   INDEX FAST FULL SCAN| T1_IX | 65668 |   320K|    41   (0)| 00:00:01 |
-------------------------------------------------------------------------------
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wolfgang</title>
		<link>http://jonathanlewis.wordpress.com/2009/10/02/quiz-night-3/#comment-34557</link>
		<dc:creator><![CDATA[Wolfgang]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 18:38:15 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=2304#comment-34557</guid>
		<description><![CDATA[Well perhaps t is an IOT? And as a Fast Full Scan is a kind of FTS on an index, the hint is not really ignored.]]></description>
		<content:encoded><![CDATA[<p>Well perhaps t is an IOT? And as a Fast Full Scan is a kind of FTS on an index, the hint is not really ignored.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
