Quote:
Does anyone know why?
1. Most database engines use caches too, and I think also MySQL does.
So when you you execute the queries for the second time, the database engines probably:
-has the queries already parsed and compiled (with the execution plan)
-has the relevant pages already in cache and has therefore not to read on disk (only logical reads, no physicals reads)
You can monitor and measure the query response time for example with p6spy.
2. Several jdbc drivers are provided with a cache for prepared statements,
so the same prepared-statement query executed for a second time, has not to be parsed anymore.
Also this could make further queries faster than the first execution.