sql - mysql count performance -


 select count(*) mytable; select count(table_id) mytable; //table_id primary_key 

both query running slow on table 10 million rows. wondering why since wouldn't easy mysql keep counter gets updated on insert,update , delete?
, there way improve query? used explain didn't much.

as cherouvim pointed out in comments, depends on storage engine.

myisam keep count of table rows, , can keep accurate since locks myisam supports table lock.

innodb supports transactions, , needs table scan count rows.

http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -