简体   繁体   English

MySQL查询缓存工作

[英]MySQL query caching working

I want to understand how MySQL query cache works. 我想了解MySQL查询缓存的工作方式。 I have checked this api 我已经检查过这个API

How does these scenarios will work.? 这些方案将如何工作?

Case 1 情况1

select * from my_table where column = 'Myvalue';

Case 2 情况二

select * from my_table where column = 'test';

Case 3 情况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.? 因此,当执行情况3时,我想知道结果是从缓存中获取还是从数据库中获取。 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. 由于查询1和3相同,因此只要第一个查询的结果仍在查询缓存中,并且查询之间的表没有更新,则第三个查询将由缓存提供服务,而不是命中该表。

The query cache is off by default. 默认情况下,查询缓存处于关闭状态。 Set query_cache_size to the size in bytes to enable the query cache. query_cache_size设置为字节大小以启用查询缓存。 Set in multiples of 1024 bytes. 以1024字节的倍数设置。 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. 在MySQL 5.1.17之前,准备好的语句不使用查询缓存。 Beginning with 5.1.17, prepared statements use the query cache under certain conditions, which differ depending on the preparation method. 从5.1.17开始,已准备好的语句在某些条件下使用查询缓存,具体情况取决于准备方法。

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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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