Search code examples
mysqlcountinnodb

How to do a fast but innacurate InnoDB row count?


The FAQ of PHPMyAdmin has this to say about its approximate row counts for InnoDB:

phpMyAdmin uses a quick method to get the row count, and this method only returns an approximate count in the case of InnoDB tables.

I would like to use this 'quick method' - but everywhere I search seems to have a different answer.

Does anyone know?


Solution

  • They do this:

    SHOW TABLE STATUS LIKE 'foo';
    

    This returns a 'Rows' column. With MyISAM it's 100% accurate, InnoDB just guesses. This is why MyISAM is faster than InnoDB when doing a 'SELECT COUNT(*)' query without a where clause.

    phpMyAdmin is open-source, so you can just go into the code and see for yourself!