Re: Fastest way to get table records' number
| From: | Shelley | Date: | Thu, 20 Mar 2008 01:36:12 +0000 |
| Subject: | Re: Fastest way to get table records' number | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271871@lists.php.net to get a copy of this message | ||
Nathan Nobbe wrote:
On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballard@gmail.com> wrote:Thanks. This is my test results: mysql> select count(*) from article; +----------+ | count(*) | +----------+ | 1065868 | +----------+ 1 row in set (1.30 sec) mysql> select count(1) from article; +----------+ | count(1) | +----------+ | 1065868 | +----------+ 1 row in set (0.82 sec) mysql> select count(*) from article; +----------+ | count(*) | +----------+ | 1065868 | +----------+ 1 row in set (0.81 sec) mysql> select count(id) from article; +-----------+ | count(id) | +-----------+ | 1065868 | +-----------+ 1 row in set (0.85 sec) mysql> select count(1) from article; +----------+ | count(1) | +----------+ | 1065868 | +----------+ 1 row in set (0.82 sec) mysql> select count(*) from article; +----------+ | count(*) | +----------+ | 1065868 | +----------+ 1 row in set (0.81 sec) mysql> select count(id) from article; +-----------+ | count(id) | +-----------+ | 1065868 | +-----------+ 1 row in set (0.85 sec) mysql> select count(1) from article; +----------+ | count(1) | +----------+ | 1065868 | +----------+ 1 row in set (0.81 sec) Seems that count(1) is always not a bad answer. So, I determined to choose count(1). Thank you all for your replies. -- Regards, Shelley ( PHP Architecture: http://phparch.cn )That works; I'm just wondering why you went with a count on an 'ID' column rather than COUNT(*).ouch, it looks like im horribly wrong :O mysql> select count(*) from table; +----------+ | count(*) | +----------+ | 361724 | +----------+ 1 row in set (0.90 sec) mysql> select count(id) from table; +------------+ | count(did) | +------------+| 361724 |+------------+ 1 row in set (4.56 sec) -nathan Hi nanthan,