3 ms·
For the count(*) queries: Almost no database optimizes this. What they do is count the rows. MyISAM (one of the storage engines for MySQL) heavily optimizes
by mdasen 18y ago
For the count(*) queries:
Almost no database optimizes this. What they do is count the rows. MyISAM (one of the storage engines for MySQL) heavily optimizes this by having a row count in the table data.
This turns out not to be that useful because who wants to count the number of rows in a table? You usually want to count a subset of those rows. Like, how many comments are there for post_id 7.
So, MySQL isn't unoptimized for this.
- ajross 18y agoYou mean MySQL can give you the answer in constant or log time. But folks like me, who naively use the count() aggregate like we've been taught in books, are going to have scalability problems unless we understand the internals of the database engine. That was my point: it's not a slam against MySQL per se, it's a slam against the whole development metaphor, which seems to derive unholy pleasure in hiding critically important implementation details from the developer.