Index: qc/sql/sql_cache.cc =================================================================== --- qc.orig/sql/sql_cache.cc +++ qc/sql/sql_cache.cc @@ -1322,6 +1322,27 @@ uchar *query_cache_query_get_key(const u Functions to store things into the query cache *****************************************************************************/ +bool Query_cache::is_disabled_ext(void) +{ + /* disabled -> enabled */ + if (is_trace_disabled() && global_system_variables.query_cache_type !=0) + { + query_cache.update_query_cache_trace(true); + return false; + } + + /* enable -> disable */ + if (!is_trace_disabled() && global_system_variables.query_cache_type ==0) + { + query_cache.update_query_cache_trace(false); + query_cache.flush(); + return true; + } + + return is_trace_disabled(); +} + + /* Note on double-check locking (DCL) usage. @@ -1388,7 +1409,7 @@ Query_cache::insert(Query_cache_tls *que DBUG_ENTER("Query_cache::insert"); /* See the comment on double-check locking usage above. */ - if (is_disabled() || query_cache_tls->first_query_block == NULL) + if (is_disabled_ext() || query_cache_tls->first_query_block == NULL) DBUG_VOID_RETURN; QC_DEBUG_SYNC("wait_in_query_cache_insert"); @@ -1448,7 +1469,7 @@ Query_cache::abort(Query_cache_tls *quer THD *thd= current_thd; /* See the comment on double-check locking usage above. */ - if (is_disabled() || query_cache_tls->first_query_block == NULL) + if (is_disabled_ext() || query_cache_tls->first_query_block == NULL) DBUG_VOID_RETURN; if (try_lock()) @@ -1586,6 +1607,7 @@ Query_cache::Query_cache(ulong query_cac query_cache_limit(query_cache_limit_arg), queries_in_cache(0), hits(0), inserts(0), refused(0), total_blocks(0), lowmem_prunes(0), m_query_cache_is_disabled(FALSE), + m_query_cache_trace(false), min_allocation_unit(ALIGN_SIZE(min_allocation_unit_arg)), min_result_data_size(ALIGN_SIZE(min_result_data_size_arg)), def_query_hash_size(ALIGN_SIZE(def_query_hash_size_arg)), @@ -1962,7 +1984,7 @@ Query_cache::send_result_to_client(THD * See also a note on double-check locking usage above. */ - if (is_disabled() || thd->locked_tables_mode || + if (is_disabled_ext() || thd->locked_tables_mode || thd->variables.query_cache_type == 0 || query_cache_size == 0) goto err; @@ -2304,7 +2326,7 @@ void Query_cache::invalidate(THD *thd, T my_bool using_transactions) { DBUG_ENTER("Query_cache::invalidate (table list)"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; using_transactions= using_transactions && thd->in_multi_stmt_transaction_mode(); @@ -2334,7 +2356,7 @@ void Query_cache::invalidate(THD *thd, T void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used) { DBUG_ENTER("Query_cache::invalidate (changed table list)"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; THD *thd= current_thd; @@ -2363,7 +2385,7 @@ void Query_cache::invalidate(CHANGED_TAB void Query_cache::invalidate_locked_for_write(TABLE_LIST *tables_used) { DBUG_ENTER("Query_cache::invalidate_locked_for_write"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; THD *thd= current_thd; @@ -2387,7 +2409,7 @@ void Query_cache::invalidate(THD *thd, T my_bool using_transactions) { DBUG_ENTER("Query_cache::invalidate (table)"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; using_transactions= using_transactions && thd->in_multi_stmt_transaction_mode(); @@ -2405,7 +2427,7 @@ void Query_cache::invalidate(THD *thd, c my_bool using_transactions) { DBUG_ENTER("Query_cache::invalidate (key)"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; using_transactions= using_transactions && thd->in_multi_stmt_transaction_mode(); @@ -2426,7 +2448,7 @@ void Query_cache::invalidate(char *db) { DBUG_ENTER("Query_cache::invalidate (db)"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; bool restart= FALSE; @@ -2514,7 +2536,7 @@ void Query_cache::invalidate_by_MyISAM_f void Query_cache::flush() { DBUG_ENTER("Query_cache::flush"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; QC_DEBUG_SYNC("wait_in_query_cache_flush1"); @@ -2547,7 +2569,7 @@ void Query_cache::pack(ulong join_limit, { DBUG_ENTER("Query_cache::pack"); - if (is_disabled()) + if (is_disabled_ext()) DBUG_VOID_RETURN; /* @@ -2616,7 +2638,10 @@ void Query_cache::init() be used. */ if (global_system_variables.query_cache_type == 0) + { query_cache.disable_query_cache(); + query_cache.update_query_cache_trace(false); + } DBUG_VOID_RETURN; } Index: qc/sql/sql_cache.h =================================================================== --- qc.orig/sql/sql_cache.h +++ qc/sql/sql_cache.h @@ -297,10 +297,12 @@ private: Cache_lock_status m_cache_lock_status; bool m_query_cache_is_disabled; + bool volatile m_query_cache_trace; void free_query_internal(Query_cache_block *point); void invalidate_table_internal(THD *thd, uchar *key, uint32 key_length); void disable_query_cache(void) { m_query_cache_is_disabled= TRUE; } + void update_query_cache_trace(bool new_flag) { m_query_cache_trace = new_flag; } protected: /* @@ -445,7 +447,10 @@ protected: uint def_table_hash_size = QUERY_CACHE_DEF_TABLE_HASH_SIZE); bool is_disabled(void) { return m_query_cache_is_disabled; } - + bool is_trace_disabled(void) { return !m_query_cache_trace; } + + /* extensional implementation of is_disabled */ + bool is_disabled_ext(void); /* initialize cache (mutex) */ void init(); /* resize query cache (return real query size, 0 if disabled) */ Index: qc/sql/sys_vars.cc =================================================================== --- qc.orig/sql/sys_vars.cc +++ qc/sql/sys_vars.cc @@ -1866,7 +1866,7 @@ static Sys_var_ulong Sys_query_cache_min static const char *query_cache_type_names[]= { "OFF", "ON", "DEMAND", 0 }; static bool check_query_cache_type(sys_var *self, THD *thd, set_var *var) { - if (query_cache.is_disabled()) + if (query_cache.is_disabled_ext()) { my_error(ER_QUERY_CACHE_DISABLED, MYF(0)); return true; @@ -1879,8 +1879,8 @@ static Sys_var_enum Sys_query_cache_type "except SELECT SQL_NO_CACHE ... queries. DEMAND = Cache only " "SELECT SQL_CACHE ... queries", SESSION_VAR(query_cache_type), CMD_LINE(REQUIRED_ARG), - query_cache_type_names, DEFAULT(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, - ON_CHECK(check_query_cache_type)); + query_cache_type_names, DEFAULT(1), NO_MUTEX_GUARD, NOT_IN_BINLOG/*, + ON_CHECK(check_query_cache_type)*/); static Sys_var_mybool Sys_query_cache_wlock_invalidate( "query_cache_wlock_invalidate",