1

I am trying to execute following query

select COUNT(*) from tbl_impressions group by spackage 

and it took approximately 40 seconds to execute it at first but after a few time same query is executing within 2 seconds.

Does any one know the reason?

PS: All the tables are already indexed.

Thanks in advance.

Damodaran
  • 10,882
  • 10
  • 60
  • 81

1 Answers1

0

The reason why this happens is the following:

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.

Please for further documentation look here http://dev.mysql.com/doc/refman/5.1/en/query-cache.html

Christos
  • 53,228
  • 8
  • 76
  • 108