2

How to disable caching queries' results for the current session in MySQL8?

The Documentation of system variables has lot of variables that regard to caching but most of them are deprecated and I could not find any to use for disabling a query caching.
I am interested in disabling caching for all statements following the disable command. Is there any way to do that?

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Jimmix
  • 5,644
  • 6
  • 44
  • 71

1 Answers1

4

The query cache was removed in MySQL 8.

You can try clearing buffers, as described here: how to clear/flush mysql innodb buffer pool?

However, there will be OS-level disk caching, and also hardware (HDD/SDD) caching. This makes a 2 order magnitude difference on what I'm personally testing at the moment. What you're proposing may not be possible.

I'd suggest using EXPLAIN queries and very carefully thinking about what indexes are used, how many rows are touched, whether it's creating temporary tables, and generally to think through the execution strategy MySQL will be having ot execute.

Once you believe you have fixed your performance issue, see how it performs on a cold boot.

ChrisGraham
  • 56
  • 1
  • 2
  • Yes, probably what I'll do is to prepare a separate instance of a DB inside a docker container that I will restart before querying it. That's a fat ass workaround but seems to be the only solution that would get rid of buffering. Good that you pointed out the file system buffering, I'll keep that in mind. – Jimmix Nov 18 '19 at 18:09
  • MySQL 8.0 will not support query cache, and users upgrading will be encouraged to use either Server-side Query Rewrite or ProxySQL as a man-in-the-middle cache. [Source](https://mysqlserverteam.com/mysql-8-0-retiring-support-for-the-query-cache/) – Jimmix Apr 24 '21 at 17:33