<?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:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Different ways to count</title>
	<atom:link href="http://awads.net/wp/2005/08/24/different-ways-to-count/feed/" rel="self" type="application/rss+xml" />
	<link>http://awads.net/wp/2005/08/24/different-ways-to-count/</link>
	<description>News, views, tips and tricks on Oracle and other fun stuff</description>
	<lastBuildDate>Tue, 24 Jan 2012 20:49:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2005/08/24/different-ways-to-count/comment-page-1/#comment-152</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Fri, 09 Sep 2005 00:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=99#comment-152</guid>
		<description>&lt;p&gt;Thanks for the tip John. It&#039;s always good to have many alternatives to accomplish the same thing, so one can choose what best suits the need.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for the tip John. It&#8217;s always good to have many alternatives to accomplish the same thing, so one can choose what best suits the need.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: John Wimmer</title>
		<link>http://awads.net/wp/2005/08/24/different-ways-to-count/comment-page-1/#comment-149</link>
		<dc:creator>John Wimmer</dc:creator>
		<pubDate>Thu, 08 Sep 2005 19:45:58 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=99#comment-149</guid>
		<description>&lt;p&gt;If you take periodic exports, you can look at the export log and tell how many rows were exported.  Depending on how big your output file is, it might be qquicker, plus is uses no database resources to find the number.  Like the analyze number, it is dated, though.  Handy of you don&#039;t have good stats, but a current export.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If you take periodic exports, you can look at the export log and tell how many rows were exported.  Depending on how big your output file is, it might be qquicker, plus is uses no database resources to find the number.  Like the analyze number, it is dated, though.  Handy of you don&#8217;t have good stats, but a current export.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2005/08/24/different-ways-to-count/comment-page-1/#comment-131</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Tue, 30 Aug 2005 19:19:37 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=99#comment-131</guid>
		<description>&lt;p&gt;Hi Stu,&lt;/p&gt;

&lt;p&gt;&gt;as youâ€™ve mentioned selecting MAX(ROWNUM) from user_tables is the fastest method of counting rows&lt;/p&gt;

&lt;p&gt;I think you meant &quot;selecting &lt;code&gt;num_rows&lt;/code&gt; from &lt;code&gt;user_tables&lt;/code&gt;&quot;.&lt;/p&gt;

&lt;p&gt;&gt;I believe that a COUNT(rowid) will run a little faster than a &lt;code&gt;COUNT(*)&lt;/code&gt;&lt;br /&gt;
&gt;a COUNT of the indexed column will be quicker than a &lt;code&gt;COUNT(rowid)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For more discussions and links about which form of &lt;code&gt;count&lt;/code&gt; is faster, check &lt;a href=&quot;http://awads.net/wp/2005/07/06/count-vs-count1/&quot;&gt;my previous post&lt;/a&gt; about this subject.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Stu,</p>

<p>&gt;as youâ€™ve mentioned selecting MAX(ROWNUM) from user_tables is the fastest method of counting rows</p>

<p>I think you meant &#8220;selecting <code>num_rows</code> from <code>user_tables</code>&#8220;.</p>

<p>&gt;I believe that a COUNT(rowid) will run a little faster than a <code>COUNT(*)</code><br />
&gt;a COUNT of the indexed column will be quicker than a <code>COUNT(rowid)</code></p>

<p>For more discussions and links about which form of <code>count</code> is faster, check <a href="http://awads.net/wp/2005/07/06/count-vs-count1/">my previous post</a> about this subject.</p>

<p>Thanks.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Stu Lindenmayer</title>
		<link>http://awads.net/wp/2005/08/24/different-ways-to-count/comment-page-1/#comment-129</link>
		<dc:creator>Stu Lindenmayer</dc:creator>
		<pubDate>Tue, 30 Aug 2005 05:53:51 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=99#comment-129</guid>
		<description>&lt;p&gt;Hi Eddie,
as you&#039;ve mentioned selecting MAX(ROWNUM) from user&#095;tables is the fastest method of counting rows. Although I&#039;d advise that users should also select the LAST&#095;ANALYSED column:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;select num_rows, 
to_char(last_analyzed, &#039;DD-MON-YYYY HH24:MI&#039;) as valid_at 
from dba_tables where table_name=&#039;EMP&#039;;

  NUM_ROWS VALID_AT
---------- -----------------
        14 30-AUG-2005 15:11
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will provide the user with an idea of how old the row count acutally is.&lt;/p&gt;

&lt;p&gt;Additionally, I believe that a COUNT(rowid) will run a little faster than a &lt;code&gt;COUNT(*)&lt;/code&gt; as validation of all rows is performed by Oracle for &lt;code&gt;COUNT(*)&lt;/code&gt; operation.&lt;/p&gt;

&lt;p&gt;Also if an index exists on the table being counted, a COUNT of the indexed column will be quicker than a COUNT(rowid). For example, with an index on the emp table ename column:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;practice:SYS&gt;explain plan for select count(rowid) from scott.emp;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Explained.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;practice:SYS&gt;@xpls

Plan Table
-----------------------------------------------------------------------------------------
&#124; Operation                           &#124;  Name                   &#124;  Rows &#124; Bytes&#124;  Cost  &#124;
-----------------------------------------------------------------------------------------
&#124; SELECT STATEMENT                    &#124;                         &#124;     1 &#124;    7 &#124;      2 &#124;
&#124;  SORT AGGREGATE                     &#124;                         &#124;     1 &#124;    7 &#124;        &#124;
&#124;   TABLE ACCESS FULL                 &#124;EMP                      &#124;    14 &#124;   98 &#124;      2 &#124; 
-----------------------------------------------------------------------------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;whereas hitting only the index column provides a faster count via a full index scan:&lt;/p&gt;

&lt;p&gt;explain plan for select count(ename) from scott.emp;&lt;/p&gt;

&lt;p&gt;Explained.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;practice:SYS&gt;@xpls

Plan Table
-----------------------------------------------------------------------------------------
&#124; Operation                           &#124;  Name                   &#124;  Rows &#124; Bytes&#124;  Cost  &#124;
-----------------------------------------------------------------------------------------
&#124; SELECT STATEMENT                    &#124;                         &#124;     1 &#124;    6 &#124;      1 &#124;
&#124;  SORT AGGREGATE                     &#124;                         &#124;     1 &#124;    6 &#124;        &#124;
&#124;   INDEX FULL SCAN                   &#124;EMP_IDX                  &#124;    14 &#124;   84 &#124;      1 &#124;
-----------------------------------------------------------------------------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cheers!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Eddie,
as you&#8217;ve mentioned selecting MAX(ROWNUM) from user&#95;tables is the fastest method of counting rows. Although I&#8217;d advise that users should also select the LAST&#95;ANALYSED column:</p>

<pre><code>select num_rows, 
to_char(last_analyzed, 'DD-MON-YYYY HH24:MI') as valid_at 
from dba_tables where table_name='EMP';

  NUM_ROWS VALID_AT
---------- -----------------
        14 30-AUG-2005 15:11
</code></pre>

<p>This will provide the user with an idea of how old the row count acutally is.</p>

<p>Additionally, I believe that a COUNT(rowid) will run a little faster than a <code>COUNT(*)</code> as validation of all rows is performed by Oracle for <code>COUNT(*)</code> operation.</p>

<p>Also if an index exists on the table being counted, a COUNT of the indexed column will be quicker than a COUNT(rowid). For example, with an index on the emp table ename column:</p>

<pre><code>practice:SYS&gt;explain plan for select count(rowid) from scott.emp;
</code></pre>

<p>Explained.</p>

<pre><code>practice:SYS&gt;@xpls

Plan Table
-----------------------------------------------------------------------------------------
| Operation                           |  Name                   |  Rows | Bytes|  Cost  |
-----------------------------------------------------------------------------------------
| SELECT STATEMENT                    |                         |     1 |    7 |      2 |
|  SORT AGGREGATE                     |                         |     1 |    7 |        |
|   TABLE ACCESS FULL                 |EMP                      |    14 |   98 |      2 | 
-----------------------------------------------------------------------------------------
</code></pre>

<p>whereas hitting only the index column provides a faster count via a full index scan:</p>

<p>explain plan for select count(ename) from scott.emp;</p>

<p>Explained.</p>

<pre><code>practice:SYS&gt;@xpls

Plan Table
-----------------------------------------------------------------------------------------
| Operation                           |  Name                   |  Rows | Bytes|  Cost  |
-----------------------------------------------------------------------------------------
| SELECT STATEMENT                    |                         |     1 |    6 |      1 |
|  SORT AGGREGATE                     |                         |     1 |    6 |        |
|   INDEX FULL SCAN                   |EMP_IDX                  |    14 |   84 |      1 |
-----------------------------------------------------------------------------------------
</code></pre>

<p>Cheers!</p>]]></content:encoded>
	</item>
</channel>
</rss>

