Tag Archives: MySQL

Fast MySQL InnoDB count. Really fast

Last night I was pairing with John on a feature for an upcoming release. I wanted to count the number of rows in a table so we could run analytics and track performance. I <3 metrics, ya know?

“Tim, this is simple. Why are you writing about this?”

select count(*) from messages;

And it is simple. If this were MyISAM. See, MyISAM always stores the number of rows on the table header. So, whenever we ask “how many rows are there?”, it can just grab the count and return it. Not InnoDB.

In InnoDB (for internal reasons), the number of rows has to be counted. Every single time. One of the tables we were counting was over 1.2 million rows. On a small EC2 instance with no other queries/major processes, this takes 1 minute and 20 seconds. This is unacceptable.

Posted in tech | Tagged , , , , , , , , | 1 Comment