简体   繁体   中英

MySQL query caching working

I want to understand how MySQL query cache works. I have checked this api

How does these scenarios will work.?

Case 1

select * from my_table where column = 'Myvalue';

Case 2

select * from my_table where column = 'test';

Case 3

select * from my_table where column = 'Myvalue';

So when case 3 is executed i want to know that whether the results will be fetched from the cache or from the database.? Can somebody explain.? Because they are mentioning this in the manual

Queries must be exactly the same (byte for byte) to be seen as identical.

Since queries 1 and 3 are identical, as long as the results from the first query are still in the query cache and there were no updates to the table between the queries, the third query will be served up by the cache instead of hitting the table.

The query cache is off by default. Set query_cache_size to the size in bytes to enable the query cache. Set in multiples of 1024 bytes. The documentation says:

Sizes in tens of megabytes are usually beneficial.

Also note the following about query cache operation :

Before MySQL 5.1.17, prepared statements do not use the query cache. Beginning with 5.1.17, prepared statements use the query cache under certain conditions, which differ depending on the preparation method.

If a table changes, all cached queries that use the table become invalid and are removed from the cache.

Note that according to the query cache, the following two queries are not identical, though they return identical result sets:

select * from my_table where column = 'Myvalue';

SELECT * FROM my_table WHERE column = 'Myvalue';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM