MySQL. InnoDB. COUNT.

Думаю многие упирались в скорость отработки COUNT при работе с MySQL и InnoDB таблицами.

Мы уже даже привыкли с этим жить и нашли костыли способы как с этим бороться.

Почитывая блог «перконы» наткнулся на объяснение такого поведения, виной всему MVCC:

This is pretty common request which is of high priority as soon as I know. It is however not as trivial as it sounds as Innodb is multi versioning engine so each transaction could see different amount of rows in the table which needs extra handling. Not what it is impossible just not as trivial as you’re saying.

At this poing if you have no holes in your primary key and it goes from one select max(id) is frequently good and fast way to get the count. You also could use counter table especially now with Triggers in MySQL 5.0

Yes I know it is ugly but we have to live with what we have 🙂

Читайте еще: