<?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: Filter Subqueries</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sat, 18 May 2013 11:04:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Plan timing &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-51548</link>
		<dc:creator><![CDATA[Plan timing &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Mon, 19 Nov 2012 21:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-51548</guid>
		<description><![CDATA[[...] Note: although the plan in lines 3 &#8211; 7 could be executed once for each row returned by the plan in lines 9 &#8211; 11, the number of executions could (and in this case is) fewer than the worst case thanks to scalar subquery caching. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Note: although the plan in lines 3 &#8211; 7 could be executed once for each row returned by the plan in lines 9 &#8211; 11, the number of executions could (and in this case is) fewer than the worst case thanks to scalar subquery caching. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Indexes are Tables &#8211; All Things Oracle</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-43223</link>
		<dc:creator><![CDATA[Indexes are Tables &#8211; All Things Oracle]]></dc:creator>
		<pubDate>Fri, 16 Dec 2011 14:48:17 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-43223</guid>
		<description><![CDATA[[...] different products – which is unlikely in this case) we may find that our subquery benefits from “scalar subquery caching”, which means that under perfect conditions we will run the subquery just once per product sold in [...]]]></description>
		<content:encoded><![CDATA[<p>[...] different products – which is unlikely in this case) we may find that our subquery benefits from “scalar subquery caching”, which means that under perfect conditions we will run the subquery just once per product sold in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-37183</link>
		<dc:creator><![CDATA[Victor]]></dc:creator>
		<pubDate>Fri, 03 Sep 2010 14:47:28 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-37183</guid>
		<description><![CDATA[Thanks Jonathan for your reply. I see. I came to this post from &quot;Join ordering&quot; post where you talk about different strategies on similar kind of queries and now it makes more sense. There is something I can&#039;t understand as you said &quot;When I changed the first occurrence of department 1 to 432, Oracle got to the row with department 432 before it got to a row with department 1, and stored the average salary for department 432 in the hash table location that would otherwise have been used by department 1.&quot;. Do you know about how the algorithm builds the hash table to go into this hash colission (as you called it)?
Many thanks.]]></description>
		<content:encoded><![CDATA[<p>Thanks Jonathan for your reply. I see. I came to this post from &#8220;Join ordering&#8221; post where you talk about different strategies on similar kind of queries and now it makes more sense. There is something I can&#8217;t understand as you said &#8220;When I changed the first occurrence of department 1 to 432, Oracle got to the row with department 432 before it got to a row with department 1, and stored the average salary for department 432 in the hash table location that would otherwise have been used by department 1.&#8221;. Do you know about how the algorithm builds the hash table to go into this hash colission (as you called it)?<br />
Many thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-37182</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 03 Sep 2010 11:35:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-37182</guid>
		<description><![CDATA[Victor,

The transformation you&#039;ve done to get your query is known as unnesting. In this specific case, to demonstrate a point, I blocked the automatic unnesting that the optimizer would have done; but there are some cases of filter subqueries which the optimizer won&#039;t handle automatically that you could do this type of manual rewrite for.]]></description>
		<content:encoded><![CDATA[<p>Victor,</p>
<p>The transformation you&#8217;ve done to get your query is known as unnesting. In this specific case, to demonstrate a point, I blocked the automatic unnesting that the optimizer would have done; but there are some cases of filter subqueries which the optimizer won&#8217;t handle automatically that you could do this type of manual rewrite for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-37179</link>
		<dc:creator><![CDATA[Victor]]></dc:creator>
		<pubDate>Thu, 02 Sep 2010 14:43:03 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-37179</guid>
		<description><![CDATA[Hi Jonathan,

Many thanks for this amazing blog.

How about using below query ? it seems then you avoid to run the subquery again and again as it does a join between emp and avg.
[sourcecode gutter=&quot;false&quot;]
select
        count(*)
        from    emp,
         (  select  dept_no,
                      avg(inner.sal) sal 
               from    emp inner
              group by dept_no
            ) avg
        where   emp.sal &gt; avg.sal
           and   emp.dept_no = avg.dept_no
[/sourcecode]

Cheers,
Victor
]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>Many thanks for this amazing blog.</p>
<p>How about using below query ? it seems then you avoid to run the subquery again and again as it does a join between emp and avg.</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
select
        count(*)
        from    emp,
         (  select  dept_no,
                      avg(inner.sal) sal 
               from    emp inner
              group by dept_no
            ) avg
        where   emp.sal &gt; avg.sal
           and   emp.dept_no = avg.dept_no
</pre>
<p>Cheers,<br />
Victor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: No change &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34831</link>
		<dc:creator><![CDATA[No change &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Thu, 12 Nov 2009 19:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34831</guid>
		<description><![CDATA[[...] A small change in data can cause a huge  variation in the number of times a subquery runs [...]]]></description>
		<content:encoded><![CDATA[<p>[...] A small change in data can cause a huge  variation in the number of times a subquery runs [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: josh</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34659</link>
		<dc:creator><![CDATA[josh]]></dc:creator>
		<pubDate>Mon, 19 Oct 2009 16:11:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34659</guid>
		<description><![CDATA[Hi Jonathan,

Can this type of collision happen to a character based columns not just numbers]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>Can this type of collision happen to a character based columns not just numbers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henish</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34077</link>
		<dc:creator><![CDATA[Henish]]></dc:creator>
		<pubDate>Fri, 07 Aug 2009 14:14:08 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34077</guid>
		<description><![CDATA[Hello Sir,

It would be great if you would please flash more light on your below comment


&quot;I defined a table with no indexes in a tablespace using freelist management, so I could make some reasonable assumptions about the way in the which the data would be inserted and queried&quot;


Many Thanks]]></description>
		<content:encoded><![CDATA[<p>Hello Sir,</p>
<p>It would be great if you would please flash more light on your below comment</p>
<p>&#8220;I defined a table with no indexes in a tablespace using freelist management, so I could make some reasonable assumptions about the way in the which the data would be inserted and queried&#8221;</p>
<p>Many Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34066</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 06 Aug 2009 17:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34066</guid>
		<description><![CDATA[Henish,
If I&#039;ve understood your questions, you want to know (a) why Oracle got to the row with the department set to 432 before it got to a row with department set to 1; and (b) why 432 and 1 has to the same location.

a) Although you should not rely on any specific ordering of data (or action) when using SQL, there are simple cases where the actual mechanics cannot change. I defined a table with no indexes in a tablespace using freelist management, so I could make some reasonable assumptions about the way in the which the data would be inserted and queried. In effect I was relying on my knowledge of the current internal mechanics used by Oracle - this is not something I would do for a production system.

b) The principle of hashing is that you have an infinite number of different values that you need to store as evenly as possible in a finite number of locations. Consequently you will find cases where two different input numbers hash to the same output value. I justed experimented until I found a suitable second number.]]></description>
		<content:encoded><![CDATA[<p>Henish,<br />
If I&#8217;ve understood your questions, you want to know (a) why Oracle got to the row with the department set to 432 before it got to a row with department set to 1; and (b) why 432 and 1 has to the same location.</p>
<p>a) Although you should not rely on any specific ordering of data (or action) when using SQL, there are simple cases where the actual mechanics cannot change. I defined a table with no indexes in a tablespace using freelist management, so I could make some reasonable assumptions about the way in the which the data would be inserted and queried. In effect I was relying on my knowledge of the current internal mechanics used by Oracle &#8211; this is not something I would do for a production system.</p>
<p>b) The principle of hashing is that you have an infinite number of different values that you need to store as evenly as possible in a finite number of locations. Consequently you will find cases where two different input numbers hash to the same output value. I justed experimented until I found a suitable second number.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henish</title>
		<link>http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34039</link>
		<dc:creator><![CDATA[Henish]]></dc:creator>
		<pubDate>Tue, 04 Aug 2009 20:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/#comment-34039</guid>
		<description><![CDATA[Respected Sir,



update emp
	set dept_no = 432
where
	dept_no = 1
and	rownum = 1


In your above example with respect to filter you updated the first row of dept_no=1 with 432. 

Also you said a statement as below  



Oracle got to the row with department 432 before it got to a row with department 1, and stored the average salary for department 432 in the hash table location that would otherwise have been used by department 1



I have one confusion that who would it possible during sql execution that the row with deptno=432 appear first among other row with same department (i.e. dept_no =1)

could you please flash more light on this?

Also who could oracle hash dept_no=432 on the location where dept_no=1 would supppose to be store?


Thanks 

Sir]]></description>
		<content:encoded><![CDATA[<p>Respected Sir,</p>
<p>update emp<br />
	set dept_no = 432<br />
where<br />
	dept_no = 1<br />
and	rownum = 1</p>
<p>In your above example with respect to filter you updated the first row of dept_no=1 with 432. </p>
<p>Also you said a statement as below  </p>
<p>Oracle got to the row with department 432 before it got to a row with department 1, and stored the average salary for department 432 in the hash table location that would otherwise have been used by department 1</p>
<p>I have one confusion that who would it possible during sql execution that the row with deptno=432 appear first among other row with same department (i.e. dept_no =1)</p>
<p>could you please flash more light on this?</p>
<p>Also who could oracle hash dept_no=432 on the location where dept_no=1 would supppose to be store?</p>
<p>Thanks </p>
<p>Sir</p>
]]></content:encoded>
	</item>
</channel>
</rss>
