Workaround for slow count(*) in InnoDB

from the Artful MySQL Tips List


It can be especially slow in MySQL 5.7.

A workaround: for table tblname with primary key PK till it's fixed, pick off the rows value from ...

EXPLAIN SELECT COUNT(PK) FROM tblname USE INDEX (PRIMARY) ;

As of MySQL version 5.7.18, there is a better workaround: add a FORCE INDEX clause to the SELECT COUNT(*) command.



Return to the Artful MySQL Tips page