MySQL Forums
Forum List  »  Performance

Re: resultset rows performance
Posted by: Rick James
Date: September 14, 2012 10:29PM

Simple question; complicated answer...

* SELECT COUNT(*) FROM tbl; -- instantaneous for MyISAM tables. The row count is "dead reckoned". But only for this simple case.
* SELECT COUNT(*) FROM tbl -- for InnoDB, this picks a small secondary index and does a full scan of that index.
* InnoDB cannot be sped up without violating the "transaction isolation level" chosen.
* SELECT COUNT(*) FROM tbl WHERE ...; -- This requires more work because it has to check the rows against the WHERE clause. If there is a useful INDEX, it could be rather fast.
* SELECT SQL_CALC_FOUND_ROWS ... LIMIT ... -- does (effectively) two things: The full query, plus SELECT COUNT(*) FROM tbl WHERE ...

I am suspicious of your timings (and hence some of your conclusions) for two reasons:
* Was the "Query cache" on? (Use SELECT SQL_NO_CACHE ... to avoid it for benchmarking.)
* The first time you run a query, it may read the disk a lot; the second time you run it (or a similar query that needs the same disk blocks), it will run much faster. (Rule of Thumb: 10 times as fast.)

So...
* Avoid the QC.
* Run each test twice; use the second timing.

Options: ReplyQuote


Subject
Views
Written By
Posted
2573
September 14, 2012 02:16AM
1168
September 14, 2012 03:54AM
1127
September 14, 2012 07:49AM
Re: resultset rows performance
1056
September 14, 2012 10:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.