<?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: Cartesian Merge Join</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Thu, 23 May 2013 12:47:17 +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/2006/12/13/cartesian-merge-join/#comment-40610</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 02 Jun 2011 20:52:21 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-40610</guid>
		<description><![CDATA[CJ,

There are all sorts of little changes (and bugs) that appear in point releases; but it&#039;s possible that the calculated cardinality from line 21 (which will end up in line 18) is very much smaller than one, even thought it has to be reported as one. Then (very small * 508K) can come to one.  Simple rounding can cause some confusion.  This is only a guess, of course; you might be able to confirm it by looking at the 10053 trace.]]></description>
		<content:encoded><![CDATA[<p>CJ,</p>
<p>There are all sorts of little changes (and bugs) that appear in point releases; but it&#8217;s possible that the calculated cardinality from line 21 (which will end up in line 18) is very much smaller than one, even thought it has to be reported as one. Then (very small * 508K) can come to one.  Simple rounding can cause some confusion.  This is only a guess, of course; you might be able to confirm it by looking at the 10053 trace.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CJ</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-40596</link>
		<dc:creator><![CDATA[CJ]]></dc:creator>
		<pubDate>Thu, 02 Jun 2011 17:20:58 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-40596</guid>
		<description><![CDATA[Jonathan sir,

I extracted an execution plan from AWR, and am a bit puzzled on reading the following bit:

[sourcecode]
------------------------------------------------------------------------------------
&#124; Id  &#124; Operation                        &#124; Name       &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124;
------------------------------------------------------------------------------------
&#124;  17 &#124;             MERGE JOIN CARTESIAN &#124;            &#124;     1 &#124;    62 &#124; 10837   (2)&#124;
&#124;  18 &#124;              NESTED LOOPS        &#124;            &#124;     1 &#124;    44 &#124;   249   (1)&#124;
&#124;  19 &#124;               FAST DUAL          &#124;            &#124;     1 &#124;       &#124;     2   (0)&#124;
&#124;  20 &#124;               PARTITION RANGE ALL&#124;            &#124;     1 &#124;    44 &#124;   247   (1)&#124;
&#124;  21 &#124;                TABLE ACCESS FULL &#124; TBL_BONUSES&#124;     1 &#124;    44 &#124;   247   (1)&#124;
&#124;  22 &#124;              BUFFER SORT         &#124;            &#124;   508K&#124;  8940K&#124; 10590   (2)&#124;
&#124;  23 &#124;               TABLE ACCESS FULL  &#124; TBL_PLAYERS&#124;   508K&#124;  8940K&#124; 10588   (2)&#124;
[/sourcecode]

It&#039;s a cartesian join and so the estimated cardinality here should be 1*508K = 508K. But it is showing up as 1!!

Is this a bug or is there something else going on?

Version is 10.2.0.5 EE

Many thanks.]]></description>
		<content:encoded><![CDATA[<p>Jonathan sir,</p>
<p>I extracted an execution plan from AWR, and am a bit puzzled on reading the following bit:</p>
<pre class="brush: plain; title: ; notranslate">
------------------------------------------------------------------------------------
| Id  | Operation                        | Name       | Rows  | Bytes | Cost (%CPU)|
------------------------------------------------------------------------------------
|  17 |             MERGE JOIN CARTESIAN |            |     1 |    62 | 10837   (2)|
|  18 |              NESTED LOOPS        |            |     1 |    44 |   249   (1)|
|  19 |               FAST DUAL          |            |     1 |       |     2   (0)|
|  20 |               PARTITION RANGE ALL|            |     1 |    44 |   247   (1)|
|  21 |                TABLE ACCESS FULL | TBL_BONUSES|     1 |    44 |   247   (1)|
|  22 |              BUFFER SORT         |            |   508K|  8940K| 10590   (2)|
|  23 |               TABLE ACCESS FULL  | TBL_PLAYERS|   508K|  8940K| 10588   (2)|
</pre>
<p>It&#8217;s a cartesian join and so the estimated cardinality here should be 1*508K = 508K. But it is showing up as 1!!</p>
<p>Is this a bug or is there something else going on?</p>
<p>Version is 10.2.0.5 EE</p>
<p>Many thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: amao</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-37022</link>
		<dc:creator><![CDATA[amao]]></dc:creator>
		<pubDate>Fri, 20 Aug 2010 05:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-37022</guid>
		<description><![CDATA[I have query as below, both tables are partitioned (partition by range of data_desc, one day one partition.) 


select count(1) from
 ( select &#039;2010-08-02&#039; as data_desc,
          t2.lev,
          count(1)
     from dn_coinlog_his        t1,
          dn_character_mes1     t2
   where t2.area_id = t1.area_id
     and t2.character_id = t1.characterid
     and t2.data_desc = t1.data_desc
     and t1.data_desc = &#039;2010-08-02&#039;
   group by t2.lev);
   
However, it did NOT use transtive closure to generate execution plan with &quot;partition range single&quot;.  
I traced it with 10053 and found it passed the CBQT validity, however, Oracle did NOT rewrite it 
with t1.data_desc = &#039;2010-08-02&#039; and t2.data_desc =&#039;2010-08-02&#039;.

Below is abstract from 10053 event.

Predicate Information:

**************************
Predicate Move-Around (PM)
**************************
PM: Considering predicate move-around in SEL$1 (#0).
PM:   Checking validity of predicate move-around in SEL$1 (#0).
CBQT: Validity checks passed for afg5yjfy225db.
Query block (0x2a973e5398) before join elimination:
SQL:******* UNPARSED QUERY IS *******
SELECT &#039;2010-08-02&#039; &quot;DATA_DESC&quot;,&quot;T2&quot;.&quot;LEV&quot; &quot;LEV&quot;,COUNT(1) &quot;COUNT(1)&quot; FROM &quot;DI_USER&quot;.&quot;DN_COINLOG_HIS&quot; &quot;T1&quot;,&quot;DI_USER&quot;.&quot;DN_CHARACTER_MES1&quot; &quot;T2&quot; 
WHERE &quot;T2&quot;.&quot;AREA_ID&quot;=&quot;T1&quot;.&quot;AREA_ID&quot; 
AND &quot;T2&quot;.&quot;CHARACTER_ID&quot;=&quot;T1&quot;.&quot;CHARACTERID&quot; 
AND &quot;T2&quot;.&quot;DATA_DESC&quot;=&quot;T1&quot;.&quot;DATA_DESC&quot; 
AND &quot;T1&quot;.&quot;DATA_DESC&quot;=&#039;2010-08-02&#039; 
GROUP BY &quot;T2&quot;.&quot;LEV&quot;
Query block (0x2a973e5398) unchanged


Could you show me why Oracle rewrite it with PM, sometime it not?
By the way, I have wrote you about this issue with trace file. Sorry for disturb you again.

Thank you again for your time,
Amao]]></description>
		<content:encoded><![CDATA[<p>I have query as below, both tables are partitioned (partition by range of data_desc, one day one partition.) </p>
<p>select count(1) from<br />
 ( select &#8217;2010-08-02&#8242; as data_desc,<br />
          t2.lev,<br />
          count(1)<br />
     from dn_coinlog_his        t1,<br />
          dn_character_mes1     t2<br />
   where t2.area_id = t1.area_id<br />
     and t2.character_id = t1.characterid<br />
     and t2.data_desc = t1.data_desc<br />
     and t1.data_desc = &#8217;2010-08-02&#8242;<br />
   group by t2.lev);</p>
<p>However, it did NOT use transtive closure to generate execution plan with &#8220;partition range single&#8221;.<br />
I traced it with 10053 and found it passed the CBQT validity, however, Oracle did NOT rewrite it<br />
with t1.data_desc = &#8217;2010-08-02&#8242; and t2.data_desc =&#8217;2010-08-02&#8242;.</p>
<p>Below is abstract from 10053 event.</p>
<p>Predicate Information:</p>
<p>**************************<br />
Predicate Move-Around (PM)<br />
**************************<br />
PM: Considering predicate move-around in SEL$1 (#0).<br />
PM:   Checking validity of predicate move-around in SEL$1 (#0).<br />
CBQT: Validity checks passed for afg5yjfy225db.<br />
Query block (0x2a973e5398) before join elimination:<br />
SQL:******* UNPARSED QUERY IS *******<br />
SELECT &#8217;2010-08-02&#8242; &#8220;DATA_DESC&#8221;,&#8221;T2&#8243;.&#8221;LEV&#8221; &#8220;LEV&#8221;,COUNT(1) &#8220;COUNT(1)&#8221; FROM &#8220;DI_USER&#8221;.&#8221;DN_COINLOG_HIS&#8221; &#8220;T1&#8243;,&#8221;DI_USER&#8221;.&#8221;DN_CHARACTER_MES1&#8243; &#8220;T2&#8243;<br />
WHERE &#8220;T2&#8243;.&#8221;AREA_ID&#8221;=&#8221;T1&#8243;.&#8221;AREA_ID&#8221;<br />
AND &#8220;T2&#8243;.&#8221;CHARACTER_ID&#8221;=&#8221;T1&#8243;.&#8221;CHARACTERID&#8221;<br />
AND &#8220;T2&#8243;.&#8221;DATA_DESC&#8221;=&#8221;T1&#8243;.&#8221;DATA_DESC&#8221;<br />
AND &#8220;T1&#8243;.&#8221;DATA_DESC&#8221;=&#8217;2010-08-02&#8242;<br />
GROUP BY &#8220;T2&#8243;.&#8221;LEV&#8221;<br />
Query block (0x2a973e5398) unchanged</p>
<p>Could you show me why Oracle rewrite it with PM, sometime it not?<br />
By the way, I have wrote you about this issue with trace file. Sorry for disturb you again.</p>
<p>Thank you again for your time,<br />
Amao</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajith</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-37014</link>
		<dc:creator><![CDATA[Ajith]]></dc:creator>
		<pubDate>Thu, 19 Aug 2010 14:16:05 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-37014</guid>
		<description><![CDATA[Thank you Jonathan,

I will do that when we get CMJs in memory next time and will use &quot;+peeked_binds&quot; option with display_cursor. 

Thank you again for your time,
Ajith]]></description>
		<content:encoded><![CDATA[<p>Thank you Jonathan,</p>
<p>I will do that when we get CMJs in memory next time and will use &#8220;+peeked_binds&#8221; option with display_cursor. </p>
<p>Thank you again for your time,<br />
Ajith</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-37003</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 18 Aug 2010 21:13:12 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-37003</guid>
		<description><![CDATA[Ajith,

This seems a little unlikely because you still get bind variable peeking that results (bugs excepted) in optimization against known constants. I suppose it&#039;s possible that you could get more Cartesian Merge Joins on SIMILAR than you would on FORCED because the former allows re-optimization in various circumstances - so you get through more plans.

You may be getting CMJs because the estimated cardinality of the driving table is much less than one. It the estimate is correct then the CMJ is reasonable - if the estimate is wrong then the query will take longer than expected. When you find a CMJ in memory, use the &quot;peeked_binds&quot; option in dbms_xplan.display_cursor ( http://optimizermagic.blogspot.com/2008/02/displaying-and-reading-execution-plans.html ) to see if you can find the bind variables and reproduce the plan using constants.]]></description>
		<content:encoded><![CDATA[<p>Ajith,</p>
<p>This seems a little unlikely because you still get bind variable peeking that results (bugs excepted) in optimization against known constants. I suppose it&#8217;s possible that you could get more Cartesian Merge Joins on SIMILAR than you would on FORCED because the former allows re-optimization in various circumstances &#8211; so you get through more plans.</p>
<p>You may be getting CMJs because the estimated cardinality of the driving table is much less than one. It the estimate is correct then the CMJ is reasonable &#8211; if the estimate is wrong then the query will take longer than expected. When you find a CMJ in memory, use the &#8220;peeked_binds&#8221; option in dbms_xplan.display_cursor ( <a href="http://optimizermagic.blogspot.com/2008/02/displaying-and-reading-execution-plans.html" rel="nofollow">http://optimizermagic.blogspot.com/2008/02/displaying-and-reading-execution-plans.html</a> ) to see if you can find the bind variables and reproduce the plan using constants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajith</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-36994</link>
		<dc:creator><![CDATA[Ajith]]></dc:creator>
		<pubDate>Tue, 17 Aug 2010 12:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-36994</guid>
		<description><![CDATA[Jonathan,

If the cursor_sharing parameter is set to SIMILAR at the instance level, do you think that it can cause Cartesian merge join for many queries? I see a lot of Cartesian joins in one such database(11G - 11.1.0.7.0). I am investigating on the root cause. If it is not the reason, what else can lead to Cartesian joins? Most of the time, the query executes fast (using nested loop join), but at times it takes a long time to execute (using Cartesian merge join).

Thanks,
Ajith]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>If the cursor_sharing parameter is set to SIMILAR at the instance level, do you think that it can cause Cartesian merge join for many queries? I see a lot of Cartesian joins in one such database(11G &#8211; 11.1.0.7.0). I am investigating on the root cause. If it is not the reason, what else can lead to Cartesian joins? Most of the time, the query executes fast (using nested loop join), but at times it takes a long time to execute (using Cartesian merge join).</p>
<p>Thanks,<br />
Ajith</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-36935</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Mon, 09 Aug 2010 12:33:10 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-36935</guid>
		<description><![CDATA[Brian,

You might consider using the opt_param() hint to set _optimizer_mjc_enabled to false for the duration of the query - but it&#039;s probably an unsupported method (unless you get approval through an SR to Oracle).

The cardinality of 1 MIGHT be a side effect of the &quot;in subquery&quot; applying a selectivity of 5% to the target of the &quot;IN&quot; so a cardinality hint that scales up the single table cardinality of the target table by a factor of 20 (or more) might help - but it&#039;s hard to say without a detailed investigation of the query, and the cardinality hint is a little subtle in anything other than very trivial cases.

Is it possible that you&#039;re seeing a bug which I thought I&#039;d described somewhere on the blog but can&#039;t find at present ... there are cases in 10g where the cardinality of a query with subquery is ALWAYS 1 thanks to an error in a bug-fix relating to when the normal 5% selectivity is applied. If this bug appears as the last step of a query then it doesn&#039;t really matter, but if it appears as the last step of a non-mergeable inline view then it can have a huge impact.  A workaround that may apply is to put a push_subq hint into the subquery in the inline view.]]></description>
		<content:encoded><![CDATA[<p>Brian,</p>
<p>You might consider using the opt_param() hint to set _optimizer_mjc_enabled to false for the duration of the query &#8211; but it&#8217;s probably an unsupported method (unless you get approval through an SR to Oracle).</p>
<p>The cardinality of 1 MIGHT be a side effect of the &#8220;in subquery&#8221; applying a selectivity of 5% to the target of the &#8220;IN&#8221; so a cardinality hint that scales up the single table cardinality of the target table by a factor of 20 (or more) might help &#8211; but it&#8217;s hard to say without a detailed investigation of the query, and the cardinality hint is a little subtle in anything other than very trivial cases.</p>
<p>Is it possible that you&#8217;re seeing a bug which I thought I&#8217;d described somewhere on the blog but can&#8217;t find at present &#8230; there are cases in 10g where the cardinality of a query with subquery is ALWAYS 1 thanks to an error in a bug-fix relating to when the normal 5% selectivity is applied. If this bug appears as the last step of a query then it doesn&#8217;t really matter, but if it appears as the last step of a non-mergeable inline view then it can have a huge impact.  A workaround that may apply is to put a push_subq hint into the subquery in the inline view.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-36915</link>
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Wed, 04 Aug 2010 17:13:28 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-36915</guid>
		<description><![CDATA[I am encountering the CARTESIAN MERGE JOIN on 10.2.0.4 with a query that references an inline view in it&#039;s WHERE clause as.  This inline view queries an actual view itself.

select ...
where col1 in ()

The inline view can range from 1 to 50 results and the performance is terrible with a few dozen results in the inline view.  The optimizer is estimating only 1 row from the inline view.

Setting the parameter, _optimizer_mjc_enabled to false forces a NESTED LOOP instead of the CMJ.  

I tried with setting the CARDINALITY and DYNAMIC_SAMPLING hint, but neither one of these prevented the CMJ and still showed an estimation of 1.

Would there be anything else possible to preclude the CMJ from occurring other than setting the hidden parameter?]]></description>
		<content:encoded><![CDATA[<p>I am encountering the CARTESIAN MERGE JOIN on 10.2.0.4 with a query that references an inline view in it&#8217;s WHERE clause as.  This inline view queries an actual view itself.</p>
<p>select &#8230;<br />
where col1 in ()</p>
<p>The inline view can range from 1 to 50 results and the performance is terrible with a few dozen results in the inline view.  The optimizer is estimating only 1 row from the inline view.</p>
<p>Setting the parameter, _optimizer_mjc_enabled to false forces a NESTED LOOP instead of the CMJ.  </p>
<p>I tried with setting the CARDINALITY and DYNAMIC_SAMPLING hint, but neither one of these prevented the CMJ and still showed an estimation of 1.</p>
<p>Would there be anything else possible to preclude the CMJ from occurring other than setting the hidden parameter?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-35511</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Mon, 15 Feb 2010 19:59:37 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-35511</guid>
		<description><![CDATA[Taral,

Read note 30 - where I point out that we don&#039;t scan the whole hash data set for each row in the parent set.

Think of a hash table as a large set of buckets (and I mean water carrying buckets) arranged in a large square pattern - say 64 buckets in an 8 by 8 square.

To use the hash table you have some piece of arithmetic which says:  if I want the number 1,436 it will be in the bucket in row 3 column 8; if I want the number 9,132 it will be in the bucket in row 8 column 2.  (That&#039;s all that a &quot;hash function&quot; does.)

So if you have a number I know where to look for a match.  And Oracle tries to use a lot of buckets in a very big square - so there aren&#039;t many &quot;wrong&quot; rows in a bucket when you look in it.]]></description>
		<content:encoded><![CDATA[<p>Taral,</p>
<p>Read note 30 &#8211; where I point out that we don&#8217;t scan the whole hash data set for each row in the parent set.</p>
<p>Think of a hash table as a large set of buckets (and I mean water carrying buckets) arranged in a large square pattern &#8211; say 64 buckets in an 8 by 8 square.</p>
<p>To use the hash table you have some piece of arithmetic which says:  if I want the number 1,436 it will be in the bucket in row 3 column 8; if I want the number 9,132 it will be in the bucket in row 8 column 2.  (That&#8217;s all that a &#8220;hash function&#8221; does.)</p>
<p>So if you have a number I know where to look for a match.  And Oracle tries to use a lot of buckets in a very big square &#8211; so there aren&#8217;t many &#8220;wrong&#8221; rows in a bucket when you look in it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Taral Desai</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-35509</link>
		<dc:creator><![CDATA[Taral Desai]]></dc:creator>
		<pubDate>Mon, 15 Feb 2010 18:11:08 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/#comment-35509</guid>
		<description><![CDATA[Hi Jonathan,

As from your last comment regarding probing for hash table. Can you please explain more about what do you mean by cell. As, general understanding is each row for parent table scans whole hash data which is there in memory or temp tablespace for child table. Please correct me if i am wrong on above sentence. Also, can you please give some more information.]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>As from your last comment regarding probing for hash table. Can you please explain more about what do you mean by cell. As, general understanding is each row for parent table scans whole hash data which is there in memory or temp tablespace for child table. Please correct me if i am wrong on above sentence. Also, can you please give some more information.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
