alessio1985
alessio1985

Reputation: 513

Why is it that when the same query is executed twice in MySQL, it returns two very different response times?

my question is as follows:

Why if I do the same query two times in shell MySql get two very different response times (ie,

the first time and the second a much shorter time)?

and how can I do to prevent this from happening??

thank you very much in advance

Upvotes: 0

Views: 1105

Answers (2)

Pannan Mp
Pannan Mp

Reputation: 77

This could be due to 1.query caching is turned on or due to 2.the difference in performance states of the system in which it is being executed.
In query caching if you run a query once mysql stores the compiled version of the query and is fetched when called again . the time for compiling is not there in the repeated execution of the same query . query caching can be turned off but it is not a good idea

Upvotes: 2

bizzehdee
bizzehdee

Reputation: 20993

This is most likely down to query and/or result caching. if you run a query once, MySQL stores the compiled version of that query, and also has the indexes stored in memory for those particular tables, so any subsequent queries are vastly faster than the original.

Upvotes: 5

Related Questions