<?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: Limited SELECT count(*)</title> <atom:link href="http://www.mysqldiary.com/limited-select-count/feed/" rel="self" type="application/rss+xml" /><link>http://www.mysqldiary.com/limited-select-count/</link> <description>Exploring, Sharing and  Discussing MySQL practice</description> <lastBuildDate>Thu, 02 Feb 2012 09:16:49 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Ashley</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-2149</link> <dc:creator>Ashley</dc:creator> <pubDate>Wed, 08 Sep 2010 23:22:23 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-2149</guid> <description>hey, nice blog...really like it and added to bookmarks. keep up with good work</description> <content:encoded><![CDATA[<p>hey, nice blog&#8230;really like it and added to bookmarks. keep up with good work</p> ]]></content:encoded> </item> <item><title>By: Stephen Kimberling</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1236</link> <dc:creator>Stephen Kimberling</dc:creator> <pubDate>Mon, 21 Jun 2010 08:31:24 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1236</guid> <description>Looking forward to reading more. Great blog post.Really looking forward to read more.</description> <content:encoded><![CDATA[<p>Looking forward to reading more. Great blog post.Really looking forward to read more.</p> ]]></content:encoded> </item> <item><title>By: XPerez</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1148</link> <dc:creator>XPerez</dc:creator> <pubDate>Wed, 09 Jun 2010 08:36:48 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1148</guid> <description>Dear Hazan,
Yes, would be redundant, but the parser understands better the command, takes less time and assures to reserve limited memory results.
This can be checked and tested for a 1 milion record table, selecting conditional to am indexed field, example:
SELECT count(1) FROM cities
WHERE country_id = 50
LIMIT 1</description> <content:encoded><![CDATA[<p>Dear Hazan,</p><p>Yes, would be redundant, but the parser understands better the command, takes less time and assures to reserve limited memory results.</p><p>This can be checked and tested for a 1 milion record table, selecting conditional to am indexed field, example:</p><p>SELECT count(1) FROM cities<br
/> WHERE country_id = 50<br
/> LIMIT 1</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1147</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Wed, 09 Jun 2010 07:09:01 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1147</guid> <description>Thanks for your reply,
Dont you think that the usage of Limit with a count query is redundant? (because the limit applies only on the result and a count results is always one)</description> <content:encoded><![CDATA[<p>Thanks for your reply,<br
/> Dont you think that the usage of Limit with a count query is redundant? (because the limit applies only on the result and a count results is always one)</p> ]]></content:encoded> </item> <item><title>By: XPerez</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1138</link> <dc:creator>XPerez</dc:creator> <pubDate>Tue, 08 Jun 2010 07:09:53 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1138</guid> <description>Firts of all it&#039;s to have good indexes, and it&#039;s better to count a field using these indexes:
SELECT COUNT(1) FROM users WHERE postal_code = &#039;23456&#039;
If you have indexes on postal_code, these count takes few time.
Also, take a look that I make count(1), not count(*), because I&#039;m saying to mysql that I don&#039;t need fields, only count, and the query it&#039;s executed quickest.
Remember that the best policy to make a count before to listing results (and paging), on large sites and large tables, it&#039;s to have a general count in a separate table, almost for those tables that you need to make full scan (or limited where). Also, you can obtain full count on base mysql tables and indexes.
In relation to LIMIT, on all queries it&#039;s better to use a LIMIT:
SELECT count(1) FROM users WHERE postal_code=&#039;67677&#039; LIMIT 1
SELECT count(1) FROM users LIMIT 1
Even when you have 2 or 3 millions of users, these counts will be made on less that a sec.
Remember ever to use cache in your code, and to save those queries that can take a long time.</description> <content:encoded><![CDATA[<p>Firts of all it&#8217;s to have good indexes, and it&#8217;s better to count a field using these indexes:</p><p>SELECT COUNT(1) FROM users WHERE postal_code = &#8217;23456&#8242;</p><p>If you have indexes on postal_code, these count takes few time.</p><p>Also, take a look that I make count(1), not count(*), because I&#8217;m saying to mysql that I don&#8217;t need fields, only count, and the query it&#8217;s executed quickest.</p><p>Remember that the best policy to make a count before to listing results (and paging), on large sites and large tables, it&#8217;s to have a general count in a separate table, almost for those tables that you need to make full scan (or limited where). Also, you can obtain full count on base mysql tables and indexes.</p><p>In relation to LIMIT, on all queries it&#8217;s better to use a LIMIT:</p><p>SELECT count(1) FROM users WHERE postal_code=&#8217;67677&#8242; LIMIT 1</p><p>SELECT count(1) FROM users LIMIT 1</p><p>Even when you have 2 or 3 millions of users, these counts will be made on less that a sec.</p><p>Remember ever to use cache in your code, and to save those queries that can take a long time.</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1130</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Sun, 06 Jun 2010 06:06:49 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1130</guid> <description>The Count will return only one row of result. The limit clause is limiting the number of result rows. Hence, any limit that greater than one will will still show one result which is the only result (that count(*) returns).</description> <content:encoded><![CDATA[<p>The Count will return only one row of result. The limit clause is limiting the number of result rows. Hence, any limit that greater than one will will still show one result which is the only result (that count(*) returns).</p> ]]></content:encoded> </item> <item><title>By: Binod Suman</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1120</link> <dc:creator>Binod Suman</dc:creator> <pubDate>Fri, 04 Jun 2010 14:34:45 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1120</guid> <description>Thanks a lot, this below SQL worked perfectly in my project. But I am still surprise why count(*) does not work with limit clause.
Any how thank a lot of this better workaround.
SELECT COUNT(1) FROM (SELECT 1 FROM subscriber LIMIT 18, 2000)s
Thanks,
Binod Suman
Bangalore,India</description> <content:encoded><![CDATA[<p>Thanks a lot, this below SQL worked perfectly in my project. But I am still surprise why count(*) does not work with limit clause.</p><p>Any how thank a lot of this better workaround.</p><p>SELECT COUNT(1) FROM (SELECT 1 FROM subscriber LIMIT 18, 2000)s</p><p>Thanks,</p><p>Binod Suman<br
/> Bangalore,India</p> ]]></content:encoded> </item> <item><title>By: Emily</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-1096</link> <dc:creator>Emily</dc:creator> <pubDate>Tue, 01 Jun 2010 20:59:33 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-1096</guid> <description>To Josh:
This limited count is useful for showing list with a limited roller. If your Roller shows only 10 pages at a time you don&#039;t need to perform a full count(*) query. A limited count(*) is sufficient and much more performed.</description> <content:encoded><![CDATA[<p>To Josh:<br
/> This limited count is useful for showing list with a limited roller. If your Roller shows only 10 pages at a time you don&#8217;t need to perform a full count(*) query. A limited count(*) is sufficient and much more performed.</p> ]]></content:encoded> </item> <item><title>By: Steve</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-978</link> <dc:creator>Steve</dc:creator> <pubDate>Fri, 28 May 2010 17:37:57 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-978</guid> <description>Keep up the good work, I like your writing.</description> <content:encoded><![CDATA[<p>Keep up the good work, I like your writing.</p> ]]></content:encoded> </item> <item><title>By: student scholarships</title><link>http://www.mysqldiary.com/limited-select-count/comment-page-1/#comment-917</link> <dc:creator>student scholarships</dc:creator> <pubDate>Fri, 21 May 2010 09:52:15 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98#comment-917</guid> <description>Valuable info. Lucky me I found your site by accident, I bookmarked it.</description> <content:encoded><![CDATA[<p>Valuable info. Lucky me I found your site by accident, I bookmarked it.</p> ]]></content:encoded> </item> </channel> </rss>
