
Optimization Scenario | Description | Value |
Query cache partition optimization | Partitioning of Query Cache/Meta Hash is performed, mapping different types or ranges of queries precisely to specific partitions. This reduces the probability of hash collisions and accelerates the query cache positioning and retrieval process. | Improves the hash performance and hit rate of the query cache, significantly reducing CPU resource consumption in high-concurrency query scenarios, and more efficiently responding to a large number of query requests. |
Read-only node table opening optimization | Deep optimization is performed on the table opening operation during the read-only node query cache validity verification process. This reduces unnecessary cache invalidation caused by table operations, ensuring that the query cache remains effective in more scenarios. | Improves the actual utilization of the cache and the overall query performance of the system. |
Intelligent cache control based on hit rate | When the query cache hit rate is low, the intelligent cache control mechanism is automatically activated. It limits the number of concurrent queries and adjusts the sampling frequency appropriately, allowing the majority of queries to bypass the query cache. Only dedicated threads handle sampling and hit rate estimation. Once the hit rate improves, the query cache feature is re-enabled. | Prevents resource waste and performance degradation caused by a large number of queries flooding the cache system under low hit rate conditions. It reduces the space occupied by ineffective query caches and maintains stable and efficient system operation across different hit rate scenarios. |
Cache insertion and eviction overhead optimization | Optimize the cache replacement algorithm and memory management policy to reduce the frequency and resource consumption of cache insertion and eviction operations. Perform cache replacement based on proper policies, prioritizing the retention of high-frequency and important query cache results. | Reduces system performance fluctuations caused by frequent cache insertion and eviction, allowing the query cache to make the most efficient use of limited memory resources and providing continuous, stable query acceleration support. |
LRU cache policy optimization | The Query Cache LRU cache policy is finely tuned based on the query size and number of hits, prioritizing the storage of high-frequency and scalar query results. This helps avoid space waste caused by the slow cache query. | Improves cache space utilization and the system's query response performance under specific loads, ensuring that cache resources are allocated to the most valuable query tasks. |
Dynamic cache switch control | Dynamically disables the query cache when the system faces write load pressure, and enable it again within seconds after the read-write load stops. | Prevents issues related to query cache invalidation and performance degradation caused by frequent data updates. It improves the adaptability and flexibility of the query cache, allowing the system to maintain good performance in complex read-write load environments. |
Dynamic cache capacity adjustment | Supports dynamically resizing the query cache size, with the adjustment process not blocking ongoing read-write requests. The cache size is adjusted flexibly based on real-time load demands and resource availability. | Addresses performance bottlenecks caused by an improperly fixed cache size, avoiding sharp performance declines or interruptions due to cache capacity adjustments. This ensures continuous, stable, and efficient query acceleration services for the system. |
Parameter Name | Restart Required | Global or Not | Default Value | Value Range | Supported Nodes | Description |
query_cache_limit | no | No | 1048576 | 0 - ulong_max* | Read-write instance Read-only instances | Query result sets larger than this value will not be cached. Unit: Bytes. |
query_cache_size | no | No | 1048576 | 1048576 - ulong_max* | Read-write instance Read-only instances | The size of memory available for Query Cache in the system (memory space will only be used when in use). Unit: Bytes. The value should be a multiple of 1,024. Note: In a Sysbench POC scenario, it is recommended to set the query_cache_size to more than 20% of the table size. For normal scenarios, the recommended value is around 5% of the Buffer Pool. If the business does not have read-only tables or if the hotspots are not obvious, it is recommended to reduce the value of query_cache_size. |
query_cache_type | See the description column for details. | No | OFF | OFF/ON/DEMAND | Read-write instance Read-only instances | Value: OFF – Indicates that the feature is disabled. Value: ON – Indicates that all results are cached, unless the SELECT statement uses sql_no_cache to disable query cache. Value: DEMAND – Indicates that only SELECT statements with queries explicitly specified to be cached using sql_cache are cached. Note: If the query cache is initially disabled (with query_cache_type=0 in the configuration file), it cannot be dynamically enabled and requires a restart with the my.cnf configuration file to enable the query cache. However, the query cache can always be dynamically disabled. |
query_cache_wlock_invalidate | no | No | OFF | ON/OFF | Read-write instance Read-only instances | When a write lock occurs on a table, whether the query cache related to that table should be invalidated first: ON: Yes OFF: No |
SHOW STATUS LIKE 'Qcache%';
Status | Description |
Qcache_hits | The number of query cache hits. |
Qcache_hit_rate | The recent query hit rate, which is the proportion of queries that hit the query cache out of the last 10,000 queries (Qcache_search_times increases by 10,000). |
Qcache_search_times | The number of query cache searches (queries that are throttled or unable to use the cache are not counted). |
Qcache_total_times | The total number of times queries accessed the query cache (situations such as traffic throttling are also recorded). |
Qcache_free_memory | The remaining space in the query cache. |
Qcache_inserts | The number of times result sets are successfully cached. |
Qcache_not_cached | The number of times result sets are not cached. |
Qcache_queries_in_cache | The number of queries cached in the query cache. |
Qcache_lowmem_prunes | The number of query cache entries evicted due to the LRU cache policy. |
Testing Objective | Testing Scenarios | Testing Steps and Results |
The performance improvement of query cache in read scenarios. | The performance improvement brought by Query Cache under different data volumes. | |
The impact of query cache size (query_cache_size) on performance. | The performance improvement brought by Query Cache under different query_cache_size values and data volumes. |








Feedback