From 1dff783854d165611beb35a14f7ee7c853903bd6 Mon Sep 17 00:00:00 2001 From: "bell@52.0.168.192.in-addr.arpa" <> Date: Wed, 10 Aug 2005 18:58:55 +0300 Subject: [PATCH] block using QC in case of having tables locked by LOCK... (BUG#12385) --- mysql-test/r/query_cache_noembeded.result | 18 +++++++++++++ mysql-test/t/query_cache_noembeded.test | 33 +++++++++++++++++++++++ sql/sql_cache.cc | 7 +++-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 mysql-test/r/query_cache_noembeded.result create mode 100644 mysql-test/t/query_cache_noembeded.test diff --git a/mysql-test/r/query_cache_noembeded.result b/mysql-test/r/query_cache_noembeded.result new file mode 100644 index 00000000000..f2b06eea45d --- /dev/null +++ b/mysql-test/r/query_cache_noembeded.result @@ -0,0 +1,18 @@ +set GLOBAL query_cache_size=1355776; +reset query cache; +flush status; +CREATE TABLE t1 ( a INT NOT NULL PRIMARY KEY AUTO_INCREMENT ) ENGINE = +MyISAM; +LOCK TABLE t1 READ LOCAL; +INSERT INTO t1 VALUES (), (), (); +SELECT * FROM t1; +a +SELECT * FROM t1; +a +1 +2 +3 +SELECT * FROM t1; +a +drop table t1; +set GLOBAL query_cache_size=default; diff --git a/mysql-test/t/query_cache_noembeded.test b/mysql-test/t/query_cache_noembeded.test new file mode 100644 index 00000000000..c909bfcdf3b --- /dev/null +++ b/mysql-test/t/query_cache_noembeded.test @@ -0,0 +1,33 @@ +-- source include/have_query_cache.inc +-- source include/not_embedded.inc + +# +# Tests with query cache +# +set GLOBAL query_cache_size=1355776; + +# Reset query cache variables. + +reset query cache; +flush status; + +# +# do not use QC if tables locked (BUG#12385) +# +connect (root,localhost,root,,test,$MASTER_MYPORT,master.sock); +connection root; +CREATE TABLE t1 ( a INT NOT NULL PRIMARY KEY AUTO_INCREMENT ) ENGINE = +MyISAM; +LOCK TABLE t1 READ LOCAL; +connect (root2,localhost,root,,test,$MASTER_MYPORT,master.sock); +connection root2; +INSERT INTO t1 VALUES (), (), (); +connection root; +SELECT * FROM t1; +connection root2; +SELECT * FROM t1; +connection root; +SELECT * FROM t1; +drop table t1; + +set GLOBAL query_cache_size=default; diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index d729a6cc301..667b6e546d3 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -739,7 +739,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) TABLE_COUNTER_TYPE local_tables; ulong tot_length; DBUG_ENTER("Query_cache::store_query"); - if (query_cache_size == 0) + if (query_cache_size == 0 || thd->locked_tables) DBUG_VOID_RETURN; if ((local_tables= is_cacheable(thd, thd->query_length, @@ -750,7 +750,10 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) STRUCT_LOCK(&structure_guard_mutex); if (query_cache_size == 0) + { + STRUCT_UNLOCK(&structure_guard_mutex); DBUG_VOID_RETURN; + } DUMP(this); /* Key is query + database + flag */ @@ -874,7 +877,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) byte flags; DBUG_ENTER("Query_cache::send_result_to_client"); - if (query_cache_size == 0 || + if (query_cache_size == 0 || thd->locked_tables || /* it is not possible to check has_transactions() function of handler because tables not opened yet