Aufwind
Aufwind

Reputation: 26278

Does MySQL store somehow the last querie(s)?

While working with MySQL and some really "performance greedy queries" I noticed, that if I run such a greedy query it could take 2 or 3 minutes to be computed. But if I retry the query immediately after it finished the first time, it takes only some seconds. Does MySQL store something like "the last x queries"?

Upvotes: 3

Views: 94

Answers (3)

Jordan H.
Jordan H.

Reputation: 331

Yes, depending on how the MySQL Server is configured, it may be using the query cache. This stores the results of identical queries until a certain limit (which you can set if you control the server) has been reached. Read http://dev.mysql.com/doc/refman/5.1/en/query-cache.html to find out more about how to tune your query cache to speed up your application if it issues many identical queries.

Upvotes: 0

Leons
Leons

Reputation: 2674

The execution plan for the query will be calculated and re-used. The data can be cached, so subsequent executions will be faster.

Upvotes: 0

Mark Staff
Mark Staff

Reputation: 721

The short answer is yes. there is a Query Cache.

The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. The query cache is shared among sessions, so a result set generated by one client can be sent in response to the same query issued by another client.

from here

Upvotes: 5

Related Questions