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
Post a Comment