Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SQL_NO_CACHE apply to the enitre query, including subqueries?

Tags:

mysql

SQL_NO_CACHE can be used to disable MySQL's cache when performing a SELECT query, like so:-

SELECT SQL_NO_CACHE * FROM tblA

I am wondering if I perform a query containing a subquery if I need to specify for the subquery as well, for example:-

SELECT SQL_NO_CACHE
     a.*,
     (SELECT col1 FROM tblB WHERE id=1)
FROM tblA a

Would the cache be disabled for the subquery?

like image 828
rgvcorley Avatar asked Mar 19 '26 04:03

rgvcorley


1 Answers

Not only does it apply to the whole query, the subquery doesn't get cached at all.

You can check for yourself if a cache is hit by issueing the command

SHOW STATUS LIKE 'QCache%';

You will see among those variables QCache_hits and Qcache_inserts. The latter increases when a query result is inserted as the name says and the first one tells you, if after a select the cache was used or not.

The queries for which results get read from cache must be exactly like the ones that inserted the result set into cache. It's even case sensitive.

 SELECT foo FROM bar;

is not the same as

 SELECt foo FROM bar;
like image 87
fancyPants Avatar answered Mar 20 '26 20:03

fancyPants



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!