<?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: Subquery Factoring</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Mon, 20 May 2013 17:10:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Log Buffer #259, A Carnival of the Vanities for DBAs</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-53912</link>
		<dc:creator><![CDATA[Log Buffer #259, A Carnival of the Vanities for DBAs]]></dc:creator>
		<pubDate>Mon, 04 Mar 2013 15:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-53912</guid>
		<description><![CDATA[[...] Jonathan Lewis shares an interesting little conundrum about subquery factoring that hasn’t changed in the recent (11.2.0.3) patch for subquery factoring. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Jonathan Lewis shares an interesting little conundrum about subquery factoring that hasn’t changed in the recent (11.2.0.3) patch for subquery factoring. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45445</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Mon, 12 Mar 2012 13:21:16 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45445</guid>
		<description><![CDATA[A reader,
Not on a couple of versions I tested. I still see one query doing the sort order by (although parallel) and the other not, viz:

[sourcecode]
---------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation                    &#124; Name     &#124; Rows  &#124; Bytes &#124; Cost  &#124;    TQ  &#124;IN-OUT&#124; PQ Distri
---------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT             &#124;          &#124;     3 &#124;     9 &#124;     6 &#124;        &#124;      &#124;
&#124;   1 &#124;  PX COORDINATOR              &#124;          &#124;       &#124;       &#124;       &#124;        &#124;      &#124;
&#124;   2 &#124;   PX SEND QC (RANDOM)        &#124; :TQ10002 &#124;     3 &#124;     9 &#124;     6 &#124;  Q1,02 &#124; P-&gt;S &#124; QC (RAND)
&#124;   3 &#124;    HASH GROUP BY             &#124;          &#124;     3 &#124;     9 &#124;     6 &#124;  Q1,02 &#124; PCWP &#124;
&#124;   4 &#124;     PX RECEIVE               &#124;          &#124;     3 &#124;     9 &#124;     6 &#124;  Q1,02 &#124; PCWP &#124;
&#124;   5 &#124;      PX SEND HASH            &#124; :TQ10001 &#124;     3 &#124;     9 &#124;     6 &#124;  Q1,01 &#124; P-&gt;P &#124; HASH
&#124;   6 &#124;       HASH GROUP BY          &#124;          &#124;     3 &#124;     9 &#124;     6 &#124;  Q1,01 &#124; PCWP &#124;
&#124;   7 &#124;        VIEW                  &#124;          &#124;    14 &#124;    42 &#124;     6 &#124;  Q1,01 &#124; PCWP &#124;
&#124;   8 &#124;         SORT ORDER BY        &#124;          &#124;    14 &#124;    42 &#124;     6 &#124;  Q1,01 &#124; PCWP &#124;
&#124;   9 &#124;          PX RECEIVE          &#124;          &#124;    14 &#124;    42 &#124;     2 &#124;  Q1,01 &#124; PCWP &#124;
&#124;  10 &#124;           PX SEND RANGE      &#124; :TQ10000 &#124;    14 &#124;    42 &#124;     2 &#124;  Q1,00 &#124; P-&gt;P &#124; RANGE
&#124;  11 &#124;            PX BLOCK ITERATOR &#124;          &#124;    14 &#124;    42 &#124;     2 &#124;  Q1,00 &#124; PCWC &#124;
&#124;  12 &#124;             TABLE ACCESS FULL&#124; EMP      &#124;    14 &#124;    42 &#124;     2 &#124;  Q1,00 &#124; PCWP &#124;
---------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation                &#124; Name     &#124; Rows  &#124; Bytes &#124; Cost  &#124;    TQ  &#124;IN-OUT&#124; PQ Distrib &#124;
--------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT         &#124;          &#124;     3 &#124;     9 &#124;    27 &#124;        &#124;      &#124;            &#124;
&#124;   1 &#124;  PX COORDINATOR          &#124;          &#124;       &#124;       &#124;       &#124;        &#124;      &#124;            &#124;
&#124;   2 &#124;   PX SEND QC (RANDOM)    &#124; :TQ10001 &#124;     3 &#124;     9 &#124;    27 &#124;  Q1,01 &#124; P-&gt;S &#124; QC (RAND)  &#124;
&#124;   3 &#124;    HASH GROUP BY         &#124;          &#124;     3 &#124;     9 &#124;    27 &#124;  Q1,01 &#124; PCWP &#124;            &#124;
&#124;   4 &#124;     PX RECEIVE           &#124;          &#124;     3 &#124;     9 &#124;    27 &#124;  Q1,01 &#124; PCWP &#124;            &#124;
&#124;   5 &#124;      PX SEND HASH        &#124; :TQ10000 &#124;     3 &#124;     9 &#124;    27 &#124;  Q1,00 &#124; P-&gt;P &#124; HASH       &#124;
&#124;   6 &#124;       HASH GROUP BY      &#124;          &#124;     3 &#124;     9 &#124;    27 &#124;  Q1,00 &#124; PCWP &#124;            &#124;
&#124;   7 &#124;        PX BLOCK ITERATOR &#124;          &#124;    14 &#124;    42 &#124;     2 &#124;  Q1,00 &#124; PCWC &#124;            &#124;
&#124;   8 &#124;         TABLE ACCESS FULL&#124; EMP      &#124;    14 &#124;    42 &#124;     2 &#124;  Q1,00 &#124; PCWP &#124;            &#124;
--------------------------------------------------------------------------------------------------

[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>A reader,<br />
Not on a couple of versions I tested. I still see one query doing the sort order by (although parallel) and the other not, viz:</p>
<pre class="brush: plain; title: ; notranslate">
---------------------------------------------------------------------------------------------------
| Id  | Operation                    | Name     | Rows  | Bytes | Cost  |    TQ  |IN-OUT| PQ Distri
---------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |          |     3 |     9 |     6 |        |      |
|   1 |  PX COORDINATOR              |          |       |       |       |        |      |
|   2 |   PX SEND QC (RANDOM)        | :TQ10002 |     3 |     9 |     6 |  Q1,02 | P-&gt;S | QC (RAND)
|   3 |    HASH GROUP BY             |          |     3 |     9 |     6 |  Q1,02 | PCWP |
|   4 |     PX RECEIVE               |          |     3 |     9 |     6 |  Q1,02 | PCWP |
|   5 |      PX SEND HASH            | :TQ10001 |     3 |     9 |     6 |  Q1,01 | P-&gt;P | HASH
|   6 |       HASH GROUP BY          |          |     3 |     9 |     6 |  Q1,01 | PCWP |
|   7 |        VIEW                  |          |    14 |    42 |     6 |  Q1,01 | PCWP |
|   8 |         SORT ORDER BY        |          |    14 |    42 |     6 |  Q1,01 | PCWP |
|   9 |          PX RECEIVE          |          |    14 |    42 |     2 |  Q1,01 | PCWP |
|  10 |           PX SEND RANGE      | :TQ10000 |    14 |    42 |     2 |  Q1,00 | P-&gt;P | RANGE
|  11 |            PX BLOCK ITERATOR |          |    14 |    42 |     2 |  Q1,00 | PCWC |
|  12 |             TABLE ACCESS FULL| EMP      |    14 |    42 |     2 |  Q1,00 | PCWP |
---------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------
| Id  | Operation                | Name     | Rows  | Bytes | Cost  |    TQ  |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |          |     3 |     9 |    27 |        |      |            |
|   1 |  PX COORDINATOR          |          |       |       |       |        |      |            |
|   2 |   PX SEND QC (RANDOM)    | :TQ10001 |     3 |     9 |    27 |  Q1,01 | P-&gt;S | QC (RAND)  |
|   3 |    HASH GROUP BY         |          |     3 |     9 |    27 |  Q1,01 | PCWP |            |
|   4 |     PX RECEIVE           |          |     3 |     9 |    27 |  Q1,01 | PCWP |            |
|   5 |      PX SEND HASH        | :TQ10000 |     3 |     9 |    27 |  Q1,00 | P-&gt;P | HASH       |
|   6 |       HASH GROUP BY      |          |     3 |     9 |    27 |  Q1,00 | PCWP |            |
|   7 |        PX BLOCK ITERATOR |          |    14 |    42 |     2 |  Q1,00 | PCWC |            |
|   8 |         TABLE ACCESS FULL| EMP      |    14 |    42 |     2 |  Q1,00 | PCWP |            |
--------------------------------------------------------------------------------------------------

</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: A reader</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45053</link>
		<dc:creator><![CDATA[A reader]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 14:16:26 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45053</guid>
		<description><![CDATA[The first query behaves just like the second one if you do:

alter table emp parallel 4;]]></description>
		<content:encoded><![CDATA[<p>The first query behaves just like the second one if you do:</p>
<p>alter table emp parallel 4;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45042</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 02:24:52 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45042</guid>
		<description><![CDATA[David,

You&#039;re absolutely right. The application code is wrong if it&#039;s expecting an ordered result without supplying an &quot;order by&quot; clause - and that&#039;s true under any circumstances.  It just happens that sometimes we put in an &quot;order by&quot; clause and the execution plan doesn&#039;t end with a &quot;sort order by&quot; operation because the optimizer has determined that previous operations will guarantee that the data will be appearing in the right order as a guaranteed side effect of the earlier operatins.

The only point I was making with the note was that there are still cases even with the latest patching where the code with the inline view doesn&#039;t produce the same execution plan as the code with a CTE that has been inlined.]]></description>
		<content:encoded><![CDATA[<p>David,</p>
<p>You&#8217;re absolutely right. The application code is wrong if it&#8217;s expecting an ordered result without supplying an &#8220;order by&#8221; clause &#8211; and that&#8217;s true under any circumstances.  It just happens that sometimes we put in an &#8220;order by&#8221; clause and the execution plan doesn&#8217;t end with a &#8220;sort order by&#8221; operation because the optimizer has determined that previous operations will guarantee that the data will be appearing in the right order as a guaranteed side effect of the earlier operatins.</p>
<p>The only point I was making with the note was that there are still cases even with the latest patching where the code with the inline view doesn&#8217;t produce the same execution plan as the code with a CTE that has been inlined.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Pyke Le Brun</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45039</link>
		<dc:creator><![CDATA[David Pyke Le Brun]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 02:07:20 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45039</guid>
		<description><![CDATA[What i meant was, without the order by on the outside of the query, I would never expect to have deterministic row ordering.

in any case... Is the same true if you use a full view with an order by clause.. ?

ie
[sourcecode language=&quot;sql&quot; gutter=&quot;false&quot;]
create or replace view e
as
  select
        /*+ gather_plan_statistics */
        deptno
  from    emp
  order by deptno
;

select   deptno, count(*)
from  e
group by deptno
;

[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>What i meant was, without the order by on the outside of the query, I would never expect to have deterministic row ordering.</p>
<p>in any case&#8230; Is the same true if you use a full view with an order by clause.. ?</p>
<p>ie</p>
<pre class="brush: sql; gutter: false; title: ; notranslate">
create or replace view e
as
  select
        /*+ gather_plan_statistics */
        deptno
  from    emp
  order by deptno
;

select   deptno, count(*)
from  e
group by deptno
;

</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45035</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 00:19:36 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45035</guid>
		<description><![CDATA[David,
&lt;blockquote&gt;
&quot;what is the advantage of putting the order by in the “inner” query?&quot;


Don&#039;t ask me, I didn&#039;t write the application: &lt;i&gt;&quot;... this third party application is ... &quot;&lt;/i&gt;. The sample above is just demonstrating the issue, perhaps if we saw an example of the real application code we might some rationale for doing things this way.]]></description>
		<content:encoded><![CDATA[<p>David,</p>
<blockquote><p>
&#8220;what is the advantage of putting the order by in the “inner” query?&#8221;</p>
<p>Don&#8217;t ask me, I didn&#8217;t write the application: <i>&#8220;&#8230; this third party application is &#8230; &#8220;</i>. The sample above is just demonstrating the issue, perhaps if we saw an example of the real application code we might some rationale for doing things this way.</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barfo Rama</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45034</link>
		<dc:creator><![CDATA[Barfo Rama]]></dc:creator>
		<pubDate>Tue, 14 Feb 2012 23:12:07 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45034</guid>
		<description><![CDATA[I think the &quot;advantage&quot; is demonstrating &lt;b&gt;select  deptno  from emp order by deptno&lt;/b&gt; has different results in different queries.]]></description>
		<content:encoded><![CDATA[<p>I think the &#8220;advantage&#8221; is demonstrating <b>select  deptno  from emp order by deptno</b> has different results in different queries.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Pyke Le Brun</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/14/subquery-factoring-5/#comment-45032</link>
		<dc:creator><![CDATA[David Pyke Le Brun]]></dc:creator>
		<pubDate>Tue, 14 Feb 2012 22:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8317#comment-45032</guid>
		<description><![CDATA[what is the advantage of putting the order by in the &quot;inner&quot; query?

i would always have written this query as

[sourcecode]
select   deptno, count(*)
from (
    select
        /*+ gather_plan_statistics */
        deptno
    from    emp
) e
group by deptno
order by deptno
;

[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<p>what is the advantage of putting the order by in the &#8220;inner&#8221; query?</p>
<p>i would always have written this query as</p>
<pre class="brush: plain; title: ; notranslate">
select   deptno, count(*)
from (
    select
        /*+ gather_plan_statistics */
        deptno
    from    emp
) e
group by deptno
order by deptno
;

</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
