Mysql state invalidating
You can access the patch from: 2742 Kristofer Pettersson 2008-10-29 Bug#38551 query cache can still consume [very little] cpu time even when it is off.
You can access the patch from: 2917 Kristofer Pettersson 2008-11-07 Bug#38551 query cache can still consume [very little] cpu time even when it is off.
You can access the patch from: 2735 Kristofer Pettersson 2008-09-08 Bug#38551 query cache can still consume [very little] cpu time even when it is off.
When the query cache size is zero, all query cache functionallity should be skipped.
3) Only be able to disable query cache at compile time/startup time.
What is left to investigate is if it really is possible to read query_cache_size in a concurrent environment and if the rare but occasional lack of consistence when the query_cache_size change is an issue for the overall system performance. After review, it may be pushed to the relevant source trees for release in the next version.
The current code actually locks/unlocks the query_cache lock twice when the query_cache_size is zero! This can all be bypassed if the check for query_cache_size is done without holding the QC lock as in Query_cache::store_query The CPU time wasted is very less, however, in benchmark situations, every cpu cycle counts.
It often happens to see and hear of replication SQL thread almost always in state “invalidating query cache entries (table)” .
By using the command line option --query_cache_type=0, the user can disable the query cache permanently and avoid taking the query cache mutex.
At this time there is no plan to backport the fix to a stable release as it changes the behavior of the query_cache_type command line option.
The query mutex becomes a very hot spot especially if you are using RBR.
In fact, with RBR there is a binlog event for each modified row, thus the mutex is acquired for every row.
Search for mysql state invalidating:
Since query_cache_size is protected from any changes by the barrier in Query_cache::resize() we can safely add a test at the begining of the invalidate* functions to avoid having mutexes locked when the query cache is ment to be disabled. After review, it may be pushed to the relevant source trees for release in the next version.