Commit a42cbe06 authored by Jon Olav Hauglid's avatar Jon Olav Hauglid

Bug #51336 Assert in reload_acl_and_cache during RESET QUERY CACHE

Attempts to execute RESET statements within a transaction that
had acquired metadata locks, led to an assertion failure on 
debug servers. This bug didn't cause any problems on release
builds.

The triggered assert is designed to check that caches are not
flushed or reset while having active transactions. It is triggered
if acquired metadata locks exist that are not from LOCK TABLE or
HANDLER statements.

In this case it was triggered by RESET QUERY CACHE while having
an active transaction that had acquired locks. The reason the
assertion was triggered, was that RESET statements, unlike the
similar FLUSH statements, was not causing an implicit commit.

This patch fixes the problem by making sure RESET statements
commit the current transaction before executing. The commit
causes acquired metadata locks to be released, preventing the
assertion from being triggered.

Incompatible change: This patch changes RESET statements so
that they cause an implicit commit.

Test case added to query_cache.test.
parent 3f1a9baf
...@@ -658,6 +658,11 @@ YES ...@@ -658,6 +658,11 @@ YES
# #
# SQLCOM_RESET # SQLCOM_RESET
# #
INSERT INTO db1.trans (a) VALUES (1);
reset query cache;
CALL db1.test_if_commit();
IMPLICIT COMMIT
YES
# #
# SQLCOM_PURGE # SQLCOM_PURGE
# #
......
...@@ -1721,3 +1721,14 @@ SELECT SQL_CACHE * FROM t1 WHERE a IN ...@@ -1721,3 +1721,14 @@ SELECT SQL_CACHE * FROM t1 WHERE a IN
ERROR 42S22: Unknown column 'SQL_NO_CACHE' in 'field list' ERROR 42S22: Unknown column 'SQL_NO_CACHE' in 'field list'
DROP TABLE t1; DROP TABLE t1;
End of 5.1 tests End of 5.1 tests
#
# Bug#51336 Assert in reload_acl_and_cache during RESET QUERY CACHE
#
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(id INT);
START TRANSACTION;
SELECT * FROM t1;
id
RESET QUERY CACHE;
COMMIT;
DROP TABLE t1;
...@@ -697,6 +697,10 @@ source include/implicit_commit_helper.inc; ...@@ -697,6 +697,10 @@ source include/implicit_commit_helper.inc;
--echo # SQLCOM_RESET --echo # SQLCOM_RESET
--echo # --echo #
let $statement=
reset query cache;
source include/implicit_commit_helper.inc;
--echo # --echo #
--echo # SQLCOM_PURGE --echo # SQLCOM_PURGE
--echo # --echo #
......
...@@ -1363,3 +1363,22 @@ SELECT SQL_CACHE * FROM t1 WHERE a IN ...@@ -1363,3 +1363,22 @@ SELECT SQL_CACHE * FROM t1 WHERE a IN
DROP TABLE t1; DROP TABLE t1;
--echo End of 5.1 tests --echo End of 5.1 tests
--echo #
--echo # Bug#51336 Assert in reload_acl_and_cache during RESET QUERY CACHE
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1(id INT);
START TRANSACTION;
SELECT * FROM t1;
# This caused an assert
RESET QUERY CACHE;
COMMIT;
DROP TABLE t1;
...@@ -2521,6 +2521,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, ...@@ -2521,6 +2521,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
case SQLCOM_ASSIGN_TO_KEYCACHE: case SQLCOM_ASSIGN_TO_KEYCACHE:
case SQLCOM_PRELOAD_KEYS: case SQLCOM_PRELOAD_KEYS:
case SQLCOM_FLUSH: case SQLCOM_FLUSH:
case SQLCOM_RESET:
case SQLCOM_CHECK: case SQLCOM_CHECK:
implicit_commit= TRUE; implicit_commit= TRUE;
break; break;
......
...@@ -325,6 +325,7 @@ void init_update_queries(void) ...@@ -325,6 +325,7 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_PRELOAD_KEYS]= CF_AUTO_COMMIT_TRANS; sql_command_flags[SQLCOM_PRELOAD_KEYS]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_FLUSH]= CF_AUTO_COMMIT_TRANS; sql_command_flags[SQLCOM_FLUSH]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_RESET]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CHECK]= CF_AUTO_COMMIT_TRANS; sql_command_flags[SQLCOM_CHECK]= CF_AUTO_COMMIT_TRANS;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment