When I execute a simple statement in phpMyAdmin like
SELECT *
FROM a
where \"a\" has 500\'000 rows, it gives me a time of a few milliseconds on
Besides splash21's answer, it is a good idea to use SQL_NO_CACHE when testing for execution time. This makes sure that you are looking at the real time to do the query, not just grabbing a cached result.
SELECT SQL_NO_CACHE *
FROM a
phpMyAdmin automatically appends a LIMIT
clause to your statement, so it has a smaller result set to return thus making it faster.
Even if you need all 300,000 or 500,000 results then you should really use a LIMIT
. Multiple smaller queries does not necessarily mean same execution time as a single big query.
The displayed execution time is how long the query took to run on the server - it's accurate and comes from the MySQL engine itself. Unfortunately, the results have to then be sent over the web to your browser to be displayed, which takes a lot longer.
Imagine you have a pretty big table, let's say a million rows. Now you do a select, something you know is going to take a while:
SELECT * FROM bigTable WHERE value > 1234
...and PMA will report (after some waiting) that the query took some 0.0045 seconds. This is not the whole query time, this is the time of getting the first 25 hits. Or 50, or whatever you set the page size to. So it's obviously fast - it stops as soon as you get the first screenful of rows. But you will notice that it gives you this deceptive result after looong seconds; it's because MySQL needs to really do the job, in order to determine which rows to return. It runs the whole query, and then it takes another look and returns only a few rows. That's what you get the time of.
Do a count() with the same conditions.
SELECT COUNT(1) FROM bigTable WHERE value > 1234
You will get ONE row telling you the total number of rows, and naturally, PMA will display the exact time needed for this. It has to, because now the first page and the whole result means the same thing.