From: Mattias Jonsson Date: December 16 2011 10:19pm Subject: bzr push into mysql-trunk branch (mattias.jonsson:3672 to 3673) WL#4443 List-Archive: http://lists.mysql.com/commits/142162 Message-Id: <201112162219.pBGMJOF2029626@acsmt358.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3673 Mattias Jonsson 2011-12-16 WL#4443 fixing query cache tests Reverted back to storing queries in the query cache after the tables was locked. This makes transactional storage engines work with the query cache since they can use the lock as signal to start a new transaktion. This also means that queries that fails (like on access control) before the tables are locked is not registered and is not included in Qcache_not_cached status variable. modified: mysql-test/r/grant_cache_no_prot.result sql/sql_select.cc sql/sql_union.cc 3672 Mattias Jonsson 2011-12-16 WL#4443 test fixes main.type_date had bad result, changed opt_trace.bugs_no_prot_none changed trace due to no subquery executions during prepare phase. removed unused variables store_in_query_cache. modified: mysql-test/r/type_date.result mysql-test/suite/opt_trace/r/bugs_no_prot_none.result mysql-test/t/type_date.test sql/sql_select.cc sql/sql_union.cc === modified file 'mysql-test/r/grant_cache_no_prot.result' --- a/mysql-test/r/grant_cache_no_prot.result 2010-08-09 08:32:50 +0000 +++ b/mysql-test/r/grant_cache_no_prot.result 2011-12-16 22:18:36 +0000 @@ -176,7 +176,7 @@ Variable_name Value Qcache_hits 7 show status like "Qcache_not_cached"; Variable_name Value -Qcache_not_cached 7 +Qcache_not_cached 4 ----- establish connection user4 (user=mysqltest_1) ----- select "user4"; user4 @@ -207,7 +207,7 @@ Variable_name Value Qcache_hits 8 show status like "Qcache_not_cached"; Variable_name Value -Qcache_not_cached 8 +Qcache_not_cached 5 ----- close connections ----- ----- switch to connection default ----- set names binary; === modified file 'sql/sql_select.cc' --- a/sql/sql_select.cc 2011-12-16 21:46:26 +0000 +++ b/sql/sql_select.cc 2011-12-16 22:18:36 +0000 @@ -1183,6 +1183,7 @@ mysql_select(THD *thd, SELECT_LEX *select_lex) { bool free_join= 1; + bool store_in_query_cache= false; uint og_num= 0; ORDER *first_order= NULL; ORDER *first_group= NULL; @@ -1205,7 +1206,7 @@ mysql_select(THD *thd, /* Only register the query if it was opened above. */ if (thd->lex->tables_state < Query_tables_list::TABLES_STATE_LOCKED) - query_cache_store_query(thd, thd->lex->query_tables); + store_in_query_cache= true; if (mysql_prepare_select(thd, tables, wild_num, fields, conds, og_num, first_order, first_group, having, @@ -1230,6 +1231,13 @@ mysql_select(THD *thd, DBUG_RETURN(true); } + /* + We must wait after locking to store the query in the query cache. + Transactional engines must been signalled that the statement started. + */ + if (store_in_query_cache) + query_cache_store_query(thd, thd->lex->query_tables); + if (mysql_execute_select(thd, select_lex, free_join, join)) DBUG_RETURN(true); === modified file 'sql/sql_union.cc' --- a/sql/sql_union.cc 2011-12-16 21:46:26 +0000 +++ b/sql/sql_union.cc 2011-12-16 22:18:36 +0000 @@ -33,6 +33,7 @@ bool mysql_union(THD *thd, LEX *lex, sel SELECT_LEX_UNIT *unit, ulong setup_tables_done_option) { bool res; + bool store_in_query_cache= false; DBUG_ENTER("mysql_union"); if (open_query_tables(thd)) @@ -40,7 +41,7 @@ bool mysql_union(THD *thd, LEX *lex, sel /* Only register the query if it was opened above */ if (thd->lex->tables_state < Query_tables_list::TABLES_STATE_LOCKED) - query_cache_store_query(thd, thd->lex->query_tables); + store_in_query_cache= true; res= unit->prepare(thd, result, SELECT_NO_UNLOCK | setup_tables_done_option); @@ -50,6 +51,13 @@ bool mysql_union(THD *thd, LEX *lex, sel if (lock_query_tables(thd)) goto err; + /* + We must wait after locking to store the query in the query cache. + Transactional engines must been signalled that the statement started. + */ + if (store_in_query_cache) + query_cache_store_query(thd, thd->lex->query_tables); + res= unit->optimize() || unit->exec(); res|= unit->cleanup(); DBUG_RETURN(res); No bundle (reason: useless for push emails).