Slow count(*) workaround

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.

Last updated 26 Nov 2024


Return to the Artful MySQL Tips page