<?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: Count(*)</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/03/04/count-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Fri, 24 May 2013 13:27:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Pavol Babel</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45626</link>
		<dc:creator><![CDATA[Pavol Babel]]></dc:creator>
		<pubDate>Tue, 20 Mar 2012 09:00:23 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45626</guid>
		<description><![CDATA[Randolf, here is reduced tkprof output from AIX. Getting O/S level statistics is slow on some platforms. I noticed only on 10g Linux / Windows. I&#039;m not able to reproduce issue even on 9.2.0.8 on Linux x86

[sourcecode language=&quot;css&quot;]

SELECT
       COUNT (SOURCE)
  FROM (SELECT /*+ full(source$) */
               SOURCE
          FROM sys.source$
        UNION ALL
        SELECT /*+ full(source$) */
               SOURCE
          FROM sys.source$);

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      1.77       5.04      40238      40264          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      1.77       5.04      40238      40264          0           1




SELECT
       sum(cnt)
  FROM (SELECT /*+ full(source$) */
               count(SOURCE) cnt
          FROM sys.source$
        UNION ALL
        SELECT /*+ full(source$) */
               count(SOURCE)
          FROM sys.source$)

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      1.28       2.90      40198      40264          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      1.28       2.90      40198      40264          0           1

[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Randolf, here is reduced tkprof output from AIX. Getting O/S level statistics is slow on some platforms. I noticed only on 10g Linux / Windows. I&#8217;m not able to reproduce issue even on 9.2.0.8 on Linux x86</p>
<pre class="brush: css; title: ; notranslate">

SELECT
       COUNT (SOURCE)
  FROM (SELECT /*+ full(source$) */
               SOURCE
          FROM sys.source$
        UNION ALL
        SELECT /*+ full(source$) */
               SOURCE
          FROM sys.source$);

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      1.77       5.04      40238      40264          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      1.77       5.04      40238      40264          0           1




SELECT
       sum(cnt)
  FROM (SELECT /*+ full(source$) */
               count(SOURCE) cnt
          FROM sys.source$
        UNION ALL
        SELECT /*+ full(source$) */
               count(SOURCE)
          FROM sys.source$)

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      1.28       2.90      40198      40264          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      1.28       2.90      40198      40264          0           1

</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randolf Geist</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45365</link>
		<dc:creator><![CDATA[Randolf Geist]]></dc:creator>
		<pubDate>Thu, 08 Mar 2012 14:35:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45365</guid>
		<description><![CDATA[I think it&#039;s worth to point out that enabling tracing also enables Rowsource statistics sampling - and it is this Rowsource statistics sampling I believe that is responsible for the different results on different platforms. It even seems to differ between versions on the same platform: For example I have a 11.1.0.7 64bit Windows instance that is significantly faster than 10.2.0.4 64bit or 11.2.0.1 64bit on the same platform when enabling Rowsource statistics sampling. The difference is particularly significant when increasing the sample frequency, for example by simply setting STATISTICS_LEVEL = ALL.

It is a known issue that getting the time information from the O/S is the sensitive part of that operation, and probably the 9.2.0.8 port on AIX is much more efficient in that regard than other ports.

When taking stack traces during such a long running execution, in particular when using high sample frequencies, it can be seen that almost all time is spent on the ftime function calls.

Randolf]]></description>
		<content:encoded><![CDATA[<p>I think it&#8217;s worth to point out that enabling tracing also enables Rowsource statistics sampling &#8211; and it is this Rowsource statistics sampling I believe that is responsible for the different results on different platforms. It even seems to differ between versions on the same platform: For example I have a 11.1.0.7 64bit Windows instance that is significantly faster than 10.2.0.4 64bit or 11.2.0.1 64bit on the same platform when enabling Rowsource statistics sampling. The difference is particularly significant when increasing the sample frequency, for example by simply setting STATISTICS_LEVEL = ALL.</p>
<p>It is a known issue that getting the time information from the O/S is the sensitive part of that operation, and probably the 9.2.0.8 port on AIX is much more efficient in that regard than other ports.</p>
<p>When taking stack traces during such a long running execution, in particular when using high sample frequencies, it can be seen that almost all time is spent on the ftime function calls.</p>
<p>Randolf</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavol Babel</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45355</link>
		<dc:creator><![CDATA[Pavol Babel]]></dc:creator>
		<pubDate>Thu, 08 Mar 2012 00:10:20 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45355</guid>
		<description><![CDATA[Jonathan,

I also gave a try to your hinted source$ example (response to sid). There is not such a huge difference between queries. It is 3 vs 3.5 seconds (with 2.9 million rows in sys,source$) on my database (9.2.0.8 AIX 5L 5.3 POWER6 4208MHz, 8 CORES). It seems data pipelining between execution plan operators is much faster on AIX. Will uload tkprof output later (now I&#039;m too tired), too.

Regards
Pavol Babel]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>I also gave a try to your hinted source$ example (response to sid). There is not such a huge difference between queries. It is 3 vs 3.5 seconds (with 2.9 million rows in sys,source$) on my database (9.2.0.8 AIX 5L 5.3 POWER6 4208MHz, 8 CORES). It seems data pipelining between execution plan operators is much faster on AIX. Will uload tkprof output later (now I&#8217;m too tired), too.</p>
<p>Regards<br />
Pavol Babel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavol Babel</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45343</link>
		<dc:creator><![CDATA[Pavol Babel]]></dc:creator>
		<pubDate>Wed, 07 Mar 2012 11:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45343</guid>
		<description><![CDATA[Jonathan, there is no execution plan change on AIX. At least I didn&#039;t notice. I will upload execution plans later.

Regards

Pavol Babel]]></description>
		<content:encoded><![CDATA[<p>Jonathan, there is no execution plan change on AIX. At least I didn&#8217;t notice. I will upload execution plans later.</p>
<p>Regards</p>
<p>Pavol Babel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45327</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 17:06:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45327</guid>
		<description><![CDATA[Pavol,

I find that a little surprising - it certainly reproduces on 9.2.0.8 on windows, and I wouldn&#039;t have thought that a change of O/S would cause a change in plan.]]></description>
		<content:encoded><![CDATA[<p>Pavol,</p>
<p>I find that a little surprising &#8211; it certainly reproduces on 9.2.0.8 on windows, and I wouldn&#8217;t have thought that a change of O/S would cause a change in plan.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45326</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 17:04:50 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45326</guid>
		<description><![CDATA[Sid, 

The idea was a good one, but Oracle does get a bit clever with constants and counts. If you want to use the projection information to demonstrate the size of the data flow you need to select and count a non-null column from the table and use that column name all the way through the query. Here&#039;s a sample that uses source$ to make the point:
[sourcecode gutter=&quot;false&quot;]
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  3g2w174t501g6, child number 0
-------------------------------------
select         /*+ gather_plan_statistics */         count(source) from    (
   select /*+ full(source$) */ source from source$         union all
select /*+ full(source$) */ source from source$         )

Plan hash value: 3996963393

------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation            &#124; Name    &#124; Starts &#124; E-Rows &#124; A-Rows &#124;   A-Time   &#124; Buffers &#124;
------------------------------------------------------------------------------------------
&#124;   1 &#124;  SORT AGGREGATE      &#124;         &#124;      1 &#124;      1 &#124;      1 &#124;00:00:00.55 &#124;    9782 &#124;
&#124;   2 &#124;   VIEW               &#124;         &#124;      1 &#124;    569K&#124;    571K&#124;00:00:10.86 &#124;    9782 &#124;
&#124;   3 &#124;    UNION-ALL         &#124;         &#124;      1 &#124;        &#124;    571K&#124;00:00:06.86 &#124;    9782 &#124;
&#124;   4 &#124;     TABLE ACCESS FULL&#124; SOURCE$ &#124;      1 &#124;    284K&#124;    285K&#124;00:00:01.43 &#124;    4891 &#124;
&#124;   5 &#124;     TABLE ACCESS FULL&#124; SOURCE$ &#124;      1 &#124;    284K&#124;    285K&#124;00:00:01.14 &#124;    4891 &#124;
------------------------------------------------------------------------------------------

Column Projection Information (identified by operation id):
-----------------------------------------------------------
   1 - (#keys=0) COUNT(&quot;SOURCE&quot;)[22]
   2 - &quot;SOURCE&quot;[VARCHAR2,4000]
   3 - STRDEF[4000]
   4 - &quot;SOURCE&quot;[VARCHAR2,4000]
   5 - &quot;SOURCE&quot;[VARCHAR2,4000]

[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Sid, </p>
<p>The idea was a good one, but Oracle does get a bit clever with constants and counts. If you want to use the projection information to demonstrate the size of the data flow you need to select and count a non-null column from the table and use that column name all the way through the query. Here&#8217;s a sample that uses source$ to make the point:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  3g2w174t501g6, child number 0
-------------------------------------
select         /*+ gather_plan_statistics */         count(source) from    (
   select /*+ full(source$) */ source from source$         union all
select /*+ full(source$) */ source from source$         )

Plan hash value: 3996963393

------------------------------------------------------------------------------------------
| Id  | Operation            | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
------------------------------------------------------------------------------------------
|   1 |  SORT AGGREGATE      |         |      1 |      1 |      1 |00:00:00.55 |    9782 |
|   2 |   VIEW               |         |      1 |    569K|    571K|00:00:10.86 |    9782 |
|   3 |    UNION-ALL         |         |      1 |        |    571K|00:00:06.86 |    9782 |
|   4 |     TABLE ACCESS FULL| SOURCE$ |      1 |    284K|    285K|00:00:01.43 |    4891 |
|   5 |     TABLE ACCESS FULL| SOURCE$ |      1 |    284K|    285K|00:00:01.14 |    4891 |
------------------------------------------------------------------------------------------

Column Projection Information (identified by operation id):
-----------------------------------------------------------
   1 - (#keys=0) COUNT(&quot;SOURCE&quot;)[22]
   2 - &quot;SOURCE&quot;[VARCHAR2,4000]
   3 - STRDEF[4000]
   4 - &quot;SOURCE&quot;[VARCHAR2,4000]
   5 - &quot;SOURCE&quot;[VARCHAR2,4000]

</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sid</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45319</link>
		<dc:creator><![CDATA[Sid]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 14:45:16 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45319</guid>
		<description><![CDATA[In the first query, The null really hides the fact that the data from union all operator will be passed to the parent view. There is no column information for the union all operator. Replace the null with 1, the clue will reveal.

[sourcecode]
select count(*)
from (
	select null from big_table
	union all
	select null from big_table
);

------------------------------------------------------------------------
&#124; Id  &#124; Operation		&#124; Name &#124; Rows  &#124; Cost (%CPU)&#124; Time     &#124;
------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT	&#124;      &#124;     1 &#124;  8926	 (2)&#124; 00:01:48 &#124;
&#124;   1 &#124;  SORT AGGREGATE 	&#124;      &#124;     1 &#124;	    &#124;	       &#124;
&#124;   2 &#124;   VIEW			&#124;      &#124;  7984K&#124;  8926	 (2)&#124; 00:01:48 &#124;
&#124;   3 &#124;    UNION-ALL		&#124;      &#124;       &#124;	    &#124;	       &#124;
&#124;   4 &#124;     INDEX FAST FULL SCAN&#124; FOO  &#124;  3992K&#124;  4463	 (2)&#124; 00:00:54 &#124;
&#124;   5 &#124;     INDEX FAST FULL SCAN&#124; FOO  &#124;  3992K&#124;  4463	 (2)&#124; 00:00:54 &#124;
------------------------------------------------------------------------

Column Projection Information (identified by operation id):
-----------------------------------------------------------

   1 - (#keys=0) COUNT(*)[22]


select count(*)
from (
	select 1 from big_table
	union all
	select 1 from big_table
);

---------------------------------------------------------------------------------
&#124; Id  &#124; Operation		 &#124; Name &#124; Rows	&#124; Bytes &#124; Cost (%CPU)&#124; Time	&#124;
---------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT	 &#124;	&#124;     1 &#124;    13 &#124;  8926   (2)&#124; 00:01:48 &#124;
&#124;   1 &#124;  SORT AGGREGATE 	 &#124;	&#124;     1 &#124;    13 &#124;	     &#124;		&#124;
&#124;   2 &#124;   VIEW			 &#124;	&#124;     2 &#124;    26 &#124;  8926   (2)&#124; 00:01:48 &#124;
&#124;   3 &#124;    UNION-ALL		 &#124;	&#124;	&#124;	&#124;	     &#124;		&#124;
&#124;   4 &#124;     SORT AGGREGATE	 &#124;	&#124;     1 &#124;	&#124;	     &#124;		&#124;
&#124;   5 &#124;      INDEX FAST FULL SCAN&#124; FOO	&#124;  3992K&#124;	&#124;  4463   (2)&#124; 00:00:54 &#124;
&#124;   6 &#124;     SORT AGGREGATE	 &#124;	&#124;     1 &#124;	&#124;	     &#124;		&#124;
&#124;   7 &#124;      INDEX FAST FULL SCAN&#124; FOO	&#124;  3992K&#124;	&#124;  4463   (2)&#124; 00:00:54 &#124;
---------------------------------------------------------------------------------

Column Projection Information (identified by operation id):
-----------------------------------------------------------

   1 - (#keys=0) SUM(&quot;CNT&quot;)[22]
   2 - &quot;CNT&quot;[NUMBER,22]
   3 - STRDEF[22]
   4 - (#keys=0) COUNT(*)[22]
   6 - (#keys=0) COUNT(*)[22]
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>In the first query, The null really hides the fact that the data from union all operator will be passed to the parent view. There is no column information for the union all operator. Replace the null with 1, the clue will reveal.</p>
<pre class="brush: plain; title: ; notranslate">
select count(*)
from (
	select null from big_table
	union all
	select null from big_table
);

------------------------------------------------------------------------
| Id  | Operation		| Name | Rows  | Cost (%CPU)| Time     |
------------------------------------------------------------------------
|   0 | SELECT STATEMENT	|      |     1 |  8926	 (2)| 00:01:48 |
|   1 |  SORT AGGREGATE 	|      |     1 |	    |	       |
|   2 |   VIEW			|      |  7984K|  8926	 (2)| 00:01:48 |
|   3 |    UNION-ALL		|      |       |	    |	       |
|   4 |     INDEX FAST FULL SCAN| FOO  |  3992K|  4463	 (2)| 00:00:54 |
|   5 |     INDEX FAST FULL SCAN| FOO  |  3992K|  4463	 (2)| 00:00:54 |
------------------------------------------------------------------------

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

   1 - (#keys=0) COUNT(*)[22]


select count(*)
from (
	select 1 from big_table
	union all
	select 1 from big_table
);

---------------------------------------------------------------------------------
| Id  | Operation		 | Name | Rows	| Bytes | Cost (%CPU)| Time	|
---------------------------------------------------------------------------------
|   0 | SELECT STATEMENT	 |	|     1 |    13 |  8926   (2)| 00:01:48 |
|   1 |  SORT AGGREGATE 	 |	|     1 |    13 |	     |		|
|   2 |   VIEW			 |	|     2 |    26 |  8926   (2)| 00:01:48 |
|   3 |    UNION-ALL		 |	|	|	|	     |		|
|   4 |     SORT AGGREGATE	 |	|     1 |	|	     |		|
|   5 |      INDEX FAST FULL SCAN| FOO	|  3992K|	|  4463   (2)| 00:00:54 |
|   6 |     SORT AGGREGATE	 |	|     1 |	|	     |		|
|   7 |      INDEX FAST FULL SCAN| FOO	|  3992K|	|  4463   (2)| 00:00:54 |
---------------------------------------------------------------------------------

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

   1 - (#keys=0) SUM(&quot;CNT&quot;)[22]
   2 - &quot;CNT&quot;[NUMBER,22]
   3 - STRDEF[22]
   4 - (#keys=0) COUNT(*)[22]
   6 - (#keys=0) COUNT(*)[22]
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sid</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45315</link>
		<dc:creator><![CDATA[Sid]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 13:12:20 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45315</guid>
		<description><![CDATA[I was stuck around 10 mins last night, then i decided to reproduce the case. Because of the implication of count(*), i was expecting to see some clue in the &quot;Column Projection Information&quot;, but nothing. So i wonder if the null in the first query is replaced with anything else, there will be column information for the union all row source in the &quot;Column Projection Information&quot;. Anyway, will try it again later.]]></description>
		<content:encoded><![CDATA[<p>I was stuck around 10 mins last night, then i decided to reproduce the case. Because of the implication of count(*), i was expecting to see some clue in the &#8220;Column Projection Information&#8221;, but nothing. So i wonder if the null in the first query is replaced with anything else, there will be column information for the union all row source in the &#8220;Column Projection Information&#8221;. Anyway, will try it again later.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavol Babel</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45313</link>
		<dc:creator><![CDATA[Pavol Babel]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 12:30:03 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45313</guid>
		<description><![CDATA[not reproducible on 9.2.0.8 on AIX 64bit]]></description>
		<content:encoded><![CDATA[<p>not reproducible on 9.2.0.8 on AIX 64bit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanel Poder</title>
		<link>http://jonathanlewis.wordpress.com/2012/03/04/count-2/#comment-45273</link>
		<dc:creator><![CDATA[Tanel Poder]]></dc:creator>
		<pubDate>Mon, 05 Mar 2012 16:26:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8509#comment-45273</guid>
		<description><![CDATA[Yeah - and this particular query is so good example, because it doesn&#039;t have the obvious usual suspects in it, which would suffer from large rowcounts fed to them (like filter predicates, joins, sorts, aggregates), but it&#039;s pure data transfer towards the root through the execution plan tree.]]></description>
		<content:encoded><![CDATA[<p>Yeah &#8211; and this particular query is so good example, because it doesn&#8217;t have the obvious usual suspects in it, which would suffer from large rowcounts fed to them (like filter predicates, joins, sorts, aggregates), but it&#8217;s pure data transfer towards the root through the execution plan tree.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
