1

The manual indicates that "SQL_NO_CACHE" prevents a query from being added to the cache. But it doesn't say anything about using the cache, that I can see.

I'm trying to benchmark two versions of a query, but they've already been run without "SQL_NO_CACHE". So I don't know if my tests are using the query cache or not.

Does the "SQL_NO_CACHE" directive prevent a query from using the cache, or just from adding to it?

Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120

1 Answers1

3

The MySQL query cache is indexed based on the full, literal text of the query, so there is functionally no difference: even if the directive were ignored, the results of a query with SQL_NO_CACHE would be stored in a different cache "slot" from the query without SQL_NO_CACHE. (Indeed, simply adding a space to the query somewhere, or changing "SELECT" to "select" -- for instance -- would also "bust" the query cache, making it run again. The MySQL query cache is not particularly sophisticated.)

That being said, a quick test by running a query with SQL_NO_CACHE and watching the QCACHE_QUERIES_IN_CACHE status confirms that SQL_NO_CACHE does prevent variables from being stored in the cache, and a look at the source makes it look as though the presence of SQL_NO_CACHE will also keep MySQL from checking the cache for results.