SQL SERVER – SQL_NO_CACHE and OPTION RECOMPILE Target Different Caches

OPTION (RECOMPILE) and SQL_NO_CACHE concern different cached objects. A banking customer using MySQL and SQL Server prompted my comparison.

A replacement shaping template is separate from a populated tray of retained tiles.

SELECT name FROM sys.databases OPTION (RECOMPILE);
-- Historical MySQL 5.7 query-cache modifier, not SQL Server syntax:
-- SELECT SQL_NO_CACHE ColumnName FROM TableName;

OPTION (RECOMPILE) creates a temporary statement plan using the current compilation context. SQL Server discards that plan after execution. It does not flush data pages or force physical disk reads. Repeated compilation also costs resources.

Historical MySQL SQL_NO_CACHE avoids using and populating the query result cache for that statement. It does not bypass InnoDB or operating-system caches. MySQL removed the query cache in 8.0. Check the actual product and version, including MariaDB.

I incorrectly appended SQL Server OPTION syntax to the MySQL example. The corrected historical shape is now a comment. For benchmarks, identify compilation, reads and application-cache effects separately. These modifiers don’t create equivalent cache conditions.

Reference: MySQL 8.0 removal of the query cache.

Related reading

A cache modifier is not a controlled cold-disk test, it is an instruction with a specific product and scope.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

MySQL, Query Hint, SQL Cache, SQL Scripts, SQL Server
Previous Post
Schema Discovery for JSON Columns: Listing Every Key With OPENJSON
Next Post
SQL SERVER – Fixing Freezing Activity Monitor

Related Posts

3 Comments. Leave new

  • I thouhjt OPTION (RECOMPILE) only forced the compilation of a new execution plan – i.e. would still use the data from the cache if already present?

    Reply
  • Roman Peralta
    May 10, 2020 1:46 am

    I had tought that RECOMPILE hint was meant only for execution plans not for data cache.

    Reply
  • Carsten Saastamoinen
    May 16, 2020 1:15 pm

    RECOMPILE is ONLY for execution plans not for data cache!!!!!!!!!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.