<?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"
	>
<channel>
	<title>Comments on: COUNT(*) vs COUNT(col)</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/</link>
	<description>Everything about MySQL Performance</description>
	<pubDate>Tue, 02 Dec 2008 12:49:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: لدى حلين لمعرفة عدد السجلات اى الحلول تنصحوتى - سوالف سوفت</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-354572</link>
		<dc:creator>لدى حلين لمعرفة عدد السجلات اى الحلول تنصحوتى - سوالف سوفت</dc:creator>
		<pubDate>Fri, 12 Sep 2008 11:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-354572</guid>
		<description>[...] هذا الموضوع بالنسبة ل count أنصح بمتابعة هذه المدونه COUNT(*) vs COUNT(col) &#124; MySQL Performance Blog    __________________ I Love PHP (d4d@hotmail.com) [...]</description>
		<content:encoded><![CDATA[<p>[...] هذا الموضوع بالنسبة ل count أنصح بمتابعة هذه المدونه COUNT(*) vs COUNT(col) | MySQL Performance Blog    __________________ I Love PHP (d4d@hotmail.com) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: howard</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-138586</link>
		<dc:creator>howard</dc:creator>
		<pubDate>Sat, 23 Jun 2007 10:33:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-138586</guid>
		<description>hello, can i say: 

the rule of thumb is...

1. use count(primary_key) 
2. use count(indexed_field_and_not_null)
3. use count(indexed_field)
4. use count(*)

how abt the length of the index, does it matter?

thanks.</description>
		<content:encoded><![CDATA[<p>hello, can i say: </p>
<p>the rule of thumb is&#8230;</p>
<p>1. use count(primary_key)<br />
2. use count(indexed_field_and_not_null)<br />
3. use count(indexed_field)<br />
4. use count(*)</p>
<p>how abt the length of the index, does it matter?</p>
<p>thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; Easy MySQL Performance Tips</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-132964</link>
		<dc:creator>&#187; Easy MySQL Performance Tips</dc:creator>
		<pubDate>Wed, 06 Jun 2007 12:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-132964</guid>
		<description>[...] Never do a COUNT(*) (or anything *, says Zach). Instead, replace the * with the name of the column you&#8217;re searching against (and is hopefully indexed). That way some queries can execute entirely in the keycache (while * forces MySQL to read every matching row from the table). [...]</description>
		<content:encoded><![CDATA[<p>[...] Never do a COUNT(*) (or anything *, says Zach). Instead, replace the * with the name of the column you&#8217;re searching against (and is hopefully indexed). That way some queries can execute entirely in the keycache (while * forces MySQL to read every matching row from the table). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-115916</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 30 Apr 2007 02:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-115916</guid>
		<description>Pavel,

For primary key it should be the same as primary key can't have null values.
It is same as count(val2) in my example.</description>
		<content:encoded><![CDATA[<p>Pavel,</p>
<p>For primary key it should be the same as primary key can&#8217;t have null values.<br />
It is same as count(val2) in my example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-115405</link>
		<dc:creator>Pavel</dc:creator>
		<pubDate>Sat, 28 Apr 2007 23:02:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-115405</guid>
		<description>What about count(id) (id is primary key)?
Is count(id) slower than count(*)?

Using innodb + where and myisam + where;</description>
		<content:encoded><![CDATA[<p>What about count(id) (id is primary key)?<br />
Is count(id) slower than count(*)?</p>
<p>Using innodb + where and myisam + where;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-114472</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 26 Apr 2007 16:34:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-114472</guid>
		<description>Raj,

Good point. It looks like a bug to me as Innodb automatically picks up "shorter" indexes while in practice even first index you tried is shorter. 

The other interesting point I should note - smaller index may not be faster for huge tables, because if you insert data in order primary key tree is often sequential while secondary indexes may be scattered having few sequential pages.</description>
		<content:encoded><![CDATA[<p>Raj,</p>
<p>Good point. It looks like a bug to me as Innodb automatically picks up &#8220;shorter&#8221; indexes while in practice even first index you tried is shorter. </p>
<p>The other interesting point I should note - smaller index may not be faster for huge tables, because if you insert data in order primary key tree is often sequential while secondary indexes may be scattered having few sequential pages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raj</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-114163</link>
		<dc:creator>Raj</dc:creator>
		<pubDate>Thu, 26 Apr 2007 01:22:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-114163</guid>
		<description>Just saw this thread and started wondering about how the fact that innodb uses clustered indexes would play into the equation.  I find that, with a judicious choice of (col), count(col) may actually be a lot faster than count(*).

Consider this example (restarting mysql each time to flush the cache, and using O_DIRECT to bypass OS caching)

mysql&#62; explain select count(*) from wp_comments;
+----+-------------+-------------+-------+---------------+---------+---------+------+--------+-------------+
&#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; wp_comments &#124; index &#124; NULL          &#124; PRIMARY &#124; 8       &#124; NULL &#124; 424672 &#124; Using index &#124; 
+----+-------------+-------------+-------+---------------+---------+---------+------+--------+-------------+
1 row in set (0.11 sec)

mysql&#62;  explain select count(rajid) from wp_comments;
+----+-------------+-------------+-------+---------------+--------+---------+------+--------+-------------+
&#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; wp_comments &#124; index &#124; NULL          &#124; rajidx &#124; 9       &#124; NULL &#124; 424672 &#124; Using index &#124; 
+----+-------------+-------------+-------+---------------+--------+---------+------+--------+-------------+
1 row in set (0.00 sec)


mysql&#62; select count(*) from wp_comments;
+----------+
&#124; count(*) &#124;
+----------+
&#124;   230120 &#124; 
+----------+
1 row in set (32.57 sec)

and if you look at the buffer pool used for the count(*):

Total memory allocated 589194920; in additional pool allocated 714496
Buffer pool size   32768
Free buffers       14104
Database pages     18664
Modified db pages  0


restart mysql and check the count of (rajid):

mysql&#62; select count(rajid) from wp_comments;
+--------------+
&#124; count(rajid) &#124;
+--------------+
&#124;       230120 &#124; 
+--------------+
1 row in set (0.28 sec)

Much faster.  Why?  Because it only reads the index data, not the row data for the table when you use a secondary index.  Check the buffer pool usage:

Total memory allocated 589194920; in additional pool allocated 714496
Buffer pool size   32768
Free buffers       32332
Database pages     436
Modified db pages  0

The column rajid btw, is just a copy of the PK column comment_ID with a unique index:

mysql&#62; show create table wp_comments\G
*************************** 1. row ***************************
       Table: wp_comments
Create Table: CREATE TABLE `wp_comments` (
  `comment_ID` bigint(20) unsigned NOT NULL auto_increment,
  `comment_post_ID` int(11) NOT NULL default '0',
  `comment_author` tinytext NOT NULL,
  `comment_author_email` varchar(100) NOT NULL default '',
  `comment_author_url` varchar(200) NOT NULL default '',
  `comment_author_IP` varchar(100) NOT NULL default '',
  `comment_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `comment_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
  `comment_content` text NOT NULL,
  `comment_karma` int(11) NOT NULL default '0',
  `comment_approved` enum('0','1','spam') NOT NULL default '1',
  `comment_agent` varchar(255) NOT NULL default '',
  `comment_type` varchar(20) NOT NULL default '',
  `comment_parent` bigint(20) NOT NULL default '0',
  `user_id` bigint(20) NOT NULL default '0',
  `rajid` bigint(20) unsigned default NULL,
  PRIMARY KEY  (`comment_ID`),
  UNIQUE KEY `rajidx` (`rajid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql&#62; 

btw, if there is a smaller secondary index on the table, innodb is smart enough to use that for a count, even if it is not a unique index.  For instance:
mysql&#62; explain select count(*) from wp_comments;
+----+-------------+-------------+-------+---------------+----------------------+---------+------+--------+-------------+
&#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; wp_comments &#124; index &#124; NULL          &#124; comment_approved_idx &#124; 1       &#124; NULL &#124; 228484 &#124; Using index &#124; 
+----+-------------+-------------+-------+---------------+----------------------+---------+------+--------+-------------+
1 row in set (0.23 sec)

mysql&#62; select count(*) from wp_comments;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    2
Current database: test

+----------+
&#124; count(*) &#124;
+----------+
&#124;   230120 &#124; 
+----------+
1 row in set (1.19 sec)

mysql&#62; 
and the buffer pool usage:

Total memory allocated 589194920; in additional pool allocated 721920
Buffer pool size   32768
Free buffers       32449
Database pages     319
Modified db pages  0

there's only 3 distinct values in the table for this column, so its not actually counting the values but the pointers from this index:
mysql&#62; select count( distinct (comment_approved) ) from wp_comments;
+--------------------------------------+
&#124; count( distinct (comment_approved) ) &#124;
+--------------------------------------+
&#124;                                    3 &#124; 
+--------------------------------------+
1 row in set (0.32 sec)

mysql&#62; 


cheers!
--Raj.</description>
		<content:encoded><![CDATA[<p>Just saw this thread and started wondering about how the fact that innodb uses clustered indexes would play into the equation.  I find that, with a judicious choice of (col), count(col) may actually be a lot faster than count(*).</p>
<p>Consider this example (restarting mysql each time to flush the cache, and using O_DIRECT to bypass OS caching)</p>
<p>mysql&gt; explain select count(*) from wp_comments;<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;&#8211;+&#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;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br />
|  1 | SIMPLE      | wp_comments | index | NULL          | PRIMARY | 8       | NULL | 424672 | Using index |<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;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.11 sec)</p>
<p>mysql&gt;  explain select count(rajid) from wp_comments;<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8211;+&#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;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br />
|  1 | SIMPLE      | wp_comments | index | NULL          | rajidx | 9       | NULL | 424672 | Using index |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.00 sec)</p>
<p>mysql&gt; select count(*) from wp_comments;<br />
+&#8212;&#8212;&#8212;-+<br />
| count(*) |<br />
+&#8212;&#8212;&#8212;-+<br />
|   230120 |<br />
+&#8212;&#8212;&#8212;-+<br />
1 row in set (32.57 sec)</p>
<p>and if you look at the buffer pool used for the count(*):</p>
<p>Total memory allocated 589194920; in additional pool allocated 714496<br />
Buffer pool size   32768<br />
Free buffers       14104<br />
Database pages     18664<br />
Modified db pages  0</p>
<p>restart mysql and check the count of (rajid):</p>
<p>mysql&gt; select count(rajid) from wp_comments;<br />
+&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| count(rajid) |<br />
+&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
|       230120 |<br />
+&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
1 row in set (0.28 sec)</p>
<p>Much faster.  Why?  Because it only reads the index data, not the row data for the table when you use a secondary index.  Check the buffer pool usage:</p>
<p>Total memory allocated 589194920; in additional pool allocated 714496<br />
Buffer pool size   32768<br />
Free buffers       32332<br />
Database pages     436<br />
Modified db pages  0</p>
<p>The column rajid btw, is just a copy of the PK column comment_ID with a unique index:</p>
<p>mysql&gt; show create table wp_comments\G<br />
*************************** 1. row ***************************<br />
       Table: wp_comments<br />
Create Table: CREATE TABLE `wp_comments` (<br />
  `comment_ID` bigint(20) unsigned NOT NULL auto_increment,<br />
  `comment_post_ID` int(11) NOT NULL default &#8216;0&#8242;,<br />
  `comment_author` tinytext NOT NULL,<br />
  `comment_author_email` varchar(100) NOT NULL default &#8221;,<br />
  `comment_author_url` varchar(200) NOT NULL default &#8221;,<br />
  `comment_author_IP` varchar(100) NOT NULL default &#8221;,<br />
  `comment_date` datetime NOT NULL default &#8216;0000-00-00 00:00:00&#8242;,<br />
  `comment_date_gmt` datetime NOT NULL default &#8216;0000-00-00 00:00:00&#8242;,<br />
  `comment_content` text NOT NULL,<br />
  `comment_karma` int(11) NOT NULL default &#8216;0&#8242;,<br />
  `comment_approved` enum(&#8217;0&#8242;,&#8217;1&#8242;,&#8217;spam&#8217;) NOT NULL default &#8216;1&#8242;,<br />
  `comment_agent` varchar(255) NOT NULL default &#8221;,<br />
  `comment_type` varchar(20) NOT NULL default &#8221;,<br />
  `comment_parent` bigint(20) NOT NULL default &#8216;0&#8242;,<br />
  `user_id` bigint(20) NOT NULL default &#8216;0&#8242;,<br />
  `rajid` bigint(20) unsigned default NULL,<br />
  PRIMARY KEY  (`comment_ID`),<br />
  UNIQUE KEY `rajidx` (`rajid`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1<br />
1 row in set (0.00 sec)</p>
<p>mysql&gt; </p>
<p>btw, if there is a smaller secondary index on the table, innodb is smart enough to use that for a count, even if it is not a unique index.  For instance:<br />
mysql&gt; explain select count(*) from wp_comments;<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;&#8211;+&#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;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br />
|  1 | SIMPLE      | wp_comments | index | NULL          | comment_approved_idx | 1       | NULL | 228484 | Using index |<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;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.23 sec)</p>
<p>mysql&gt; select count(*) from wp_comments;<br />
ERROR 2006 (HY000): MySQL server has gone away<br />
No connection. Trying to reconnect&#8230;<br />
Connection id:    2<br />
Current database: test</p>
<p>+&#8212;&#8212;&#8212;-+<br />
| count(*) |<br />
+&#8212;&#8212;&#8212;-+<br />
|   230120 |<br />
+&#8212;&#8212;&#8212;-+<br />
1 row in set (1.19 sec)</p>
<p>mysql&gt;<br />
and the buffer pool usage:</p>
<p>Total memory allocated 589194920; in additional pool allocated 721920<br />
Buffer pool size   32768<br />
Free buffers       32449<br />
Database pages     319<br />
Modified db pages  0</p>
<p>there&#8217;s only 3 distinct values in the table for this column, so its not actually counting the values but the pointers from this index:<br />
mysql&gt; select count( distinct (comment_approved) ) from wp_comments;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| count( distinct (comment_approved) ) |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
|                                    3 |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
1 row in set (0.32 sec)</p>
<p>mysql&gt; </p>
<p>cheers!<br />
&#8211;Raj.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vadim Voituk</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-113388</link>
		<dc:creator>Vadim Voituk</dc:creator>
		<pubDate>Tue, 24 Apr 2007 11:33:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-113388</guid>
		<description>There is a post with similar problem but in russian
http://voituk.kiev.ua/2006/07/27/mysql-right-count-statement/</description>
		<content:encoded><![CDATA[<p>There is a post with similar problem but in russian<br />
<a href="http://voituk.kiev.ua/2006/07/27/mysql-right-count-statement/" rel="nofollow">http://voituk.kiev.ua/2006/07/27/mysql-right-count-statement/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: klaus</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-111081</link>
		<dc:creator>klaus</dc:creator>
		<pubDate>Fri, 20 Apr 2007 03:29:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-111081</guid>
		<description>count(*) is similar to count(0) as you cas se here:

mysql&#62; explain extended select count(*) from mytable;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
&#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&#62; show warnings;
+-------+------+---------------------------------------------------------+
&#124; Level &#124; Code &#124; Message                                                 &#124;
+-------+------+---------------------------------------------------------+
&#124; Note  &#124; 1003 &#124; select count(0) AS `count(*)` from `database`.`mytable` &#124;
+-------+------+---------------------------------------------------------+
1 row in set (0.00 sec)

count(1) is similar to count(1) as you can se here:

mysql&#62; explain extended select count(1) from mytable;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
&#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&#62; show warnings;
+-------+------+---------------------------------------------------------+
&#124; Level &#124; Code &#124; Message                                                 &#124;
+-------+------+---------------------------------------------------------+
&#124; Note  &#124; 1003 &#124; select count(1) AS `count(1)` from `database`.`mytable` &#124;
+-------+------+---------------------------------------------------------+
1 row in set (0.00 sec)

So in conclusion count(*) == count(0) and count(*) != count(1)

Hope it helps.</description>
		<content:encoded><![CDATA[<p>count(*) is similar to count(0) as you cas se here:</p>
<p>mysql&gt; explain extended select count(*) from mytable;<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;&#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;&#8212;&#8212;&#8212;+<br />
| Note  | 1003 | select count(0) AS `count(*)` from `database`.`mytable` |<br />
+&#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 (0.00 sec)</p>
<p>count(1) is similar to count(1) as you can se here:</p>
<p>mysql&gt; explain extended select count(1) from mytable;<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;&#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;&#8212;&#8212;&#8212;+<br />
| Note  | 1003 | select count(1) AS `count(1)` from `database`.`mytable` |<br />
+&#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 (0.00 sec)</p>
<p>So in conclusion count(*) == count(0) and count(*) != count(1)</p>
<p>Hope it helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PHP Performance &#187; COUNT(*) gegen COUNT(spalte)</title>
		<link>http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-108858</link>
		<dc:creator>PHP Performance &#187; COUNT(*) gegen COUNT(spalte)</dc:creator>
		<pubDate>Sun, 15 Apr 2007 18:38:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/#comment-108858</guid>
		<description>[...] Als Argument nimmt diese Funktion entweder ein &#8216;*&#8217; oder eine bestimmte Spalte. Im MySQL Performance Blog wird verglichen, ob man dabei COUNT(*) oder COUNT(spalte) verwenden [...]</description>
		<content:encoded><![CDATA[<p>[...] Als Argument nimmt diese Funktion entweder ein &#8216;*&#8217; oder eine bestimmte Spalte. Im MySQL Performance Blog wird verglichen, ob man dabei COUNT(*) oder COUNT(spalte) verwenden [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
