Skip to content

Commit b5ab295

Browse files
author
Ajo Robert
committed
Bug#36784795 Query rewrite plugin not working when server runs with
autocommit=OFF Query rewrite plugin reload rules logic runs in an independent thread created when a request is submitted. This thread runs the reload logic and exits. When the server is in global autocommit OFF mode, the new thread and its session will also run with autocommit OFF mode. At the end of the reload execution, the code does a statement commit and exist. Statement commits does not preserve the changes in autocommit OFF mode. Due to this, after the thread exits, any table data changes done will be lost. Fix: Perform a transaction commit to ensure all changes are preserved before exiting the session/thread. Change-Id: Ib6f96873f90d99b2c53bb0157e91b160760b933e
1 parent 2aa9a55 commit b5ab295

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

mysql-test/suite/query_rewrite_plugins/r/transactions.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,25 @@ SET autocommit = DEFAULT;
176176
Warnings:
177177
Warning 1620 Plugin is busy and will be uninstalled on shutdown
178178
# Query rewrite plugin was queued for uninstalling.
179+
#
180+
# Bug#36784795 Query rewrite plugin not working when server runs with
181+
# autocommit=OFF
182+
#
183+
# Query rewrite plugin was installed.
184+
SET GLOBAL autocommit = 0;
185+
SET SESSION autocommit = ON;
186+
DELETE FROM query_rewrite.rewrite_rules;
187+
INSERT INTO query_rewrite.rewrite_rules (pattern, replacement)
188+
VALUES('SELECT ?', 'SELECT ? + 1');
189+
SELECT * FROM query_rewrite.rewrite_rules;
190+
id pattern pattern_database replacement enabled message pattern_digest normalized_pattern
191+
1 SELECT ? NULL SELECT ? + 1 YES NULL NULL NULL
192+
CALL query_rewrite.flush_rewrite_rules();
193+
SELECT * FROM query_rewrite.rewrite_rules;
194+
id pattern pattern_database replacement enabled message pattern_digest normalized_pattern
195+
1 SELECT ? NULL SELECT ? + 1 YES NULL d1b44b0c19af710b5a679907e284acd2ddc285201794bc69a2389d77baedddae select ?
196+
SET GLOBAL autocommit = DEFAULT;
197+
SET SESSION autocommit = DEFAULT;
198+
Warnings:
199+
Warning 1620 Plugin is busy and will be uninstalled on shutdown
200+
# Query rewrite plugin was queued for uninstalling.

mysql-test/suite/query_rewrite_plugins/t/transactions.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,25 @@ SELECT load_rewrite_rules();
131131
SELECT 'Rewrite me';
132132

133133
SET autocommit = DEFAULT;
134+
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
135+
--source include/disconnect_connections.inc
136+
137+
--echo #
138+
--echo # Bug#36784795 Query rewrite plugin not working when server runs with
139+
--echo # autocommit=OFF
140+
--echo #
141+
--source suite/query_rewrite_plugins/include/install_rewriter_with_optional_columns.inc
142+
143+
SET GLOBAL autocommit = 0;
144+
SET SESSION autocommit = ON;
145+
#Session autocommit is not needed to set to OFF for this test.
146+
DELETE FROM query_rewrite.rewrite_rules;
147+
INSERT INTO query_rewrite.rewrite_rules (pattern, replacement)
148+
VALUES('SELECT ?', 'SELECT ? + 1');
149+
SELECT * FROM query_rewrite.rewrite_rules;
150+
CALL query_rewrite.flush_rewrite_rules();
151+
SELECT * FROM query_rewrite.rewrite_rules;
152+
SET GLOBAL autocommit = DEFAULT;
153+
SET SESSION autocommit = DEFAULT;
134154

135155
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc

sql/parser_service.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void *parser_service_start_routine(void *arg) {
183183
(tt->m_fun)(tt->m_arg);
184184

185185
trans_commit_stmt(thd);
186+
trans_commit(thd);
186187
close_thread_tables(thd);
187188
thd->mdl_context.release_transactional_locks();
188189
close_mysql_tables(thd);

0 commit comments

Comments
 (0)