Optimise InnoDB table counts

from the Artful MySQL Tips List

SELECT COUNT(*) FROM innoDBtablename is notoriously slow. On average hardware, it can take a full minute on a table with three million rows. You might even say it's scandalously slow. There is no good fix, but there's a partial fix. Forcing the index can cut execution time by 95%:
SELECT COUNT(*) FROM innoDbtablename USING INDEX( primary );

Last updated 19 Aug 2010

Return to the Artful MySQL Tips page