<?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(*) for Innodb Tables</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: SELECT COUNT(*) sehr langsam - php.de</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-649812</link>
		<dc:creator>SELECT COUNT(*) sehr langsam - php.de</dc:creator>
		<pubDate>Tue, 08 Sep 2009 15:47:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-649812</guid>
		<description>[...] Zählen für MySQL kein Problem ist. Selbst bei 8 Mio. Zeilen.    übliches work-around sind trigger bei INSERT/DELETE mit einer zusätzlichen tabelle.    __________________ AC/DC Fanpage ifyouwantblood.de (Stewie [...]</description>
		<content:encoded><![CDATA[<p>[...] Zählen für MySQL kein Problem ist. Selbst bei 8 Mio. Zeilen.    übliches work-around sind trigger bei INSERT/DELETE mit einer zusätzlichen tabelle.    __________________ AC/DC Fanpage ifyouwantblood.de (Stewie [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-639898</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 26 Aug 2009 16:16:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-639898</guid>
		<description>SC,

Note these stats are approximate.</description>
		<content:encoded><![CDATA[<p>SC,</p>
<p>Note these stats are approximate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SC</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-639851</link>
		<dc:creator>SC</dc:creator>
		<pubDate>Wed, 26 Aug 2009 15:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-639851</guid>
		<description>If your table has a primary key, you can also get the count from 
show index from , the cardinality of the key will give you count of the rows in the table.</description>
		<content:encoded><![CDATA[<p>If your table has a primary key, you can also get the count from<br />
show index from , the cardinality of the key will give you count of the rows in the table.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cloudspace - A Cool Little Company's Thoughts, News, Happenings</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-625217</link>
		<dc:creator>Cloudspace - A Cool Little Company's Thoughts, News, Happenings</dc:creator>
		<pubDate>Thu, 06 Aug 2009 14:57:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-625217</guid>
		<description>[...] never contain a NULL value, and tell MySQL to &#8216;use index (index_name)&#8217;. Also, thanks to Wallace, who commented on the MySQL Performance Blog      Share and [...]</description>
		<content:encoded><![CDATA[<p>[...] never contain a NULL value, and tell MySQL to &#8216;use index (index_name)&#8217;. Also, thanks to Wallace, who commented on the MySQL Performance Blog      Share and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wallace</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-529049</link>
		<dc:creator>Wallace</dc:creator>
		<pubDate>Fri, 03 Apr 2009 11:40:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-529049</guid>
		<description>Why the performance gap?

Running this slow query took 138 seconds (2 min 18.09 sec)
SELECT COUNT(*) FROM dbmail_messageblks;
+----------+
&#124; COUNT(*) &#124;
+----------+
&#124;   262788 &#124;
+----------+
1 row in set (2 min 18.09 sec)

After optimizing the SQL, it took 0.27 seconds.
SELECT COUNT(*) FROM dbmail_messageblks use index(physmessage_id_index);
+----------+
&#124; COUNT(*) &#124;
+----------+
&#124;   262796 &#124;
+----------+
1 row in set (0.27 sec)

&gt; SHOW CREATE TABLE dbmail_messageblks\G
*************************** 1. row ***************************
        Table: dbmail_messageblks
Create Table: CREATE TABLE `dbmail_messageblks` (
   `messageblk_idnr` bigint(21) NOT NULL auto_increment,
   `physmessage_id` bigint(21) NOT NULL default &#039;0&#039;,
   `messageblk` longblob NOT NULL,
   `blocksize` bigint(21) NOT NULL default &#039;0&#039;,
   `is_header` tinyint(1) NOT NULL default &#039;0&#039;,
   PRIMARY KEY  (`messageblk_idnr`),
   KEY `physmessage_id_index` (`physmessage_id`),
   KEY `physmessage_id_is_header_index` (`physmessage_id`,`is_header`),
   CONSTRAINT `dbmail_messageblks_ibfk_1` FOREIGN KEY (`physmessage_id`) REFERENCES `dbmail_physmessage` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=602519 DEFAULT CHARSET=utf8

&gt; EXPLAIN SELECT COUNT(*) FROM dbmail_messageblks\G
*************************** 1. row ***************************
            id: 1
   select_type: SIMPLE
         table: dbmail_messageblks
          type: index
possible_keys: NULL
           key: PRIMARY
       key_len: 8
           ref: NULL
          rows: 1930308
         Extra: Using index

&gt; EXPLAIN SELECT COUNT(*) FROM dbmail_messageblks use index(physmessage_id_index)\G
*************************** 1. row ***************************
            id: 1
   select_type: SIMPLE
         table: dbmail_messageblks
          type: index
possible_keys: NULL
           key: physmessage_id_index
       key_len: 8
           ref: NULL
          rows: 1930310
         Extra: Using index</description>
		<content:encoded><![CDATA[<p>Why the performance gap?</p>
<p>Running this slow query took 138 seconds (2 min 18.09 sec)<br />
SELECT COUNT(*) FROM dbmail_messageblks;<br />
+&#8212;&#8212;&#8212;-+<br />
| COUNT(*) |<br />
+&#8212;&#8212;&#8212;-+<br />
|   262788 |<br />
+&#8212;&#8212;&#8212;-+<br />
1 row in set (2 min 18.09 sec)</p>
<p>After optimizing the SQL, it took 0.27 seconds.<br />
SELECT COUNT(*) FROM dbmail_messageblks use index(physmessage_id_index);<br />
+&#8212;&#8212;&#8212;-+<br />
| COUNT(*) |<br />
+&#8212;&#8212;&#8212;-+<br />
|   262796 |<br />
+&#8212;&#8212;&#8212;-+<br />
1 row in set (0.27 sec)</p>
<p>&gt; SHOW CREATE TABLE dbmail_messageblks\G<br />
*************************** 1. row ***************************<br />
        Table: dbmail_messageblks<br />
Create Table: CREATE TABLE `dbmail_messageblks` (<br />
   `messageblk_idnr` bigint(21) NOT NULL auto_increment,<br />
   `physmessage_id` bigint(21) NOT NULL default &#8216;0&#8242;,<br />
   `messageblk` longblob NOT NULL,<br />
   `blocksize` bigint(21) NOT NULL default &#8216;0&#8242;,<br />
   `is_header` tinyint(1) NOT NULL default &#8216;0&#8242;,<br />
   PRIMARY KEY  (`messageblk_idnr`),<br />
   KEY `physmessage_id_index` (`physmessage_id`),<br />
   KEY `physmessage_id_is_header_index` (`physmessage_id`,`is_header`),<br />
   CONSTRAINT `dbmail_messageblks_ibfk_1` FOREIGN KEY (`physmessage_id`) REFERENCES `dbmail_physmessage` (`id`) ON DELETE CASCADE ON UPDATE CASCADE<br />
) ENGINE=InnoDB AUTO_INCREMENT=602519 DEFAULT CHARSET=utf8</p>
<p>&gt; EXPLAIN SELECT COUNT(*) FROM dbmail_messageblks\G<br />
*************************** 1. row ***************************<br />
            id: 1<br />
   select_type: SIMPLE<br />
         table: dbmail_messageblks<br />
          type: index<br />
possible_keys: NULL<br />
           key: PRIMARY<br />
       key_len: 8<br />
           ref: NULL<br />
          rows: 1930308<br />
         Extra: Using index</p>
<p>&gt; EXPLAIN SELECT COUNT(*) FROM dbmail_messageblks use index(physmessage_id_index)\G<br />
*************************** 1. row ***************************<br />
            id: 1<br />
   select_type: SIMPLE<br />
         table: dbmail_messageblks<br />
          type: index<br />
possible_keys: NULL<br />
           key: physmessage_id_index<br />
       key_len: 8<br />
           ref: NULL<br />
          rows: 1930310<br />
         Extra: Using index</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nop</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-479705</link>
		<dc:creator>nop</dc:creator>
		<pubDate>Tue, 17 Feb 2009 01:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-479705</guid>
		<description>correction: replace &quot;8 seconds&quot; with &quot;5 minutes, 8 seconds&quot;.</description>
		<content:encoded><![CDATA[<p>correction: replace &#8220;8 seconds&#8221; with &#8220;5 minutes, 8 seconds&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nop</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-479697</link>
		<dc:creator>nop</dc:creator>
		<pubDate>Tue, 17 Feb 2009 01:18:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-479697</guid>
		<description>ready for a headache? try &quot;select count($field) from $table;&quot; and compare the time it takes to &quot;select count($field) from $table use index($field);&quot; 
($field is the primary key (int autoincrement) in $table which was converted from myisam and has around 900k rows in it).

for me, the standard count without use index takes around 8 seconds - the count with forced index takes below 0.1 seconds.

any thoughts on why this is so?</description>
		<content:encoded><![CDATA[<p>ready for a headache? try &#8220;select count($field) from $table;&#8221; and compare the time it takes to &#8220;select count($field) from $table use index($field);&#8221;<br />
($field is the primary key (int autoincrement) in $table which was converted from myisam and has around 900k rows in it).</p>
<p>for me, the standard count without use index takes around 8 seconds &#8211; the count with forced index takes below 0.1 seconds.</p>
<p>any thoughts on why this is so?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fekke</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-419585</link>
		<dc:creator>Fekke</dc:creator>
		<pubDate>Sun, 21 Dec 2008 05:26:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-419585</guid>
		<description>3,000 records may be a problem. If you have three tables with 1,000 records each and you do a join involving the three tables with no indexes at all then you would have 1,000,000,000 records full scan to fetch the results.

So the optimization you acquire by creating the proper indexes not only relies on how many records your tables have but also what your queries are.</description>
		<content:encoded><![CDATA[<p>3,000 records may be a problem. If you have three tables with 1,000 records each and you do a join involving the three tables with no indexes at all then you would have 1,000,000,000 records full scan to fetch the results.</p>
<p>So the optimization you acquire by creating the proper indexes not only relies on how many records your tables have but also what your queries are.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-331977</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 20 Jul 2008 16:04:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-331977</guid>
		<description>Ries, Kishore

Indeed 3000 records is very small unless these are 10MB faxes stored directly in the database :)   Wrong indexing or query which MySQL can&#039;t optimize well is likely reason.  If you report the EXPLAIN on our forums we might be able to help.</description>
		<content:encoded><![CDATA[<p>Ries, Kishore</p>
<p>Indeed 3000 records is very small unless these are 10MB faxes stored directly in the database <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />    Wrong indexing or query which MySQL can&#8217;t optimize well is likely reason.  If you report the EXPLAIN on our forums we might be able to help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ries van Twisk</title>
		<link>http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/comment-page-1/#comment-330847</link>
		<dc:creator>Ries van Twisk</dc:creator>
		<pubDate>Fri, 18 Jul 2008 14:33:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/#comment-330847</guid>
		<description>to Kishore.

I you need to read upon SQL, usage of indexes etc. 3000 records is nothing for any DB and shouldn&#039;t be slow in any case.
Most likely your DB is not properly normalized and you don&#039;t have proper indexes.

Ries</description>
		<content:encoded><![CDATA[<p>to Kishore.</p>
<p>I you need to read upon SQL, usage of indexes etc. 3000 records is nothing for any DB and shouldn&#8217;t be slow in any case.<br />
Most likely your DB is not properly normalized and you don&#8217;t have proper indexes.</p>
<p>Ries</p>
]]></content:encoded>
	</item>
</channel>
</rss>
