(That said, an index doesn't make this magically faster... the fast performance that people credit MyISAM with is that asking for the total number of rows in a table was O(1), as its lack of intricate transaction concurrency allowed it to just keep a global counter; one which of course was difficult and costly to repair after an unclean outage. In comparison, that indexes can optimize a count() over a where is obvious and true of any sane database engine, whether it be PostgreSQL or any of the common MySQL backends.)
MySQL can do index only queries, whereas PG currently can not (it is part of the next release iirc). This can often result in a fraction of the disk I/O being done for MySQL.
Thanks for pointing this out, though! I'm going to go look into how InnoDB manages to handle that.
[1] select count(object_id) from wp_term_relationships force index(PRIMARY);
[2] select count([asterisk]) from wp_term_relationships
[3] select count([asterisk]) from wp_posts
... all of which produce execution plans that show indexes are being used to perform the count() query. All tables are using InnoDB.
Off topic question: how do you escape an asterisk when entering a reply so that it shows w/in the thread vs. italicizing text?
WHERE id > 0
For some reason counting with that is a lot faster (from my testing) to just a straight count
Questions:
1) What version of MySQL are you testing on?
2) What storage engine are the relevant tables using?
3) What does the execution plan show for both cases (with where id > 0 and w/out it)?