Your first query may be slower because MySQL actually pushes the disk on the first query, not the second.
Your operating system may cache files in memory as they are read; as a result, subsequent readings may not be necessary to actually get to disk and will return much faster.
Typically, I usually run a query several times and look for consistency. Most often, the first run will take several times longer, and the 2nd and 4th takes about the same time. These subsequent runs are probably more characteristic of the performance that you will see in a real production system, since your production database should store this data in the OS cache, while your development system rarely gets access.
After all, when it comes to query performance, for the most part you should just give it a quick walk in development and monitor the slow query log during production to see which queries are really needed.
For software-based queries for performance data, take a few samples and use the median. But in practice, this will not be terribly representative of the actual performance problems that you will encounter during the production process.
Frank farmer
source share