<?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: Explain VIEW</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2009/06/25/explain-view/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 19 Jun 2013 18:51: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/2009/06/25/explain-view/#comment-33775</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 03 Jul 2009 15:53:37 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33775</guid>
		<description><![CDATA[Todor,

I think that&#039;s an important point to consider. I always prefer to make &quot;dirty tricks&quot; explicit if possible, and certainly document why they&#039;re there.

That&#039;s partly why I prefer the no_merge hint to adding a rownum - but even there I&#039;ve been caught out by an optimisation in 10gR2 which &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;took out an &quot;order by&quot; clause&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; on an inline view with a no_merge because (as you point out) it wasn&#039;t goint to make any difference to the final result set.]]></description>
		<content:encoded><![CDATA[<p>Todor,</p>
<p>I think that&#8217;s an important point to consider. I always prefer to make &#8220;dirty tricks&#8221; explicit if possible, and certainly document why they&#8217;re there.</p>
<p>That&#8217;s partly why I prefer the no_merge hint to adding a rownum &#8211; but even there I&#8217;ve been caught out by an optimisation in 10gR2 which <a href="http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/" rel="nofollow"><em><strong>took out an &#8220;order by&#8221; clause</strong></em></a> on an inline view with a no_merge because (as you point out) it wasn&#8217;t goint to make any difference to the final result set.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todor Botev</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33772</link>
		<dc:creator><![CDATA[Todor Botev]]></dc:creator>
		<pubDate>Fri, 03 Jul 2009 14:16:56 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33772</guid>
		<description><![CDATA[I think just selecting the rownum without doing anything with it could be dangerous. At some point in the future the Optimizer could start recognizing the trick. It could find out that rownum doesn&#039;t affect the result at all - and abandon it - and the view suddenly would get merged.]]></description>
		<content:encoded><![CDATA[<p>I think just selecting the rownum without doing anything with it could be dangerous. At some point in the future the Optimizer could start recognizing the trick. It could find out that rownum doesn&#8217;t affect the result at all &#8211; and abandon it &#8211; and the view suddenly would get merged.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timur Akhmadeev</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33690</link>
		<dc:creator><![CDATA[Timur Akhmadeev]]></dc:creator>
		<pubDate>Sat, 27 Jun 2009 10:50:55 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33690</guid>
		<description><![CDATA[That sounds reasonable, thank you.]]></description>
		<content:encoded><![CDATA[<p>That sounds reasonable, thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanel Poder</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33688</link>
		<dc:creator><![CDATA[Tanel Poder]]></dc:creator>
		<pubDate>Sat, 27 Jun 2009 07:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33688</guid>
		<description><![CDATA[Yep, selecting rownum in a query block prevents optimizer from merging that query block with parent but rows are still returned there in incremental, cascading fashion - so Oracle does not have to fully materialize that query block (otherwise it would need some sort of workarea memory for storing intermediate results).]]></description>
		<content:encoded><![CDATA[<p>Yep, selecting rownum in a query block prevents optimizer from merging that query block with parent but rows are still returned there in incremental, cascading fashion &#8211; so Oracle does not have to fully materialize that query block (otherwise it would need some sort of workarea memory for storing intermediate results).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blogroll Report 19/06/2009 &#8211; 26/06/2006 &#171; Coskan&#8217;s Approach to Oracle</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33682</link>
		<dc:creator><![CDATA[Blogroll Report 19/06/2009 &#8211; 26/06/2006 &#171; Coskan&#8217;s Approach to Oracle]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 20:09:48 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33682</guid>
		<description><![CDATA[[...] Jonathan Lewis &#8211; Explain View  [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Jonathan Lewis &#8211; Explain View  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33678</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 19:06:26 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33678</guid>
		<description><![CDATA[Timur,

Another way to think about it is to go back to the concepts of the &lt;a href=&quot;http://jonathanlewis.wordpress.com/2007/01/24/left-deep-trees/&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;&quot;left deep&quot;&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; and &quot;bushy tree&quot; optimisation plans.

The &quot;unit of optimisation&quot; - the thing where Oracle examines a set of possible join orders - is based on the &quot;left deep&quot; tree, and is the unit that Oracle calls the &lt;a href=&quot;http://jonathanlewis.wordpress.com/2007/01/24/left-deep-trees/&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;&quot;query block&quot;&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;. 

If Oracle cannot transform your query into a single query block, it has to optimise each query block separately. In effect, each query block is a non-mergeable view - and in some cases Oracle will indicate this through the use of the VIEW operator.

Unfortunately, history and development cycles being what they are (a) the appearance of the VIEW operator is not totally consistent, and (b) as time passes the optimizes is enhanced to improve it&#039;s ability to transform more complicated queries into single query blocks.

Finally - compare a query block with a single table: there are execution plans where Oracle has to process the whole of table 1 before touching table 2; (e.g. hash join) there are execution plans where Oracle processes a bit of table 1 then a bit of table 2, and alternates between them  (e.g. nested loop join) - the same type of thinking applies to query blocks, some have to be evaluated completely before they can be used, some can be evaluated piecewise.

I&#039;ll try to remember to produce a different example some time over the next few weeks.]]></description>
		<content:encoded><![CDATA[<p>Timur,</p>
<p>Another way to think about it is to go back to the concepts of the <a href="http://jonathanlewis.wordpress.com/2007/01/24/left-deep-trees/" rel="nofollow"><em><strong>&#8220;left deep&#8221;</strong></em></a> and &#8220;bushy tree&#8221; optimisation plans.</p>
<p>The &#8220;unit of optimisation&#8221; &#8211; the thing where Oracle examines a set of possible join orders &#8211; is based on the &#8220;left deep&#8221; tree, and is the unit that Oracle calls the <a href="http://jonathanlewis.wordpress.com/2007/01/24/left-deep-trees/" rel="nofollow"><em><strong>&#8220;query block&#8221;</strong></em></a>. </p>
<p>If Oracle cannot transform your query into a single query block, it has to optimise each query block separately. In effect, each query block is a non-mergeable view &#8211; and in some cases Oracle will indicate this through the use of the VIEW operator.</p>
<p>Unfortunately, history and development cycles being what they are (a) the appearance of the VIEW operator is not totally consistent, and (b) as time passes the optimizes is enhanced to improve it&#8217;s ability to transform more complicated queries into single query blocks.</p>
<p>Finally &#8211; compare a query block with a single table: there are execution plans where Oracle has to process the whole of table 1 before touching table 2; (e.g. hash join) there are execution plans where Oracle processes a bit of table 1 then a bit of table 2, and alternates between them  (e.g. nested loop join) &#8211; the same type of thinking applies to query blocks, some have to be evaluated completely before they can be used, some can be evaluated piecewise.</p>
<p>I&#8217;ll try to remember to produce a different example some time over the next few weeks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33677</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 18:54:11 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33677</guid>
		<description><![CDATA[Narenda,

Addressing the rownum issue specifically - I think that Tom has pointed out in the past that if you &quot;select rownum&quot; it&#039;s a very good way of forcing Oracle to materialize the result set. The example you&#039;ve referenced is using a &quot;rownum &lt;= N&quot; clause which limits the results returned from select. This has a very different effect, and can be optimised in various ways in different versions of Oracle.

Even in the case of the &quot;select rownum&quot; though, I&#039;ve never been certain that the full result set has to be materilized before any of it can be used - it probably depends on the exact nature of the surrounding query.]]></description>
		<content:encoded><![CDATA[<p>Narenda,</p>
<p>Addressing the rownum issue specifically &#8211; I think that Tom has pointed out in the past that if you &#8220;select rownum&#8221; it&#8217;s a very good way of forcing Oracle to materialize the result set. The example you&#8217;ve referenced is using a &#8220;rownum &lt;= N&quot; clause which limits the results returned from select. This has a very different effect, and can be optimised in various ways in different versions of Oracle.</p>
<p>Even in the case of the &quot;select rownum&quot; though, I&#039;ve never been certain that the full result set has to be materilized before any of it can be used &#8211; it probably depends on the exact nature of the surrounding query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Narendra</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33670</link>
		<dc:creator><![CDATA[Narendra]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 12:15:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33670</guid>
		<description><![CDATA[Corey,

Thanks for your reply. I have not managed to test the scenario but what has surprised me is that Tom has suggested that &quot;it never had to&quot; materialize as a result of using ROWNUM. I believe that means it was the case in versions prior to 10g, as well.]]></description>
		<content:encoded><![CDATA[<p>Corey,</p>
<p>Thanks for your reply. I have not managed to test the scenario but what has surprised me is that Tom has suggested that &#8220;it never had to&#8221; materialize as a result of using ROWNUM. I believe that means it was the case in versions prior to 10g, as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Corey</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33668</link>
		<dc:creator><![CDATA[Corey]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 11:54:45 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33668</guid>
		<description><![CDATA[What version of Oracle are you using? 

This may be related:

As of 10.2.x.x and up there is a parameter called OPTIMIZER_SECURE_VIEW_MERGING (http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams146.htm) that can prevent merging from happening and cause a view to materialize. Christian Antognini has an excellent explanation in his book Troubleshooting Oracle Performance.]]></description>
		<content:encoded><![CDATA[<p>What version of Oracle are you using? </p>
<p>This may be related:</p>
<p>As of 10.2.x.x and up there is a parameter called OPTIMIZER_SECURE_VIEW_MERGING (<a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams146.htm" rel="nofollow">http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams146.htm</a>) that can prevent merging from happening and cause a view to materialize. Christian Antognini has an excellent explanation in his book Troubleshooting Oracle Performance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Narendra</title>
		<link>http://jonathanlewis.wordpress.com/2009/06/25/explain-view/#comment-33664</link>
		<dc:creator><![CDATA[Narendra]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 08:08:06 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=165#comment-33664</guid>
		<description><![CDATA[Jonathan,

Thanks. It is nice to read about EXPLAIN PLAN output in between.
Now, I had this doubt since I read one of Tom&#039;s responses recently
(http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2853107469873#1772855900346026443)
What makes CBO decide NOT to merge inline views/subqueries? I had thought use of ROWNUM (and GROUP BY, DISTINCT etc.) would FORCE the optimizer to materialize the subquery/inline view. Apparantly, Tom suggests that is not the case.
I am especially puzzled about ROWNUM not forcing the subquery to materialize.
Any chance you can throw some light?]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>Thanks. It is nice to read about EXPLAIN PLAN output in between.<br />
Now, I had this doubt since I read one of Tom&#8217;s responses recently<br />
(<a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0" rel="nofollow">http://asktom.oracle.com/pls/asktom/f?p=100:11:0</a>::::P11_QUESTION_ID:2853107469873#1772855900346026443)<br />
What makes CBO decide NOT to merge inline views/subqueries? I had thought use of ROWNUM (and GROUP BY, DISTINCT etc.) would FORCE the optimizer to materialize the subquery/inline view. Apparantly, Tom suggests that is not the case.<br />
I am especially puzzled about ROWNUM not forcing the subquery to materialize.<br />
Any chance you can throw some light?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
