diff options
author | bell@sanja.is.com.ua <> | 2004-03-04 18:32:55 +0200 |
---|---|---|
committer | bell@sanja.is.com.ua <> | 2004-03-04 18:32:55 +0200 |
commit | d03034d3062f528266ac4853ab2f2ba17f01dfdb (patch) | |
tree | f122123efc8dd764d21d073a89045021aecd2992 | |
parent | f8345cc6171edd0cbe78900975b16ed8d77f67d3 (diff) | |
download | mariadb-git-d03034d3062f528266ac4853ab2f2ba17f01dfdb.tar.gz |
invalidation of locking for write tables (BUG#2693)
fixed linking query_prealloc_size to query cache presence
-rw-r--r-- | mysql-test/r/query_cache.result | 17 | ||||
-rw-r--r-- | mysql-test/t/query_cache.test | 17 | ||||
-rw-r--r-- | sql/mysqld.cc | 9 | ||||
-rw-r--r-- | sql/set_var.cc | 4 | ||||
-rw-r--r-- | sql/sql_cache.cc | 31 | ||||
-rw-r--r-- | sql/sql_cache.h | 1 | ||||
-rw-r--r-- | sql/sql_class.h | 1 | ||||
-rw-r--r-- | sql/sql_parse.cc | 6 |
8 files changed, 82 insertions, 4 deletions
diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index c7554211a1a..a9e9f167e5f 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -687,4 +687,21 @@ select * from t3; delete from t4 where a=1; flush query cache; drop table t1,t2,t3,t4; +set query_cache_wlock_invalidate=1; +create table t1 (a int not null); +create table t2 (a int not null); +select * from t1; +a +select * from t2; +a +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 2 +lock table t1 write, t2 read; +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 1 +unlock table; +drop table t1,t2; +set query_cache_wlock_invalidate=default; set GLOBAL query_cache_size=0; diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index ad0dc80e2f7..8a07c0a53a0 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -504,6 +504,21 @@ select * from t3; enable_result_log; delete from t4 where a=1; flush query cache; - drop table t1,t2,t3,t4; + +# +# WRITE LOCK & QC +# +set query_cache_wlock_invalidate=1; +create table t1 (a int not null); +create table t2 (a int not null); +select * from t1; +select * from t2; +show status like "Qcache_queries_in_cache"; +lock table t1 write, t2 read; +show status like "Qcache_queries_in_cache"; +unlock table; +drop table t1,t2; +set query_cache_wlock_invalidate=default; + set GLOBAL query_cache_size=0; 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); |