<?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: Learning</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/11/06/learning/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/11/06/learning/</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/2012/11/06/learning/#comment-52088</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 13 Dec 2012 17:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9856#comment-52088</guid>
		<description><![CDATA[The obvious thing to experiment with is the &quot;join elimination&quot; feature of Oracle 11g. If a single column join to primary key is not going to eliminate data from the join, then Oracle can eliminate the table completely. This depends largely on referential integrity (i.e. primary key / foreign key) being declared between the tables.

Here&#039;s a gem - which I will have to write up as a proper blog when I get the time: if the primary key is deferrable, you can create duplicate rows in the parent table (temporarily), which should duplicate data in the join; but the optimizer doesn&#039;t notice when the constraint has been deferred and allows join elimination to take place: so you can get results that are arguably wrong when you defer a primary key. 

Here&#039;s a cut-n-paste from a session running 11.2.0.2:

[sourcecode gutter=&quot;false&quot;]

SQL&gt; set autotrace on explain
SQL&gt; select  chi.name from child chi , parent par where par.id = chi.id_p;

NAME
----------
Simon
Sally
Jack
Jill

4 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2406669797

---------------------------------------------------------------------------
&#124; Id  &#124; Operation         &#124; Name  &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
---------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT  &#124;       &#124;     4 &#124;    36 &#124;     3   (0)&#124; 00:00:01 &#124;
&#124;*  1 &#124;  TABLE ACCESS FULL&#124; CHILD &#124;     4 &#124;    36 &#124;     3   (0)&#124; 00:00:01 &#124;
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(&quot;CHI&quot;.&quot;ID_P&quot; IS NOT NULL)

SQL&gt; select  /*+ no_eliminate_join(par) */ chi.name from child chi , parent par where par.id = chi.id_p;

NAME
----------
Simon
Simon
Sally
Sally
Jack
Jill

6 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1687613841

-----------------------------------------------------------------------------
&#124; Id  &#124; Operation          &#124; Name   &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
-----------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT   &#124;        &#124;     4 &#124;    48 &#124;     3   (0)&#124; 00:00:01 &#124;
&#124;   1 &#124;  NESTED LOOPS      &#124;        &#124;     4 &#124;    48 &#124;     3   (0)&#124; 00:00:01 &#124;
&#124;   2 &#124;   TABLE ACCESS FULL&#124; CHILD  &#124;     4 &#124;    36 &#124;     3   (0)&#124; 00:00:01 &#124;
&#124;*  3 &#124;   INDEX RANGE SCAN &#124; PAR_PK &#124;     1 &#124;     3 &#124;     0   (0)&#124; 00:00:01 &#124;
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access(&quot;PAR&quot;.&quot;ID&quot;=&quot;CHI&quot;.&quot;ID_P&quot;)

SQL&gt; spool off

SQL&gt;


[/sourcecode]

When we disable join elimination the result changes.
The parent id for Sally and Simon exists twice in the parent table, and it&#039;s legal for it to exist twice because I&#039;ve made the primary key constraint on parent deferrable and deferred it.]]></description>
		<content:encoded><![CDATA[<p>The obvious thing to experiment with is the &#8220;join elimination&#8221; feature of Oracle 11g. If a single column join to primary key is not going to eliminate data from the join, then Oracle can eliminate the table completely. This depends largely on referential integrity (i.e. primary key / foreign key) being declared between the tables.</p>
<p>Here&#8217;s a gem &#8211; which I will have to write up as a proper blog when I get the time: if the primary key is deferrable, you can create duplicate rows in the parent table (temporarily), which should duplicate data in the join; but the optimizer doesn&#8217;t notice when the constraint has been deferred and allows join elimination to take place: so you can get results that are arguably wrong when you defer a primary key. </p>
<p>Here&#8217;s a cut-n-paste from a session running 11.2.0.2:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">

SQL&gt; set autotrace on explain
SQL&gt; select  chi.name from child chi , parent par where par.id = chi.id_p;

NAME
----------
Simon
Sally
Jack
Jill

4 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2406669797

---------------------------------------------------------------------------
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |       |     4 |    36 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| CHILD |     4 |    36 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------

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

   1 - filter(&quot;CHI&quot;.&quot;ID_P&quot; IS NOT NULL)

SQL&gt; select  /*+ no_eliminate_join(par) */ chi.name from child chi , parent par where par.id = chi.id_p;

NAME
----------
Simon
Simon
Sally
Sally
Jack
Jill

6 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1687613841

-----------------------------------------------------------------------------
| Id  | Operation          | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |        |     4 |    48 |     3   (0)| 00:00:01 |
|   1 |  NESTED LOOPS      |        |     4 |    48 |     3   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| CHILD  |     4 |    36 |     3   (0)| 00:00:01 |
|*  3 |   INDEX RANGE SCAN | PAR_PK |     1 |     3 |     0   (0)| 00:00:01 |
-----------------------------------------------------------------------------

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

   3 - access(&quot;PAR&quot;.&quot;ID&quot;=&quot;CHI&quot;.&quot;ID_P&quot;)

SQL&gt; spool off

SQL&gt;


</pre>
<p>When we disable join elimination the result changes.<br />
The parent id for Sally and Simon exists twice in the parent table, and it&#8217;s legal for it to exist twice because I&#8217;ve made the primary key constraint on parent deferrable and deferred it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: srivenu kadiyala</title>
		<link>http://jonathanlewis.wordpress.com/2012/11/06/learning/#comment-51431</link>
		<dc:creator><![CDATA[srivenu kadiyala]]></dc:creator>
		<pubDate>Tue, 13 Nov 2012 18:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9856#comment-51431</guid>
		<description><![CDATA[I presume one of the condition in the fifth thought would include the RELY or NORELY constraint state.]]></description>
		<content:encoded><![CDATA[<p>I presume one of the condition in the fifth thought would include the RELY or NORELY constraint state.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flavio</title>
		<link>http://jonathanlewis.wordpress.com/2012/11/06/learning/#comment-51391</link>
		<dc:creator><![CDATA[Flavio]]></dc:creator>
		<pubDate>Sun, 11 Nov 2012 14:35:34 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9856#comment-51391</guid>
		<description><![CDATA[That&#039;s why after 14 years with Oracle one still feels an advanced learner and sometimes not even that.]]></description>
		<content:encoded><![CDATA[<p>That&#8217;s why after 14 years with Oracle one still feels an advanced learner and sometimes not even that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Uwe Hesse</title>
		<link>http://jonathanlewis.wordpress.com/2012/11/06/learning/#comment-51351</link>
		<dc:creator><![CDATA[Uwe Hesse]]></dc:creator>
		<pubDate>Fri, 09 Nov 2012 07:31:12 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9856#comment-51351</guid>
		<description><![CDATA[Reminds me of numerous cases when I got a question: If it isn&#039;t really trivial or asked often before, many times I end up with creating a test case to find out. Because of the meanwhile tremendous complexity of the Oracle Database (and because things I used to know have changed over time), even apparently obvious answers may need such research. But after all, that&#039;s what keeps my job being interesting :-)]]></description>
		<content:encoded><![CDATA[<p>Reminds me of numerous cases when I got a question: If it isn&#8217;t really trivial or asked often before, many times I end up with creating a test case to find out. Because of the meanwhile tremendous complexity of the Oracle Database (and because things I used to know have changed over time), even apparently obvious answers may need such research. But after all, that&#8217;s what keeps my job being interesting :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Pyke Le Brun</title>
		<link>http://jonathanlewis.wordpress.com/2012/11/06/learning/#comment-51310</link>
		<dc:creator><![CDATA[David Pyke Le Brun]]></dc:creator>
		<pubDate>Wed, 07 Nov 2012 23:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9856#comment-51310</guid>
		<description><![CDATA[and that is EXACTLY why you manage to be so good at avoiding errors.

becuase not only have you come up with a list of interesting options.. you are now actually going to test them.

all I have to say is... &quot;Well done that man!&quot;]]></description>
		<content:encoded><![CDATA[<p>and that is EXACTLY why you manage to be so good at avoiding errors.</p>
<p>becuase not only have you come up with a list of interesting options.. you are now actually going to test them.</p>
<p>all I have to say is&#8230; &#8220;Well done that man!&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
