<?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/"
		>
<channel>
	<title>Comments on: count(1) vs count(*) &#8211; any difference?</title>
	<atom:link href="http://www.rustyrazorblade.com/2007/01/count1-vs-count-any-difference/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rustyrazorblade.com/2007/01/count1-vs-count-any-difference/</link>
	<description>Tech Thoughts, Mostly on LAMP - by Jon Haddad</description>
	<lastBuildDate>Fri, 03 Sep 2010 03:50:22 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jay Pipes</title>
		<link>http://www.rustyrazorblade.com/2007/01/count1-vs-count-any-difference/comment-page-1/#comment-3682</link>
		<dc:creator>Jay Pipes</dc:creator>
		<pubDate>Thu, 25 Jan 2007 03:35:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.rustyrazorblade.com/index.php/2007/01/19/count1-vs-count-any-difference/#comment-3682</guid>
		<description>Hi!

They are identical in MSSQL as well.  There is, however, a big difference in T-SQL/MSSQL between the performance of EXISTS() and SELECT COUNT(*) to determine existence...

Cheers,

Jay</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>They are identical in MSSQL as well.  There is, however, a big difference in T-SQL/MSSQL between the performance of EXISTS() and SELECT COUNT(*) to determine existence&#8230;</p>
<p>Cheers,</p>
<p>Jay</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Philip Stoev</title>
		<link>http://www.rustyrazorblade.com/2007/01/count1-vs-count-any-difference/comment-page-1/#comment-3633</link>
		<dc:creator>Philip Stoev</dc:creator>
		<pubDate>Sun, 21 Jan 2007 15:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.rustyrazorblade.com/index.php/2007/01/19/count1-vs-count-any-difference/#comment-3633</guid>
		<description>COUNT(*) is converted to COUNT(1) within the parser, therefore very early in the query execution sequence.</description>
		<content:encoded><![CDATA[<p>COUNT(*) is converted to COUNT(1) within the parser, therefore very early in the query execution sequence.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Burton</title>
		<link>http://www.rustyrazorblade.com/2007/01/count1-vs-count-any-difference/comment-page-1/#comment-3620</link>
		<dc:creator>Kevin Burton</dc:creator>
		<pubDate>Sat, 20 Jan 2007 06:05:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.rustyrazorblade.com/index.php/2007/01/19/count1-vs-count-any-difference/#comment-3620</guid>
		<description>Also, on MyISAM an internal row count is maintained which is used for COUNT......</description>
		<content:encoded><![CDATA[<p>Also, on MyISAM an internal row count is maintained which is used for COUNT&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed</title>
		<link>http://www.rustyrazorblade.com/2007/01/count1-vs-count-any-difference/comment-page-1/#comment-3608</link>
		<dc:creator>Ed</dc:creator>
		<pubDate>Fri, 19 Jan 2007 16:25:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.rustyrazorblade.com/index.php/2007/01/19/count1-vs-count-any-difference/#comment-3608</guid>
		<description>They are treated essentially the same.   You can see below that mysql internally rewrites count(*) to count(0).

mysql&gt; explain extended select count(*) from foo;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
&#124; id &#124; select_type &#124; table &#124; type &#124; possible_keys &#124; key  &#124; key_len &#124; ref  &#124; rows &#124; Extra                        &#124;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
&#124;  1 &#124; SIMPLE      &#124; NULL  &#124; NULL &#124; NULL          &#124; NULL &#124; NULL    &#124; NULL &#124; NULL &#124; Select tables optimized away &#124; 
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set, 1 warning (0.03 sec)

mysql&gt; show warnings;                            
+-------+------+-------------------------------------------------+
&#124; Level &#124; Code &#124; Message                                         &#124;
+-------+------+-------------------------------------------------+
&#124; Note  &#124; 1003 &#124; select count(0) AS `count(*)` from `test`.`foo` &#124; 
+-------+------+-------------------------------------------------+
1 row in set (0.00 sec)

mysql&gt; explain extended select count(1) from foo;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
&#124; id &#124; select_type &#124; table &#124; type &#124; possible_keys &#124; key  &#124; key_len &#124; ref  &#124; rows &#124; Extra                        &#124;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
&#124;  1 &#124; SIMPLE      &#124; NULL  &#124; NULL &#124; NULL          &#124; NULL &#124; NULL    &#124; NULL &#124; NULL &#124; Select tables optimized away &#124; 
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql&gt; show warnings;
+-------+------+-------------------------------------------------+
&#124; Level &#124; Code &#124; Message                                         &#124;
+-------+------+-------------------------------------------------+
&#124; Note  &#124; 1003 &#124; select count(1) AS `count(1)` from `test`.`foo` &#124; 
+-------+------+-------------------------------------------------+
1 row in set (0.00 sec)</description>
		<content:encoded><![CDATA[<p>They are treated essentially the same.   You can see below that mysql internally rewrites count(*) to count(0).</p>
<p>mysql&gt; explain extended select count(*) from foo;<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set, 1 warning (0.03 sec)</p>
<p>mysql&gt; show warnings;<br />
+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Level | Code | Message                                         |<br />
+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Note  | 1003 | select count(0) AS `count(*)` from `test`.`foo` |<br />
+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.00 sec)</p>
<p>mysql&gt; explain extended select count(1) from foo;<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set, 1 warning (0.00 sec)</p>
<p>mysql&gt; show warnings;<br />
+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Level | Code | Message                                         |<br />
+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Note  | 1003 | select count(1) AS `count(1)` from `test`.`foo` |<br />
+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.00 sec)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
