I have a table that has a large number of rows in it.
The primary key (an auto-incrementing integer) is, by default, indexed.
While waiting for a row count to be returned I did an EXPLAIN in another window and the the results were as follows:
mysql> SELECT COUNT(1) FROM `gauge_data`;
+----------+
| COUNT(1) |
+----------+
| 25453476 |
+----------+
1 row in set (2 min 36.20 sec)
mysql> EXPLAIN SELECT COUNT(1) FROM `gauge_data`;
+----+-------------+------------+-------+---------------+-----------------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+---------------+-----------------+---------+------+----------+-------------+
| 1 | SIMPLE | gauge_data | index | NULL | gauge_data_FI_1 | 5 | NULL | 24596487 | Using index |
+----+-------------+------------+-------+---------------+-----------------+---------+------+----------+-------------+
1 row in set (0.13 sec)
Since the primary key is guaranteed to be unique, can I just take the number of rows from the EXPLAIN and use that as the row count of the table?
BTW, I believe the difference in numbers is due to the fact that more data is continually being added to this table.
EXPLAINcommand be more accurate than aSHOW TABLE STATUScommand? I've seen the row count fluctuate wildly in phpMyAdmin – Patrick Nov 29 '12 at 14:53