Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium Production Scenario

Why does `SELECT COUNT(*)` on InnoDB scan the entire primary key tree unlike MyISAM?

Real-World Scenario / Incident Description

Executing `SELECT COUNT(*) FROM orders` on a 50-million row InnoDB table took 12 seconds.

767 views • Updated 1 month ago

Why InnoDB Cannot Store an Exact Row Count

Because InnoDB uses MVCC (Multi-Version Concurrency Control), different concurrent transactions see different numbers of visible rows at the exact same moment.

  • MyISAM locked tables and stored a single counter, but did not support transactions.
  • Solution for Large Tables: Use Redis cached counters or query information_schema.TABLES.TABLE_ROWS for approximations.
Related Concepts: #COUNT #InnoDB #MVCC #Performance