summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2004-03-04 18:32:55 +0200
committerunknown <bell@sanja.is.com.ua>2004-03-04 18:32:55 +0200
commit8ea9621c5ad6af7ed890475000c07cef3ce7accf (patch)
treef122123efc8dd764d21d073a89045021aecd2992 /sql
parent1471b9fcfdfffb1f791a4f7e974be1739abc25d6 (diff)
downloadmariadb-git-8ea9621c5ad6af7ed890475000c07cef3ce7accf.tar.gz
invalidation of locking for write tables (BUG#2693)
fixed linking query_prealloc_size to query cache presence mysql-test/r/query_cache.result: test of QC invalidation by LOCK command mysql-test/t/query_cache.test: test of QC invalidation by LOCK command sql/mysqld.cc: new variable query_cache_wlock_invalidate fixed query_prealloc_size with QC absence sql/set_var.cc: new variable query_cache_wlock_invalidate sql/sql_cache.cc: new method for table invalidation sql/sql_cache.h: new method for table invalidation sql/sql_class.h: new variable query_cache_wlock_invalidate sql/sql_parse.cc: layout fixed
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc9
-rw-r--r--sql/set_var.cc4
-rw-r--r--sql/sql_cache.cc31
-rw-r--r--sql/sql_cache.h1
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_parse.cc6
6 files changed, 49 insertions, 3 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index b4c5ce33277..b63f903263e 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3228,7 +3228,7 @@ enum options_mysqld {
OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
OPT_OPEN_FILES_LIMIT,
OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_SIZE,
- OPT_QUERY_CACHE_TYPE, OPT_RECORD_BUFFER,
+ OPT_QUERY_CACHE_TYPE, OPT_QUERY_CACHE_WLOCK_INVALIDATE, OPT_RECORD_BUFFER,
OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT,
OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
OPT_READONLY, OPT_DEBUGGING,
@@ -4015,12 +4015,17 @@ this value; if zero (the default): when the size exceeds max_binlog_size. \
(gptr*) &global_system_variables.query_cache_type,
(gptr*) &max_system_variables.query_cache_type,
0, GET_ULONG, REQUIRED_ARG, 1, 0, 2, 0, 1, 0},
+ {"query_cache_wlock_invalidate", OPT_QUERY_CACHE_WLOCK_INVALIDATE,
+ "Invalidate queries in query cache on LOCK for write",
+ (gptr*) &global_system_variables.query_cache_wlock_invalidate,
+ (gptr*) &max_system_variables.query_cache_wlock_invalidate,
+ 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
+#endif /*HAVE_QUERY_CACHE*/
{"query_prealloc_size", OPT_QUERY_PREALLOC_SIZE,
"Persistent buffer for query parsing and execution",
(gptr*) &global_system_variables.query_prealloc_size,
(gptr*) &max_system_variables.query_prealloc_size, 0, GET_ULONG,
REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, 1024, ~0L, 0, 1024, 0},
-#endif /*HAVE_QUERY_CACHE*/
{"read_buffer_size", OPT_RECORD_BUFFER,
"Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value.",
(gptr*) &global_system_variables.read_buff_size,
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 9b605cacb97..d0c21ef293a 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -229,6 +229,9 @@ sys_var_long_ptr sys_query_cache_limit("query_cache_limit",
sys_var_thd_enum sys_query_cache_type("query_cache_type",
&SV::query_cache_type,
&query_cache_type_typelib);
+sys_var_thd_bool
+sys_query_cache_wlock_invalidate("query_cache_wlock_invalidate",
+ &SV::query_cache_wlock_invalidate);
#endif /* HAVE_QUERY_CACHE */
sys_var_long_ptr sys_server_id("server_id",&server_id);
sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol",
@@ -405,6 +408,7 @@ sys_var *sys_variables[]=
#ifdef HAVE_QUERY_CACHE
&sys_query_cache_limit,
&sys_query_cache_type,
+ &sys_query_cache_wlock_invalidate,
#endif /* HAVE_QUERY_CACHE */
&sys_quote_show_create,
&sys_rand_seed1,
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 63d4e4222b4..77bdcb79a8d 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1090,6 +1090,37 @@ void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used)
DBUG_VOID_RETURN;
}
+
+/*
+ Invalidate locked for write
+
+ SYNOPSIS
+ Query_cache::invalidate_locked_for_write()
+ tables_used - table list
+
+ NOTE
+ can be used only for opened tables
+*/
+void Query_cache::invalidate_locked_for_write(TABLE_LIST *tables_used)
+{
+ DBUG_ENTER("Query_cache::invalidate (changed table list)");
+ if (query_cache_size > 0 && tables_used)
+ {
+ STRUCT_LOCK(&structure_guard_mutex);
+ if (query_cache_size > 0)
+ {
+ DUMP(this);
+ for (; tables_used; tables_used= tables_used->next)
+ {
+ if (tables_used->lock_type & (TL_WRITE_LOW_PRIORITY | TL_WRITE))
+ invalidate_table(tables_used->table);
+ }
+ }
+ STRUCT_UNLOCK(&structure_guard_mutex);
+ }
+ DBUG_VOID_RETURN;
+}
+
/*
Remove all cached queries that uses the given table
*/
diff --git a/sql/sql_cache.h b/sql/sql_cache.h
index 74b1a6cee96..0c6579250ab 100644
--- a/sql/sql_cache.h
+++ b/sql/sql_cache.h
@@ -360,6 +360,7 @@ protected:
void invalidate(THD* thd, TABLE_LIST *tables_used,
my_bool using_transactions);
void invalidate(CHANGED_TABLE_LIST *tables_used);
+ void invalidate_locked_for_write(TABLE_LIST *tables_used);
void invalidate(THD* thd, TABLE *table, my_bool using_transactions);
void invalidate(THD *thd, const char *key, uint32 key_length,
my_bool using_transactions);
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d96c6bb53cc..85724e7c83f 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -336,6 +336,7 @@ struct system_variables
my_bool log_warnings;
my_bool low_priority_updates;
my_bool new_mode;
+ my_bool query_cache_wlock_invalidate;
CONVERT *convert_set;
};
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ac3ccd4fc62..bc69f7136ad 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2307,8 +2307,12 @@ mysql_execute_command(void)
goto error;
thd->in_lock_tables=1;
thd->options|= OPTION_TABLE_LOCK;
- if (!(res=open_and_lock_tables(thd,tables)))
+ if (!(res= open_and_lock_tables(thd, tables)))
{
+#ifdef HAVE_QUERY_CACHE
+ if (thd->variables.query_cache_wlock_invalidate)
+ query_cache.invalidate_locked_for_write(tables);
+#endif /*HAVE_QUERY_CACHE*/
thd->locked_tables=thd->lock;
thd->lock=0;
send_ok(&thd->net);