<?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: Join Ordering &#8211; pt1</title>
	<atom:link href="http://jonathanlewis.wordpress.com/join-ordering-pt1/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sun, 19 May 2013 12:40:29 +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/join-ordering-pt1/#comment-34998</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 16 Dec 2009 10:30:48 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/join-ordering-pt1/#comment-34998</guid>
		<description><![CDATA[The two queries seem to be identical - is this intentional, did you simply change some parameters between the two runs ?

A couple of things first: 
&lt;ul&gt;
(a) there are articles on this blog pointing out that if you want to give someone an execution plan it should use &lt;a href=&quot;http://jonathanlewis.wordpress.com/2006/12/22/dbms_xplan-again/&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;dbms_xplan&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;, and you have to supply the predicate section 
(b) you haven&#039;t helped me to help you by formatting your code to make it easy to read - see the &quot;How to Comment&quot; link near the top right hand side (so I had to edit it)
(c) this isn&#039;t the autotrace output from 10.2.0.4 - are you using a 9i client ?
(d) this isn&#039;t AskTom - I don&#039;t do troubleshooting for people
(e) part of your answer may be related to an example I give in my chapter of &lt;a href=&quot;http://www.apress.com/book/view/1430226684&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;&quot;Expert Oracle Practices&quot;&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; (due out January)
&lt;/ul&gt;

Question 1: In theory, cost is time; but the optimizer is not perfect and there are many reasons why the optimizer&#039;s calculated cost and the final run time of the query don&#039;t seem to be related.  Your first execution plan operates as a filter subquery, and it&#039;s &lt;a href=&quot;http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;impossible to predict&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; how many times the subquery will operate - but for the purposes of costing, Oracle assumes it will be once per row returned from the driving rowsource (hence the very high cost in your case). The cardinality of one may be variation of a bug I&#039;ve found in 10gR2 relating to aggregate subqueries that result in a cardinality of one after filtering.

Question 2: See end of question 1.]]></description>
		<content:encoded><![CDATA[<p>The two queries seem to be identical &#8211; is this intentional, did you simply change some parameters between the two runs ?</p>
<p>A couple of things first: </p>
<ul>
(a) there are articles on this blog pointing out that if you want to give someone an execution plan it should use <a href="http://jonathanlewis.wordpress.com/2006/12/22/dbms_xplan-again/" rel="nofollow"><em><strong>dbms_xplan</strong></em></a>, and you have to supply the predicate section<br />
(b) you haven&#8217;t helped me to help you by formatting your code to make it easy to read &#8211; see the &#8220;How to Comment&#8221; link near the top right hand side (so I had to edit it)<br />
(c) this isn&#8217;t the autotrace output from 10.2.0.4 &#8211; are you using a 9i client ?<br />
(d) this isn&#8217;t AskTom &#8211; I don&#8217;t do troubleshooting for people<br />
(e) part of your answer may be related to an example I give in my chapter of <a href="http://www.apress.com/book/view/1430226684" rel="nofollow"><em><strong>&#8220;Expert Oracle Practices&#8221;</strong></em></a> (due out January)
</ul>
<p>Question 1: In theory, cost is time; but the optimizer is not perfect and there are many reasons why the optimizer&#8217;s calculated cost and the final run time of the query don&#8217;t seem to be related.  Your first execution plan operates as a filter subquery, and it&#8217;s <a href="http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/" rel="nofollow"><em><strong>impossible to predict</strong></em></a> how many times the subquery will operate &#8211; but for the purposes of costing, Oracle assumes it will be once per row returned from the driving rowsource (hence the very high cost in your case). The cardinality of one may be variation of a bug I&#8217;ve found in 10gR2 relating to aggregate subqueries that result in a cardinality of one after filtering.</p>
<p>Question 2: See end of question 1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://jonathanlewis.wordpress.com/join-ordering-pt1/#comment-34978</link>
		<dc:creator><![CDATA[Joe]]></dc:creator>
		<pubDate>Mon, 14 Dec 2009 13:37:28 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/join-ordering-pt1/#comment-34978</guid>
		<description><![CDATA[Hi Jonathan,

Can you please help me to understand the following :
Oracle Version :10.2.0.4.0   
   
When I trying running the query1 it takes ages to finish compared to query 2 which takes seconds.

Question 1 :The COST of query2 is almost 350 times more. What is the reason behind this ?
Question 2: The query returns 90 rows. But why the cardinality is different in the plans of  the queries ? Isn&#039;t cardinality should be the same as the number of rows returned ?
 
I have used autotrace to generate the plan and the gem.ref_quotation table is analyzed.

Thanks,
[sourcecode]
QUERY 1:

select QUOTATION_INSTR_ID, quotation_perm_id from
gem.ref_quotation where QUOTATION_INSTR_ID in
(select QUOTATION_INSTR_ID
 from  gem.ref_quotation
where  QUOTATION_END_DATE is null
and QUOTATION_IS_PRIMARY = 1
group by QUOTATION_INSTR_ID
having count(*) &gt; 1)
order by QUOTATION_INSTR_ID;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=355664 Card=1 Bytes=17)
   1    0   SORT (ORDER BY) (Cost=355664 Card=1 Bytes=17)
   2    1     FILTER
   3    2       TABLE ACCESS (FULL) OF &#039;REF_QUOTATION&#039; (TABLE) (Cost=385 Card=58769 Bytes=999073)
   4    2       FILTER
   5    4         SORT (GROUP BY NOSORT) (Cost=7 Card=1 Bytes=10)
   6    5           TABLE ACCESS (BY INDEX ROWID) OF &#039;REF_QUOTATION&#039; (TABLE) (Cost=7 Card=1 Bytes=10)
   7    6             INDEX (RANGE SCAN) OF &#039;QUOTATION_INSTR_ID&#039; (INDEX) (Cost=3 Card=3)

Query 2:
select QUOTATION_INSTR_ID, quotation_perm_id from
gem.ref_quotation where QUOTATION_INSTR_ID in
(select QUOTATION_INSTR_ID
 from  gem.ref_quotation
where  QUOTATION_END_DATE is null
and QUOTATION_IS_PRIMARY = 1
group by QUOTATION_INSTR_ID
having count(*) &gt; 1)
order by QUOTATION_INSTR_ID;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=1019 Card=379 Bytes=8338)
   1    0   SORT (ORDER BY) (Cost=1019 Card=379 Bytes=8338)
   2    1     TABLE ACCESS (BY INDEX ROWID) OF &#039;REF_QUOTATION&#039; (TABLE) (Cost=6 Card=3 Bytes=45)
   3    2       NESTED LOOPS (Cost=1018 Card=379 Bytes=8338)
   4    3         VIEW OF &#039;VW_NSO_1&#039; (VIEW) (Cost=402 Card=2433 Bytes=17031)
   5    4           FILTER
   6    5             HASH (GROUP BY) (Cost=402 Card=122 Bytes=24330)
   7    6               TABLE ACCESS (FULL) OF &#039;REF_QUOTATION&#039; (TABLE)(Cost=387 Card=58769 Bytes=587690)
   8    3         INDEX (RANGE SCAN) OF &#039;QUOTATION_INSTR_ID&#039; (INDEX) (Cost=2 Card=3)
[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>Can you please help me to understand the following :<br />
Oracle Version :10.2.0.4.0   </p>
<p>When I trying running the query1 it takes ages to finish compared to query 2 which takes seconds.</p>
<p>Question 1 :The COST of query2 is almost 350 times more. What is the reason behind this ?<br />
Question 2: The query returns 90 rows. But why the cardinality is different in the plans of  the queries ? Isn&#8217;t cardinality should be the same as the number of rows returned ?</p>
<p>I have used autotrace to generate the plan and the gem.ref_quotation table is analyzed.</p>
<p>Thanks,</p>
<pre class="brush: plain; title: ; notranslate">
QUERY 1:

select QUOTATION_INSTR_ID, quotation_perm_id from
gem.ref_quotation where QUOTATION_INSTR_ID in
(select QUOTATION_INSTR_ID
 from  gem.ref_quotation
where  QUOTATION_END_DATE is null
and QUOTATION_IS_PRIMARY = 1
group by QUOTATION_INSTR_ID
having count(*) &gt; 1)
order by QUOTATION_INSTR_ID;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=355664 Card=1 Bytes=17)
   1    0   SORT (ORDER BY) (Cost=355664 Card=1 Bytes=17)
   2    1     FILTER
   3    2       TABLE ACCESS (FULL) OF 'REF_QUOTATION' (TABLE) (Cost=385 Card=58769 Bytes=999073)
   4    2       FILTER
   5    4         SORT (GROUP BY NOSORT) (Cost=7 Card=1 Bytes=10)
   6    5           TABLE ACCESS (BY INDEX ROWID) OF 'REF_QUOTATION' (TABLE) (Cost=7 Card=1 Bytes=10)
   7    6             INDEX (RANGE SCAN) OF 'QUOTATION_INSTR_ID' (INDEX) (Cost=3 Card=3)

Query 2:
select QUOTATION_INSTR_ID, quotation_perm_id from
gem.ref_quotation where QUOTATION_INSTR_ID in
(select QUOTATION_INSTR_ID
 from  gem.ref_quotation
where  QUOTATION_END_DATE is null
and QUOTATION_IS_PRIMARY = 1
group by QUOTATION_INSTR_ID
having count(*) &gt; 1)
order by QUOTATION_INSTR_ID;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=1019 Card=379 Bytes=8338)
   1    0   SORT (ORDER BY) (Cost=1019 Card=379 Bytes=8338)
   2    1     TABLE ACCESS (BY INDEX ROWID) OF 'REF_QUOTATION' (TABLE) (Cost=6 Card=3 Bytes=45)
   3    2       NESTED LOOPS (Cost=1018 Card=379 Bytes=8338)
   4    3         VIEW OF 'VW_NSO_1' (VIEW) (Cost=402 Card=2433 Bytes=17031)
   5    4           FILTER
   6    5             HASH (GROUP BY) (Cost=402 Card=122 Bytes=24330)
   7    6               TABLE ACCESS (FULL) OF 'REF_QUOTATION' (TABLE)(Cost=387 Card=58769 Bytes=587690)
   8    3         INDEX (RANGE SCAN) OF 'QUOTATION_INSTR_ID' (INDEX) (Cost=2 Card=3)
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
