I'm clearly missing something fundamental about how InnoDB tables work. I've created a table...
CREATE TABLE t (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY
-- whole bunch of other other fields
I've batch inserted the first, say, 300,000 records (so they all carry distinct and sequential IDs at this point). No problem.
Then I run the following (highly sophisticated) query:
SELECT COUNT(id) FROM t;
It takes around 20 seconds to run. EXPLAIN indicates it's using the primary key (i.e. the index), but that with the index it still has to contemplate just under (or sometimes over) 300,000 rows.
OPTIMIZE TABLE has no impact. Explicitly creating an index has no impact. Me whacking the server with a hammer has no impact but to summon the systems group to get me out of the machine room.
Seriously, what am I missing that would make this (and, for that matter, other "real" queries) run so slow when they seem so simple?
(I note, incidentally, that after running ALTER TABLE t ENGINE MyISAM, queries run as fast as I want them to. I realize MyISAM inherently allows faster SELECT access, but surely not a 20 second vs. sub-millisecond difference on a query for the total number of rows in the table?)