MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Kristofer Pettersson Date:October 28 2008 12:13pm
Subject:bzr commit into mysql-6.0 branch (kristofer.pettersson:2742) Bug#38551
View as plain text  
#At file:///export/home/thek/bzr/mysql-6.0-bug38551/

 2742 Kristofer Pettersson	2008-10-28
      Bug#38551 query cache can still consume [very little] cpu time even when it is off.
                                
      When the query cache is disabled, the server shouldn't attempt to take the 
      query cache mutex.
                          
      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.
added:
  mysql-test/r/query_cache_disabled.result
  mysql-test/t/query_cache_disabled-master.opt
  mysql-test/t/query_cache_disabled.test
modified:
  mysql-test/r/query_cache.result
  mysql-test/r/query_cache_type_basic.result
  mysql-test/r/query_cache_type_func.result
  mysql-test/t/query_cache.test
  mysql-test/t/query_cache_type_basic.test
  mysql-test/t/query_cache_type_func.test
  sql/set_var.cc
  sql/set_var.h
  sql/share/errmsg.txt
  sql/sql_cache.cc
  sql/sql_cache.h

per-file messages:
  mysql-test/r/query_cache.result
    * Modified test case to reflect changes in query_cache_type behavior.
  mysql-test/r/query_cache_disabled.result
    * Added test case to demonstrate changes in query_cache_type behavior.
  mysql-test/r/query_cache_type_basic.result
    * Modified test case to reflect changes in query_cache_type behavior.
  mysql-test/r/query_cache_type_func.result
    * Modified test case to reflect changes in query_cache_type behavior.
  mysql-test/t/query_cache.test
    * Modified test case to reflect changes in query_cache_type behavior.
  mysql-test/t/query_cache_disabled-master.opt
    * Added test case to demonstrate changes in query_cache_type behavior.
  mysql-test/t/query_cache_disabled.test
    * Added test case to demonstrate changes in query_cache_type behavior.
  mysql-test/t/query_cache_type_basic.test
    * Modified test case to reflect changes in query_cache_type behavior.
  mysql-test/t/query_cache_type_func.test
    * Modified test case to reflect changes in query_cache_type behavior.
  sql/set_var.cc
    * Added before trigger to verify that query_cache_type wasn't turned off or on during
    runtime.
  sql/set_var.h
    * Changed order on how the enumeration is processed. By first projecting the
    character representation of the variable to a temporary integer we can have one
    function instead of two to check if the value is valid.
  sql/share/errmsg.txt
    * Added error message
  sql/sql_cache.cc
    * If the query cache is disabled at start up, shorten the execution path and avoid
    grabbing the query cache mutex each time the invalidate interface methods are called.
  sql/sql_cache.h
    * Added new methods to set the query cache into a disabled state.
=== modified file 'mysql-test/r/query_cache.result'
--- a/mysql-test/r/query_cache.result	2008-07-17 19:55:18 +0000
+++ b/mysql-test/r/query_cache.result	2008-10-28 12:13:25 +0000
@@ -1600,6 +1600,7 @@ drop table t1,t2;
 set global query_cache_size=100000;
 set global query_cache_size=0;
 set global query_cache_type=0;
+ERROR HY000: Incorrect arguments to SET
 show status like 'Qcache_free_blocks';
 Variable_name	Value
 Qcache_free_blocks	0

=== added file 'mysql-test/r/query_cache_disabled.result'
--- a/mysql-test/r/query_cache_disabled.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/query_cache_disabled.result	2008-10-28 12:13:25 +0000
@@ -0,0 +1,13 @@
+SHOW GLOBAL VARIABLES LIKE 'query_cache_type';
+Variable_name	Value
+query_cache_type	OFF
+SET GLOBAL query_cache_type=ON;
+ERROR HY000: Query cache is disabled from the command line
+SET GLOBAL query_cache_type=DEMAND;
+ERROR HY000: Query cache is disabled from the command line
+SET GLOBAL query_cache_type=OFF;
+ERROR HY000: Query cache is disabled from the command line
+SET GLOBAL query_cache_size=1024*1024;
+SHOW GLOBAL VARIABLES LIKE 'query_cache_size';
+Variable_name	Value
+query_cache_size	1048576

=== modified file 'mysql-test/r/query_cache_type_basic.result'
--- a/mysql-test/r/query_cache_type_basic.result	2008-04-10 13:14:28 +0000
+++ b/mysql-test/r/query_cache_type_basic.result	2008-10-28 12:13:25 +0000
@@ -8,11 +8,13 @@ SELECT @session_start_value;
 ON
 '#--------------------FN_DYNVARS_134_01------------------------#'
 SET @@global.query_cache_type = 0;
+ERROR HY000: Incorrect arguments to SET
 SET @@global.query_cache_type = DEFAULT;
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
 ON
 SET @@session.query_cache_type = 0;
+ERROR HY000: Incorrect arguments to SET
 SET @@session.query_cache_type = DEFAULT;
 SELECT @@session.query_cache_type;
 @@session.query_cache_type
@@ -28,9 +30,10 @@ SET @@session.query_cache_type = '';
 ERROR 42000: Variable 'query_cache_type' can't be set to the value of ''
 '#--------------------FN_DYNVARS_134_03------------------------#'
 SET @@global.query_cache_type = OFF;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
-OFF
+ON
 SET @@global.query_cache_type = ON;
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
@@ -40,9 +43,10 @@ SELECT @@global.query_cache_type;
 @@global.query_cache_type
 DEMAND
 SET @@session.query_cache_type = OFF;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@session.query_cache_type;
 @@session.query_cache_type
-OFF
+ON
 SET @@session.query_cache_type = ON;
 SELECT @@session.query_cache_type;
 @@session.query_cache_type
@@ -59,9 +63,10 @@ ERROR 42000: Variable 'query_cache_type'
 SET @@global.query_cache_type = 'ON,OFF';
 ERROR 42000: Variable 'query_cache_type' can't be set to the value of 'ON,OFF'
 SET @@global.query_cache_type = 'OF';
+ERROR HY000: Incorrect arguments to SET
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
-OFF
+DEMAND
 'Bug# 34828: OF is taken as OFF.'
 SET @@global.query_cache_type = YES;
 ERROR 42000: Variable 'query_cache_type' can't be set to the value of 'YES'
@@ -81,9 +86,10 @@ WHERE VARIABLE_NAME='query_cache_type';
 1
 '#---------------------FN_DYNVARS_134_07-------------------------#'
 SET @@global.query_cache_type = 0;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
-OFF
+DEMAND
 SET @@global.query_cache_type = 1;
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
@@ -93,9 +99,10 @@ SELECT @@global.query_cache_type;
 @@global.query_cache_type
 DEMAND
 SET @@global.query_cache_type = 0.4;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
-OFF
+DEMAND
 SET @@global.query_cache_type = 1.0;
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
@@ -130,9 +137,10 @@ SELECT @@global.query_cache_type;
 @@global.query_cache_type
 ON
 SET @@global.query_cache_type = FALSE;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
-OFF
+ON
 '#---------------------FN_DYNVARS_134_09----------------------#'
 SET query_cache_type = 'ON';
 SET session.query_cache_type = 'OFF';
@@ -144,9 +152,10 @@ SELECT @@query_cache_type;
 @@query_cache_type
 ON
 SET global query_cache_type = 0;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@global.query_cache_type;
 @@global.query_cache_type
-OFF
+ON
 SET @@global.query_cache_type = @global_start_value;
 SELECT @@global.query_cache_type;
 @@global.query_cache_type

=== modified file 'mysql-test/r/query_cache_type_func.result'
--- a/mysql-test/r/query_cache_type_func.result	2008-04-10 13:14:28 +0000
+++ b/mysql-test/r/query_cache_type_func.result	2008-10-28 12:13:25 +0000
@@ -29,9 +29,10 @@ SELECT @@query_cache_type;
 ON
 ON Expected
 SET @@query_cache_type = OFF;
+ERROR HY000: Incorrect arguments to SET
 SELECT @@query_cache_type;
 @@query_cache_type
-OFF
+ON
 OFF Expected
 SET @@query_cache_type = DEMAND;
 SELECT @@query_cache_type;
@@ -119,24 +120,6 @@ Qcache_queries_in_cache	5
 Expected value : 3
 ==================
 Bug#35388: Stored procedure execution causes improper behavior of query cache.
-'#--------------------FN_DYNVARS_135_06-------------------------#'
-FLUSHING CACHE
-SET @@GLOBAL.query_cache_size = 0;
-SET @@GLOBAL.query_cache_size = 65536;
-** Turning cache to OFF **
-SET @@query_cache_type = OFF;
-SELECT @@query_cache_type;
-@@query_cache_type
-OFF
-SELECT id FROM t1;
-id
-1
-2
-3
-SHOW STATUS LIKE 'Qcache_queries_in_cache';
-Variable_name	Value
-Qcache_queries_in_cache	0
-0 Expected
 '#--------------------FN_DYNVARS_135_07-------------------------#'
 SELECT SQL_CACHE id FROM t1;
 id
@@ -145,8 +128,8 @@ id
 3
 SHOW STATUS LIKE 'Qcache_queries_in_cache';
 Variable_name	Value
-Qcache_queries_in_cache	0
-0 Expected
+Qcache_queries_in_cache	6
+6 Expected
 SELECT SQL_CACHE * FROM t1;
 id	value
 1	val1
@@ -154,8 +137,8 @@ id	value
 3	val3
 SHOW STATUS LIKE 'Qcache_queries_in_cache';
 Variable_name	Value
-Qcache_queries_in_cache	0
-0 Expected
+Qcache_queries_in_cache	7
+7 Expected
 '#--------------------FN_DYNVARS_135_08-------------------------#'
 FLUSHING CACHE
 SET @@GLOBAL.query_cache_size = 0;
@@ -185,15 +168,9 @@ Variable_name	Value
 Qcache_queries_in_cache	1
 0 Expected
 ** TESTING GLOBAL SCOPE **
-'#--------------------FN_DYNVARS_135_10-------------------------#'
-SET @@GLOBAL.query_cache_type = OFF;
+'#--------------------FN_DYNVARS_135_11-------------------------#'
 ** Connecting con1 using root **
 ** Connection con1 **
-SELECT @@query_cache_type;
-@@query_cache_type
-OFF
-OFF Expected
-'#--------------------FN_DYNVARS_135_11-------------------------#'
 SET @@GLOBAL.query_cache_type = DEMAND;
 ** Connecting con2 using root **
 ** Connection con2 **

=== modified file 'mysql-test/t/query_cache.test'
--- a/mysql-test/t/query_cache.test	2008-10-09 10:58:51 +0000
+++ b/mysql-test/t/query_cache.test	2008-10-28 12:13:25 +0000
@@ -1249,6 +1249,7 @@ disconnect user3;
 --echo #
 set global query_cache_size=100000;
 set global query_cache_size=0;
+--error ER_WRONG_ARGUMENTS
 set global query_cache_type=0;
 show status like 'Qcache_free_blocks';
 

=== added file 'mysql-test/t/query_cache_disabled-master.opt'
--- a/mysql-test/t/query_cache_disabled-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/query_cache_disabled-master.opt	2008-10-28 12:13:25 +0000
@@ -0,0 +1 @@
+--query_cache_type=0

=== added file 'mysql-test/t/query_cache_disabled.test'
--- a/mysql-test/t/query_cache_disabled.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/query_cache_disabled.test	2008-10-28 12:13:25 +0000
@@ -0,0 +1,13 @@
+#
+# Bug#38551 query cache can still consume [very little] cpu time even when it is off.
+#
+SHOW GLOBAL VARIABLES LIKE 'query_cache_type';
+--error ER_QUERY_CACHE_DISABLED
+SET GLOBAL query_cache_type=ON;
+--error ER_QUERY_CACHE_DISABLED
+SET GLOBAL query_cache_type=DEMAND;
+--error ER_QUERY_CACHE_DISABLED
+SET GLOBAL query_cache_type=OFF;
+SET GLOBAL query_cache_size=1024*1024;
+SHOW GLOBAL VARIABLES LIKE 'query_cache_size';
+

=== modified file 'mysql-test/t/query_cache_type_basic.test'
--- a/mysql-test/t/query_cache_type_basic.test	2008-04-10 13:14:28 +0000
+++ b/mysql-test/t/query_cache_type_basic.test	2008-10-28 12:13:25 +0000
@@ -45,10 +45,12 @@ SELECT @session_start_value;
 #                    Display the DEFAULT value of query_cache_type     #
 ######################################################################## 
 
+--error ER_WRONG_ARGUMENTS
 SET @@global.query_cache_type = 0;
 SET @@global.query_cache_type = DEFAULT;
 SELECT @@global.query_cache_type;
 
+--error ER_WRONG_ARGUMENTS
 SET @@session.query_cache_type = 0;
 SET @@session.query_cache_type = DEFAULT;
 SELECT @@session.query_cache_type;
@@ -76,6 +78,7 @@ SET @@session.query_cache_type = '';
 #             Change the value of query_cache_type to a valid value    #
 ######################################################################## 
 
+--error ER_WRONG_ARGUMENTS
 SET @@global.query_cache_type = OFF;
 SELECT @@global.query_cache_type;
 
@@ -85,6 +88,7 @@ SELECT @@global.query_cache_type;
 SET @@global.query_cache_type = DEMAND;
 SELECT @@global.query_cache_type;
 
+--error ER_WRONG_ARGUMENTS
 SET @@session.query_cache_type = OFF;
 SELECT @@session.query_cache_type;
 
@@ -108,6 +112,7 @@ SET @@global.query_cache_type = ONDEMAND
 --Error ER_WRONG_VALUE_FOR_VAR
 SET @@global.query_cache_type = 'ON,OFF';
 
+--error ER_WRONG_ARGUMENTS
 SET @@global.query_cache_type = 'OF';
 SELECT @@global.query_cache_type;
 
@@ -145,6 +150,7 @@ WHERE VARIABLE_NAME='query_cache_type';
 ################################################################### 
 
 # test if variable accepts 0,1,2
+--error ER_WRONG_ARGUMENTS
 SET @@global.query_cache_type = 0;
 SELECT @@global.query_cache_type;
 
@@ -156,6 +162,7 @@ SELECT @@global.query_cache_type;
 
 # use of decimal values
 
+--error ER_WRONG_ARGUMENTS
 SET @@global.query_cache_type = 0.4;
 SELECT @@global.query_cache_type;
 
@@ -192,6 +199,7 @@ SET @@global.query_cache_type = 3;
 
 SET @@global.query_cache_type = TRUE;
 SELECT @@global.query_cache_type;
+--error ER_WRONG_ARGUMENTS
 SET @@global.query_cache_type = FALSE;
 SELECT @@global.query_cache_type;
 
@@ -210,6 +218,7 @@ SET global.query_cache_type = 'DEMAND';
 SET session query_cache_type = 1;
 SELECT @@query_cache_type;
 
+--error ER_WRONG_ARGUMENTS
 SET global query_cache_type = 0;
 SELECT @@global.query_cache_type;
 

=== modified file 'mysql-test/t/query_cache_type_func.test'
--- a/mysql-test/t/query_cache_type_func.test	2008-04-10 13:14:28 +0000
+++ b/mysql-test/t/query_cache_type_func.test	2008-10-28 12:13:25 +0000
@@ -85,6 +85,7 @@ SET @@query_cache_type = ON;
 SELECT @@query_cache_type;
 --echo ON Expected
 
+--error ER_WRONG_ARGUMENTS
 SET @@query_cache_type = OFF;
 SELECT @@query_cache_type;
 --echo OFF Expected
@@ -173,26 +174,6 @@ SHOW STATUS LIKE 'Qcache_queries_in_cach
 --echo ==================
 --echo Bug#35388: Stored procedure execution causes improper behavior of query cache.
 
-
---echo '#--------------------FN_DYNVARS_135_06-------------------------#'
-#
-# TESTING FOR VALUE OFF or 0
-#
-
---echo FLUSHING CACHE
-SET @@GLOBAL.query_cache_size = 0;
-SET @@GLOBAL.query_cache_size = 65536;
-
---echo ** Turning cache to OFF **
-
-SET @@query_cache_type = OFF;
-SELECT @@query_cache_type;
-
-SELECT id FROM t1;
-
-SHOW STATUS LIKE 'Qcache_queries_in_cache';
---echo 0 Expected
-
 --echo '#--------------------FN_DYNVARS_135_07-------------------------#'
 #
 # TESTING QUERY WITH SQL_CACHE
@@ -201,12 +182,12 @@ SHOW STATUS LIKE 'Qcache_queries_in_cach
 SELECT SQL_CACHE id FROM t1;
 
 SHOW STATUS LIKE 'Qcache_queries_in_cache';
---echo 0 Expected
+--echo 6 Expected
 
 SELECT SQL_CACHE * FROM t1;
 
 SHOW STATUS LIKE 'Qcache_queries_in_cache';
---echo 0 Expected
+--echo 7 Expected
 
 --echo '#--------------------FN_DYNVARS_135_08-------------------------#'
 #
@@ -243,26 +224,15 @@ SHOW STATUS LIKE 'Qcache_queries_in_cach
 
 --echo ** TESTING GLOBAL SCOPE **
 
---echo '#--------------------FN_DYNVARS_135_10-------------------------#'
+--echo '#--------------------FN_DYNVARS_135_11-------------------------#'
 #
-# Turning global cache to OFF
+# Turning global cache to DEMAND
 #
-
-SET @@GLOBAL.query_cache_type = OFF;
-
 --echo ** Connecting con1 using root **
 connect (con1,localhost,root,,);
 
 --echo ** Connection con1 **
 connection con1;
-
-SELECT @@query_cache_type;
---echo OFF Expected
-
---echo '#--------------------FN_DYNVARS_135_11-------------------------#'
-#
-# Turning global cache to DEMAND
-#
 SET @@GLOBAL.query_cache_type = DEMAND;
 
 --echo ** Connecting con2 using root **

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2008-10-08 15:37:32 +0000
+++ b/sql/set_var.cc	2008-10-28 12:13:25 +0000
@@ -450,9 +450,10 @@ static sys_var_long_ptr	sys_query_cache_
 static sys_var_long_ptr        sys_query_cache_min_res_unit(&vars, "query_cache_min_res_unit",
 						     &query_cache_min_res_unit,
 						     fix_query_cache_min_res_unit);
+static int check_query_cache_type(THD *thd, set_var *var);
 static sys_var_thd_enum	sys_query_cache_type(&vars, "query_cache_type",
 					     &SV::query_cache_type,
-					     &query_cache_type_typelib);
+					     &query_cache_type_typelib, NULL, check_query_cache_type);
 static sys_var_thd_bool
 sys_query_cache_wlock_invalidate(&vars, "query_cache_wlock_invalidate",
 				 &SV::query_cache_wlock_invalidate);
@@ -1103,10 +1104,9 @@ static void fix_net_retry_count(THD *thd
 {}
 #endif /* HAVE_REPLICATION */
 
-
+#ifdef HAVE_QUERY_CACHE
 static void fix_query_cache_size(THD *thd, enum_var_type type)
 {
-#ifdef HAVE_QUERY_CACHE
   ulong new_cache_size= query_cache.resize(query_cache_size);
 
   /*
@@ -1120,11 +1120,43 @@ static void fix_query_cache_size(THD *th
 			query_cache_size, new_cache_size);
   
   query_cache_size= new_cache_size;
-#endif
 }
 
 
-#ifdef HAVE_QUERY_CACHE
+/**
+  Trigger before query_cache_type variable is updated.
+  @param thd Thread handler
+  @param var Pointer to the new variable status
+ 
+  @return Status code
+   @retval 1 Failure
+   @retval 0 Success
+*/
+
+static int check_query_cache_type(THD *thd, set_var *var)
+{
+  /*
+    Don't allow changes of the query_cache_type if the query cache
+    is disabled.
+  */
+  if (query_cache.is_disabled())
+  {
+    my_error(ER_QUERY_CACHE_DISABLED,MYF(0),ER_QUERY_CACHE_DISABLED);
+    return 1;
+  }
+
+  /*
+    Deny any attempt to modify query cache type to OFF in a multi-thread
+    environment.
+    Note: When this function is called the new value is stored in
+     var->save_result.
+  */
+  if (var->save_result.ulong_value == 0)
+    return 1;
+
+  return 0;
+}
+
 static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type)
 {
   query_cache_min_res_unit= 
@@ -3775,6 +3807,16 @@ bool not_all_support_one_shot(List<set_v
   Functions to handle SET mysql_internal_variable=const_expr
 *****************************************************************************/
 
+/**
+  Verify that the supplied value is correct.
+
+  @param thd Thread handler
+
+  @return status code
+   @retval -1 Failure
+   @retval 0 Success
+ */
+
 int set_var::check(THD *thd)
 {
   if (var->is_readonly())

=== modified file 'sql/set_var.h'
--- a/sql/set_var.h	2008-10-08 15:37:32 +0000
+++ b/sql/set_var.h	2008-10-28 12:13:25 +0000
@@ -486,9 +486,22 @@ public:
   bool check(THD *thd, set_var *var)
   {
     int ret= 0;
+    ret= check_enum(thd, var, enum_names);
+
+    /*
+      TRUE means that the character representation supplied was wrong
+      or that the integer value was wrong or missing.
+    */
+    if (ret == TRUE)
+      return TRUE;
+
     if (check_func)
       ret= (*check_func)(thd, var);
-    return ret ? ret : check_enum(thd, var, enum_names);
+
+    if (ret == 1)
+      return TRUE;
+
+    return FALSE;
   }
   bool update(THD *thd, set_var *var);
   void set_default(THD *thd, enum_var_type type);

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2008-10-24 14:17:49 +0000
+++ b/sql/share/errmsg.txt	2008-10-28 12:13:25 +0000
@@ -6409,4 +6409,6 @@ WARN_PLUGIN_DELETE_BUILTIN
 
 WARN_PLUGIN_BUSY
   eng "Plugin is busy and will be uninstalled on shutdown"
+ER_QUERY_CACHE_DISABLED
+  eng "Query cache is disabled from the command line"
 

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2008-10-17 17:47:16 +0000
+++ b/sql/sql_cache.cc	2008-10-28 12:13:25 +0000
@@ -686,7 +686,7 @@ Query_cache::insert(Query_cache_tls *que
   DBUG_ENTER("Query_cache::insert");
 
   /* See the comment on double-check locking usage above. */
-  if (query_cache_tls->first_query_block == NULL)
+  if (is_disabled() || query_cache_tls->first_query_block == NULL)
     DBUG_VOID_RETURN;
 
   DBUG_EXECUTE_IF("wait_in_query_cache_insert",
@@ -753,7 +753,7 @@ Query_cache::abort(Query_cache_tls *quer
   THD *thd= current_thd;
 
   /* See the comment on double-check locking usage above. */
-  if (query_cache_tls->first_query_block == NULL)
+  if (is_disabled() || query_cache_tls->first_query_block == NULL)
     DBUG_VOID_RETURN;
 
   STRUCT_LOCK(&structure_guard_mutex);
@@ -906,7 +906,7 @@ Query_cache::Query_cache(ulong query_cac
    min_result_data_size(ALIGN_SIZE(min_result_data_size_arg)),
    def_query_hash_size(ALIGN_SIZE(def_query_hash_size_arg)),
    def_table_hash_size(ALIGN_SIZE(def_table_hash_size_arg)),
-   initialized(0)
+   initialized(0),m_query_cache_is_disabled(FALSE)
 {
   ulong min_needed= (ALIGN_SIZE(sizeof(Query_cache_block)) +
 		     ALIGN_SIZE(sizeof(Query_cache_block_table)) +
@@ -993,7 +993,7 @@ void Query_cache::store_query(THD *thd, 
 
     See also a note on double-check locking usage above.
   */
-  if (thd->locked_tables_mode || query_cache_size == 0)
+  if (is_disabled() || thd->locked_tables_mode || query_cache_size == 0)
     DBUG_VOID_RETURN;
   uint8 tables_type= 0;
 
@@ -1503,6 +1503,9 @@ void Query_cache::invalidate(THD *thd, T
 {
   DBUG_ENTER("Query_cache::invalidate (table list)");
 
+  if (is_disabled())
+    DBUG_VOID_RETURN;
+  
   using_transactions= using_transactions &&
     (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
   for (; tables_used; tables_used= tables_used->next_local)
@@ -1529,6 +1532,9 @@ 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())
+    DBUG_VOID_RETURN;
+  
   THD *thd= current_thd;
   for (; tables_used; tables_used= tables_used->next)
   {
@@ -1576,7 +1582,10 @@ void Query_cache::invalidate(THD *thd, T
 			     my_bool using_transactions)
 {
   DBUG_ENTER("Query_cache::invalidate (table)");
-  
+
+  if (is_disabled())
+    DBUG_VOID_RETURN;
+
   using_transactions= using_transactions &&
     (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
   if (using_transactions && 
@@ -1593,6 +1602,8 @@ void Query_cache::invalidate(THD *thd, c
 			     my_bool using_transactions)
 {
   DBUG_ENTER("Query_cache::invalidate (key)");
+  if (is_disabled())
+    DBUG_VOID_RETURN;
 
   using_transactions= using_transactions &&
     (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
@@ -1654,7 +1665,8 @@ void Query_cache::invalidate(char *db)
 {
   bool restart= FALSE;
   DBUG_ENTER("Query_cache::invalidate (db)");
-
+  if (is_disabled())
+    DBUG_VOID_RETURN;
   STRUCT_LOCK(&structure_guard_mutex);
   bool interrupt;
   wait_while_table_flush_is_in_progress(&interrupt);
@@ -1742,6 +1754,9 @@ void Query_cache::invalidate_by_MyISAM_f
 void Query_cache::flush()
 {
   DBUG_ENTER("Query_cache::flush");
+  if (is_disabled())
+    DBUG_VOID_RETURN;
+  
   STRUCT_LOCK(&structure_guard_mutex);
   if (query_cache_size > 0)
   {
@@ -1769,7 +1784,8 @@ void Query_cache::flush()
 void Query_cache::pack(ulong join_limit, uint iteration_limit)
 {
   DBUG_ENTER("Query_cache::pack");
-
+  if (is_disabled())
+    DBUG_VOID_RETURN;
   bool interrupt;
   STRUCT_LOCK(&structure_guard_mutex);
   wait_while_table_flush_is_in_progress(&interrupt);
@@ -1829,6 +1845,15 @@ void Query_cache::init()
   pthread_cond_init(&COND_cache_status_changed, NULL);
   m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS;
   initialized = 1;
+  /*
+    If we explicitly turn off query cache from the command line query cache will
+    be disabled for the reminder of the server life time. This is because we
+    want to avoid locking the QC specific mutex if query cache isn't going to
+    be used.
+  */
+  if (global_system_variables.query_cache_type == 0)
+    query_cache.disable_query_cache();
+
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/sql_cache.h'
--- a/sql/sql_cache.h	2008-08-10 14:49:52 +0000
+++ b/sql/sql_cache.h	2008-10-28 12:13:25 +0000
@@ -280,7 +280,7 @@ private:
                       TABLE_FLUSH_IN_PROGRESS };
 
   Cache_status m_cache_status;
-
+  bool m_query_cache_is_disabled;
   void free_query_internal(Query_cache_block *point);
   void invalidate_table_internal(THD *thd, uchar *key, uint32 key_length);
 
@@ -428,6 +428,9 @@ protected:
 	      uint def_query_hash_size = QUERY_CACHE_DEF_QUERY_HASH_SIZE,
 	      uint def_table_hash_size = QUERY_CACHE_DEF_TABLE_HASH_SIZE);
 
+  bool is_disabled(void) { return m_query_cache_is_disabled; }
+  void disable_query_cache(void) { m_query_cache_is_disabled= TRUE; }
+
   /* initialize cache (mutex) */
   void init();
   /* resize query cache (return real query size, 0 if disabled) */

Thread
bzr commit into mysql-6.0 branch (kristofer.pettersson:2742) Bug#38551Kristofer Pettersson28 Oct
  • Re: bzr commit into mysql-6.0 branch (kristofer.pettersson:2742)Bug#38551Davi Arnaut28 Oct