<?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: Sorting</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 22 May 2013 12:40:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53519</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Wed, 13 Feb 2013 18:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53519</guid>
		<description><![CDATA[Jonathan,

thank you, sir! Your opinion is very important for me! 
I have a couple more finds about deterministic functions and ssc and I will post them asap.]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>thank you, sir! Your opinion is very important for me!<br />
I have a couple more finds about deterministic functions and ssc and I will post them asap.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53514</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 13 Feb 2013 16:56:43 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53514</guid>
		<description><![CDATA[Sayan,

Thanks for the link. Interesting difference in the caching effects.]]></description>
		<content:encoded><![CDATA[<p>Sayan,</p>
<p>Thanks for the link. Interesting difference in the caching effects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53467</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Sun, 10 Feb 2013 19:42:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53467</guid>
		<description><![CDATA[I finally wrote first part about deterministic functions on 11.2 - http://orasql.org/2013/02/10/deterministic-function-vs-scalar-subquery-caching-part-1/]]></description>
		<content:encoded><![CDATA[<p>I finally wrote first part about deterministic functions on 11.2 &#8211; <a href="http://orasql.org/2013/02/10/deterministic-function-vs-scalar-subquery-caching-part-1/" rel="nofollow">http://orasql.org/2013/02/10/deterministic-function-vs-scalar-subquery-caching-part-1/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Losing it &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53234</link>
		<dc:creator><![CDATA[Losing it &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Mon, 28 Jan 2013 18:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53234</guid>
		<description><![CDATA[[...] example I gave last week showing how a SORT operation in an execution plan might include the work of resolving function [...]]]></description>
		<content:encoded><![CDATA[<p>[...] example I gave last week showing how a SORT operation in an execution plan might include the work of resolving function [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53201</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 21:33:04 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53201</guid>
		<description><![CDATA[Yes, for example with &quot;_query_execution_cache_max_size&quot; = 2097152 if we started from 1, first hash collision will be with 260.]]></description>
		<content:encoded><![CDATA[<p>Yes, for example with &#8220;_query_execution_cache_max_size&#8221; = 2097152 if we started from 1, first hash collision will be with 260.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Preiss</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53200</link>
		<dc:creator><![CDATA[Martin Preiss]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 20:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53200</guid>
		<description><![CDATA[should have been life I guess ...]]></description>
		<content:encoded><![CDATA[<p>should have been life I guess &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Preiss</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53199</link>
		<dc:creator><![CDATA[Martin Preiss]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 20:16:51 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53199</guid>
		<description><![CDATA[Sayan,

thank you for your explaining comment. In Cost Based Oracle (chapter 9) I saw that in 10g the size of the hash table was controlled by _query_execution_cache_max_size - and obviously that is still true in 11.2.0.1. With values above the default (65536) the number of Buffers drops to the value I expected:
[sourcecode]
alter session set &quot;_query_execution_cache_max_size&quot;=262144;

-----------------------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation           &#124; Name &#124; Starts &#124; E-Rows &#124; A-Rows &#124;   A-Time   &#124; Buffers &#124;  OMem &#124;  1Mem &#124; Used-Mem &#124;
-----------------------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT    &#124;      &#124;      1 &#124;        &#124;      0 &#124;00:00:00.09 &#124;   29820 &#124;       &#124;       &#124;          &#124;
&#124;   1 &#124;  MINUS              &#124;      &#124;      1 &#124;        &#124;      0 &#124;00:00:00.09 &#124;   29820 &#124;       &#124;       &#124;          &#124;
&#124;   2 &#124;   SORT UNIQUE       &#124;      &#124;      1 &#124;   2500 &#124;    250 &#124;00:00:00.01 &#124;      77 &#124; 13312 &#124; 13312 &#124;12288  (0)&#124;
&#124;   3 &#124;    TABLE ACCESS FULL&#124; T1   &#124;      1 &#124;   2500 &#124;   2500 &#124;00:00:00.01 &#124;      77 &#124;       &#124;       &#124;          &#124;
&#124;   4 &#124;   SORT UNIQUE       &#124;      &#124;      1 &#124;   2500 &#124;    250 &#124;00:00:00.08 &#124;   29743 &#124; 13312 &#124; 13312 &#124;12288  (0)&#124;
&#124;   5 &#124;    TABLE ACCESS FULL&#124; T2   &#124;      1 &#124;   2500 &#124;   2500 &#124;00:00:00.01 &#124;      77 &#124;       &#124;       &#124;          &#124;
-----------------------------------------------------------------------------------------------------------------

alter session set &quot;_query_execution_cache_max_size&quot;=2097152;

-----------------------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation           &#124; Name &#124; Starts &#124; E-Rows &#124; A-Rows &#124;   A-Time   &#124; Buffers &#124;  OMem &#124;  1Mem &#124; Used-Mem &#124;
-----------------------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT    &#124;      &#124;      1 &#124;        &#124;      0 &#124;00:00:00.06 &#124;   19425 &#124;       &#124;       &#124;          &#124;
&#124;   1 &#124;  MINUS              &#124;      &#124;      1 &#124;        &#124;      0 &#124;00:00:00.06 &#124;   19425 &#124;       &#124;       &#124;          &#124;
&#124;   2 &#124;   SORT UNIQUE       &#124;      &#124;      1 &#124;   2500 &#124;    250 &#124;00:00:00.01 &#124;      77 &#124; 13312 &#124; 13312 &#124;12288  (0)&#124;
&#124;   3 &#124;    TABLE ACCESS FULL&#124; T1   &#124;      1 &#124;   2500 &#124;   2500 &#124;00:00:00.01 &#124;      77 &#124;       &#124;       &#124;          &#124;
&#124;   4 &#124;   SORT UNIQUE       &#124;      &#124;      1 &#124;   2500 &#124;    250 &#124;00:00:00.06 &#124;   19348 &#124; 13312 &#124; 13312 &#124;12288  (0)&#124;
&#124;   5 &#124;    TABLE ACCESS FULL&#124; T2   &#124;      1 &#124;   2500 &#124;   2500 &#124;00:00:00.01 &#124;      77 &#124;       &#124;       &#124;          &#124;
-----------------------------------------------------------------------------------------------------------------
[/sourcecode]
With the difference of 98 blocks (19348 - 19250) I can live ...

Martin]]></description>
		<content:encoded><![CDATA[<p>Sayan,</p>
<p>thank you for your explaining comment. In Cost Based Oracle (chapter 9) I saw that in 10g the size of the hash table was controlled by _query_execution_cache_max_size &#8211; and obviously that is still true in 11.2.0.1. With values above the default (65536) the number of Buffers drops to the value I expected:</p>
<pre class="brush: plain; title: ; notranslate">
alter session set &quot;_query_execution_cache_max_size&quot;=262144;

-----------------------------------------------------------------------------------------------------------------
| Id  | Operation           | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |      |      1 |        |      0 |00:00:00.09 |   29820 |       |       |          |
|   1 |  MINUS              |      |      1 |        |      0 |00:00:00.09 |   29820 |       |       |          |
|   2 |   SORT UNIQUE       |      |      1 |   2500 |    250 |00:00:00.01 |      77 | 13312 | 13312 |12288  (0)|
|   3 |    TABLE ACCESS FULL| T1   |      1 |   2500 |   2500 |00:00:00.01 |      77 |       |       |          |
|   4 |   SORT UNIQUE       |      |      1 |   2500 |    250 |00:00:00.08 |   29743 | 13312 | 13312 |12288  (0)|
|   5 |    TABLE ACCESS FULL| T2   |      1 |   2500 |   2500 |00:00:00.01 |      77 |       |       |          |
-----------------------------------------------------------------------------------------------------------------

alter session set &quot;_query_execution_cache_max_size&quot;=2097152;

-----------------------------------------------------------------------------------------------------------------
| Id  | Operation           | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |      |      1 |        |      0 |00:00:00.06 |   19425 |       |       |          |
|   1 |  MINUS              |      |      1 |        |      0 |00:00:00.06 |   19425 |       |       |          |
|   2 |   SORT UNIQUE       |      |      1 |   2500 |    250 |00:00:00.01 |      77 | 13312 | 13312 |12288  (0)|
|   3 |    TABLE ACCESS FULL| T1   |      1 |   2500 |   2500 |00:00:00.01 |      77 |       |       |          |
|   4 |   SORT UNIQUE       |      |      1 |   2500 |    250 |00:00:00.06 |   19348 | 13312 | 13312 |12288  (0)|
|   5 |    TABLE ACCESS FULL| T2   |      1 |   2500 |   2500 |00:00:00.01 |      77 |       |       |          |
-----------------------------------------------------------------------------------------------------------------
</pre>
<p>With the difference of 98 blocks (19348 &#8211; 19250) I can live &#8230;</p>
<p>Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53198</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 17:53:56 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53198</guid>
		<description><![CDATA[Also hash functions for  deterministic functions and scalar subquery caching mechanizm are the same.]]></description>
		<content:encoded><![CDATA[<p>Also hash functions for  deterministic functions and scalar subquery caching mechanizm are the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53197</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 17:52:45 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53197</guid>
		<description><![CDATA[Martin, i recently investigate deterministic functions mechanizm. It is because of hash collision of parameters hash. When function executes with different input parameter and their hashes is equal, will be cashed only first result. I&#039;ll write about it fully later.]]></description>
		<content:encoded><![CDATA[<p>Martin, i recently investigate deterministic functions mechanizm. It is because of hash collision of parameters hash. When function executes with different input parameter and their hashes is equal, will be cashed only first result. I&#8217;ll write about it fully later.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Preiss</title>
		<link>http://jonathanlewis.wordpress.com/2013/01/25/sorting-2/#comment-53196</link>
		<dc:creator><![CDATA[Martin Preiss]]></dc:creator>
		<pubDate>Sat, 26 Jan 2013 17:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=10481#comment-53196</guid>
		<description><![CDATA[Jonathan,

perhaps it&#039;s not too closely related to the topic of the article - but playing a little bit with your example I got a surprising &quot;Buffers&quot; value. My modifications of your example were the use of MOD to limit the number of different IDs and a DETERMINISTIC keyword added to the function definition:

[sourcecode]
create table t1
as
select
    mod(rownum, 250)          id,
    lpad(rownum,200)    padding
from    all_objects
where   rownum &lt;= 2500
;
 
create table t2
as
select  * from t1
;
 
exec dbms_stats.gather_table_stats(user, &#039;t1&#039;)
exec dbms_stats.gather_table_stats(user, &#039;t2&#039;)
 
create or replace function f (i_target in number)
return number deterministic
as
    m_target    number;
begin
    select max(id) into m_target from t1 where id &lt;= i_target;
    return m_target;
end;
/

select  /*+ gather_plan_statistics */
    id
from    t1
minus
select
    f(id)
from    t2
;
 
-----------------------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation           &#124; Name &#124; Starts &#124; E-Rows &#124; A-Rows &#124;   A-Time   &#124; Buffers &#124;  OMem &#124;  1Mem &#124; Used-Mem &#124;
-----------------------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT    &#124;      &#124;      1 &#124;        &#124;      0 &#124;00:00:00.16 &#124;   54747 &#124;       &#124;       &#124;          &#124;
&#124;   1 &#124;  MINUS              &#124;      &#124;      1 &#124;        &#124;      0 &#124;00:00:00.16 &#124;   54747 &#124;       &#124;       &#124;          &#124;
&#124;   2 &#124;   SORT UNIQUE       &#124;      &#124;      1 &#124;   2500 &#124;    250 &#124;00:00:00.01 &#124;      77 &#124; 13312 &#124; 13312 &#124;12288  (0)&#124;
&#124;   3 &#124;    TABLE ACCESS FULL&#124; T1   &#124;      1 &#124;   2500 &#124;   2500 &#124;00:00:00.01 &#124;      77 &#124;       &#124;       &#124;          &#124;
&#124;   4 &#124;   SORT UNIQUE       &#124;      &#124;      1 &#124;   2500 &#124;    250 &#124;00:00:00.16 &#124;   54670 &#124; 13312 &#124; 13312 &#124;12288  (0)&#124;
&#124;   5 &#124;    TABLE ACCESS FULL&#124; T2   &#124;      1 &#124;   2500 &#124;   2500 &#124;00:00:00.01 &#124;      77 &#124;       &#124;       &#124;          &#124;
-----------------------------------------------------------------------------------------------------------------

Column Projection Information (identified by operation id):
-----------------------------------------------------------

   1 - STRDEF[22]
   2 - (#keys=1) &quot;ID&quot;[NUMBER,22]
   3 - &quot;ID&quot;[NUMBER,22]
   4 - (#keys=1) &quot;F&quot;(&quot;ID&quot;)[22]
   5 - &quot;ID&quot;[NUMBER,22]
[/sourcecode]

I expected the Buffers for step 4 to be 77 * 250 = 19250: with one FTS for each distinct value in t2. But I got 54670 (= 77 * 710) (and I got the same results with clustered data when using TRUNC instead of MOD to create the test tables). Can you explain the number of buffers?

Martin]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>perhaps it&#8217;s not too closely related to the topic of the article &#8211; but playing a little bit with your example I got a surprising &#8220;Buffers&#8221; value. My modifications of your example were the use of MOD to limit the number of different IDs and a DETERMINISTIC keyword added to the function definition:</p>
<pre class="brush: plain; title: ; notranslate">
create table t1
as
select
    mod(rownum, 250)          id,
    lpad(rownum,200)    padding
from    all_objects
where   rownum &lt;= 2500
;
 
create table t2
as
select  * from t1
;
 
exec dbms_stats.gather_table_stats(user, 't1')
exec dbms_stats.gather_table_stats(user, 't2')
 
create or replace function f (i_target in number)
return number deterministic
as
    m_target    number;
begin
    select max(id) into m_target from t1 where id &lt;= i_target;
    return m_target;
end;
/

select  /*+ gather_plan_statistics */
    id
from    t1
minus
select
    f(id)
from    t2
;
 
-----------------------------------------------------------------------------------------------------------------
| Id  | Operation           | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |      |      1 |        |      0 |00:00:00.16 |   54747 |       |       |          |
|   1 |  MINUS              |      |      1 |        |      0 |00:00:00.16 |   54747 |       |       |          |
|   2 |   SORT UNIQUE       |      |      1 |   2500 |    250 |00:00:00.01 |      77 | 13312 | 13312 |12288  (0)|
|   3 |    TABLE ACCESS FULL| T1   |      1 |   2500 |   2500 |00:00:00.01 |      77 |       |       |          |
|   4 |   SORT UNIQUE       |      |      1 |   2500 |    250 |00:00:00.16 |   54670 | 13312 | 13312 |12288  (0)|
|   5 |    TABLE ACCESS FULL| T2   |      1 |   2500 |   2500 |00:00:00.01 |      77 |       |       |          |
-----------------------------------------------------------------------------------------------------------------

Column Projection Information (identified by operation id):
-----------------------------------------------------------

   1 - STRDEF[22]
   2 - (#keys=1) &quot;ID&quot;[NUMBER,22]
   3 - &quot;ID&quot;[NUMBER,22]
   4 - (#keys=1) &quot;F&quot;(&quot;ID&quot;)[22]
   5 - &quot;ID&quot;[NUMBER,22]
</pre>
<p>I expected the Buffers for step 4 to be 77 * 250 = 19250: with one FTS for each distinct value in t2. But I got 54670 (= 77 * 710) (and I got the same results with clustered data when using TRUNC instead of MOD to create the test tables). Can you explain the number of buffers?</p>
<p>Martin</p>
]]></content:encoded>
	</item>
</channel>
</rss>
