Skip to content

Commit 2c4b6dc

Browse files
author
Jon Olav Hauglid
committed
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.
1 parent 3eead1f commit 2c4b6dc

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

mysql-test/r/implicit_commit.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ YES
658658
#
659659
# SQLCOM_RESET
660660
#
661+
INSERT INTO db1.trans (a) VALUES (1);
662+
reset query cache;
663+
CALL db1.test_if_commit();
664+
IMPLICIT COMMIT
665+
YES
661666
#
662667
# SQLCOM_PURGE
663668
#

mysql-test/r/query_cache.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,3 +1721,14 @@ SELECT SQL_CACHE * FROM t1 WHERE a IN
17211721
ERROR 42S22: Unknown column 'SQL_NO_CACHE' in 'field list'
17221722
DROP TABLE t1;
17231723
End of 5.1 tests
1724+
#
1725+
# Bug#51336 Assert in reload_acl_and_cache during RESET QUERY CACHE
1726+
#
1727+
DROP TABLE IF EXISTS t1;
1728+
CREATE TABLE t1(id INT);
1729+
START TRANSACTION;
1730+
SELECT * FROM t1;
1731+
id
1732+
RESET QUERY CACHE;
1733+
COMMIT;
1734+
DROP TABLE t1;

mysql-test/t/implicit_commit.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ source include/implicit_commit_helper.inc;
697697
--echo # SQLCOM_RESET
698698
--echo #
699699

700+
let $statement=
701+
reset query cache;
702+
source include/implicit_commit_helper.inc;
703+
700704
--echo #
701705
--echo # SQLCOM_PURGE
702706
--echo #

mysql-test/t/query_cache.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,3 +1363,22 @@ SELECT SQL_CACHE * FROM t1 WHERE a IN
13631363
DROP TABLE t1;
13641364

13651365
--echo End of 5.1 tests
1366+
1367+
1368+
--echo #
1369+
--echo # Bug#51336 Assert in reload_acl_and_cache during RESET QUERY CACHE
1370+
--echo #
1371+
1372+
--disable_warnings
1373+
DROP TABLE IF EXISTS t1;
1374+
--enable_warnings
1375+
1376+
CREATE TABLE t1(id INT);
1377+
1378+
START TRANSACTION;
1379+
SELECT * FROM t1;
1380+
# This caused an assert
1381+
RESET QUERY CACHE;
1382+
1383+
COMMIT;
1384+
DROP TABLE t1;

sql/log_event.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
25212521
case SQLCOM_ASSIGN_TO_KEYCACHE:
25222522
case SQLCOM_PRELOAD_KEYS:
25232523
case SQLCOM_FLUSH:
2524+
case SQLCOM_RESET:
25242525
case SQLCOM_CHECK:
25252526
implicit_commit= TRUE;
25262527
break;

sql/sql_parse.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ void init_update_queries(void)
325325
sql_command_flags[SQLCOM_PRELOAD_KEYS]= CF_AUTO_COMMIT_TRANS;
326326

327327
sql_command_flags[SQLCOM_FLUSH]= CF_AUTO_COMMIT_TRANS;
328+
sql_command_flags[SQLCOM_RESET]= CF_AUTO_COMMIT_TRANS;
328329
sql_command_flags[SQLCOM_CHECK]= CF_AUTO_COMMIT_TRANS;
329330
}
330331

0 commit comments

Comments
 (0)