This is a read-only copy of the MariaDB Knowledgebase generated on 2024-05-19. For the latest, interactive version please visit https://mariadb.com/kb/.

Comments - Incredibly slow count(*) on MariaDB / MySQL

1 month, 1 week ago Ian Gilfillan

With InnoDB, since it only stores estimates of the number of rows in the table, in order to obtain the specific value with COUNT(*), all rows need to be read, which is very slow.

If you're happy with an estimate, you can query information_schema.tables, for example:

SELECT TABLE_ROWS FROM information_schema.tables
WHERE TABLE_SCHEMA = 'db_name' 
AND TABLE_NAME = 'table_name';

See also MDEV-18188.

 
1 month, 1 week ago Michael Modan

Thank you for your comment Ian. Meaning if I'd turn this to use MyISAM it'd work faster?

I'll test it and revert with results :)

Yes, I'm aware of the estimate option via table_rows - can I control its update frequency / ratio i.e if i run ANALYZE TABLE [table_name] periodically does it update the stats?

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.