Merge lp:~laurynas-biveinis/percona-server/bug1387951 into lp:percona-server/5.6

Proposed by Laurynas Biveinis
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: 735
Merged at revision: 736
Proposed branch: lp:~laurynas-biveinis/percona-server/bug1387951
Merge into: lp:percona-server/5.6
Diff against target: 150 lines (+82/-6)
3 files modified
mysql-test/r/percona_statement_set.result (+29/-2)
mysql-test/t/percona_statement_set.test (+48/-2)
sql/sql_parse.cc (+5/-2)
To merge this branch: bzr merge lp:~laurynas-biveinis/percona-server/bug1387951
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+248575@code.launchpad.net

Description of the change

Fix SET STATEMENT ... FOR <statement> crashes:
1) if <statement> needs to commit implicitly and fails (bug 1418049);
2) if <statement> is RW in a RO transaction (bug 1387951);
3) if <statement> is needs to reopen a temp table and fails (bug 1412423).

All three bugs are related and caused by mysql_execute_command jumping
over to an error exit (one goto per each bug) and thus skipping
per_query_variables_backup variable initialization. But the cleanup of
restoring thd->variables from the uninitialzied variable still
happened. Fixed trivially.

This bug was also indicated by a compilation warning:

07:37:58 /home/jenkins/workspace/percona-server-5.6-debian-binary-32/label_exp/debian6-32/percona-server-5.6-5.6.22-71.0/sql/sql_parse.cc: In function 'int mysql_execute_command(THD*)':
07:37:58
/home/jenkins/workspace/percona-server-5.6-debian-binary-32/label_exp/debian6-32/percona-server-5.6-5.6.22-71.0/sql/sql_parse.cc:2609:
error: 'per_query_variables_backup' may be used uninitialized in this
function

fixing which is part of bug 1408232.

Added testcases.

http://jenkins.percona.com/job/percona-server-5.6-param/805/

To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'mysql-test/r/percona_statement_set.result'
--- mysql-test/r/percona_statement_set.result 2013-09-27 17:47:04 +0000
+++ mysql-test/r/percona_statement_set.result 2015-02-04 16:26:16 +0000
@@ -8,7 +8,7 @@
8DROP PROCEDURE IF EXISTS p5;8DROP PROCEDURE IF EXISTS p5;
9DROP TABLE IF EXISTS STATEMENT;9DROP TABLE IF EXISTS STATEMENT;
10'# Setup database'10'# Setup database'
11CREATE TABLE t1 (v1 INT, v2 INT);11CREATE TABLE t1 (v1 INT, v2 INT) ENGINE=MyISAM;
12INSERT INTO t1 VALUES (1,2);12INSERT INTO t1 VALUES (1,2);
13INSERT INTO t1 VALUES (3,4);13INSERT INTO t1 VALUES (3,4);
14''14''
@@ -852,9 +852,36 @@
852'#------------------Test 22-----------------------#'852'#------------------Test 22-----------------------#'
853CREATE TABLE STATEMENT(a INT);853CREATE TABLE STATEMENT(a INT);
854DROP TABLE STATEMENT;854DROP TABLE STATEMENT;
855Test for bug 1418049: SET STATEMENT ... FOR <statement> crashes server
856if <statement> needs to commit implicitly and fails
857CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
858SET @old_lock_wait_timeout = @@session.lock_wait_timeout;
859SET SESSION lock_wait_timeout = 1;
860BEGIN;
861INSERT INTO t2 VALUES (5);
862FLUSH TABLES WITH READ LOCK;
863SET STATEMENT max_join_size = 0 FOR DROP TABLE t2;
864ERROR HY000: Lock wait timeout exceeded; try restarting transaction
865UNLOCK TABLES;
866COMMIT;
867SET SESSION lock_wait_timeout = @old_lock_wait_timeout;
868Test for bug 1387951: SET STATEMENT ... FOR <statement> crashes server
869if <statement> is RW in a RO transaction
870SET @old_tx_read_only = @@session.tx_read_only;
871SET SESSION tx_read_only = TRUE;
872SET STATEMENT myisam_repair_threads=0 FOR OPTIMIZE TABLE t0;
873ERROR 25006: Cannot execute statement in a READ ONLY transaction.
874SET SESSION tx_read_only = @old_tx_read_only;
875Test for bug 1412423: SET STATEMENT ... FOR <statement> crashes server
876if <statement> needs to re-open a temp table and fails
877CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB;
878HANDLER t3 OPEN;
879SET STATEMENT max_join_size=1000 FOR SELECT * FROM t3;
880ERROR HY000: Can't reopen table: 't3'
881DROP TABLE t3;
855''882''
856'# Cleanup'883'# Cleanup'
857DROP TABLE t1;884DROP TABLE t1, t2;
858DROP PROCEDURE p1;885DROP PROCEDURE p1;
859DROP PROCEDURE p2;886DROP PROCEDURE p2;
860DROP PROCEDURE p3;887DROP PROCEDURE p3;
861888
=== modified file 'mysql-test/t/percona_statement_set.test'
--- mysql-test/t/percona_statement_set.test 2013-09-27 17:47:04 +0000
+++ mysql-test/t/percona_statement_set.test 2015-02-04 16:26:16 +0000
@@ -1,3 +1,5 @@
1--source include/have_innodb.inc
2--source include/count_sessions.inc
1--echo '# SET STATEMENT ..... FOR .... TEST'3--echo '# SET STATEMENT ..... FOR .... TEST'
2############################ STATEMENT_SET #############################4############################ STATEMENT_SET #############################
3# #5# #
@@ -28,7 +30,7 @@
28#Set up current database30#Set up current database
29####################################################################31####################################################################
30--echo '# Setup database'32--echo '# Setup database'
31CREATE TABLE t1 (v1 INT, v2 INT);33CREATE TABLE t1 (v1 INT, v2 INT) ENGINE=MyISAM;
32INSERT INTO t1 VALUES (1,2);34INSERT INTO t1 VALUES (1,2);
33INSERT INTO t1 VALUES (3,4);35INSERT INTO t1 VALUES (3,4);
34--echo ''36--echo ''
@@ -820,11 +822,55 @@
820CREATE TABLE STATEMENT(a INT);822CREATE TABLE STATEMENT(a INT);
821DROP TABLE STATEMENT;823DROP TABLE STATEMENT;
822824
825--echo Test for bug 1418049: SET STATEMENT ... FOR <statement> crashes server
826--echo if <statement> needs to commit implicitly and fails
827
828CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
829
830SET @old_lock_wait_timeout = @@session.lock_wait_timeout;
831SET SESSION lock_wait_timeout = 1;
832
833BEGIN;
834INSERT INTO t2 VALUES (5);
835
836--connect(con1,localhost,root,,)
837--connection con1
838FLUSH TABLES WITH READ LOCK;
839
840--connection default
841--error ER_LOCK_WAIT_TIMEOUT
842SET STATEMENT max_join_size = 0 FOR DROP TABLE t2;
843
844--connection con1
845UNLOCK TABLES;
846--disconnect con1
847--connection default
848COMMIT;
849SET SESSION lock_wait_timeout = @old_lock_wait_timeout;
850
851--echo Test for bug 1387951: SET STATEMENT ... FOR <statement> crashes server
852--echo if <statement> is RW in a RO transaction
853SET @old_tx_read_only = @@session.tx_read_only;
854SET SESSION tx_read_only = TRUE;
855--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
856SET STATEMENT myisam_repair_threads=0 FOR OPTIMIZE TABLE t0;
857SET SESSION tx_read_only = @old_tx_read_only;
858
859--echo Test for bug 1412423: SET STATEMENT ... FOR <statement> crashes server
860--echo if <statement> needs to re-open a temp table and fails
861CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB;
862HANDLER t3 OPEN;
863--error ER_CANT_REOPEN_TABLE
864SET STATEMENT max_join_size=1000 FOR SELECT * FROM t3;
865DROP TABLE t3;
866
823--echo ''867--echo ''
824--echo '# Cleanup'868--echo '# Cleanup'
825DROP TABLE t1;869DROP TABLE t1, t2;
826DROP PROCEDURE p1;870DROP PROCEDURE p1;
827DROP PROCEDURE p2;871DROP PROCEDURE p2;
828DROP PROCEDURE p3;872DROP PROCEDURE p3;
829DROP PROCEDURE p4;873DROP PROCEDURE p4;
830DROP PROCEDURE p5;874DROP PROCEDURE p5;
875
876--source include/wait_until_count_sessions.inc
831877
=== modified file 'sql/sql_parse.cc'
--- sql/sql_parse.cc 2015-01-13 09:38:11 +0000
+++ sql/sql_parse.cc 2015-02-04 16:26:16 +0000
@@ -2606,7 +2606,7 @@
2606 /* have table map for update for multi-update statement (BUG#37051) */2606 /* have table map for update for multi-update statement (BUG#37051) */
2607 bool have_table_map_for_update= FALSE;2607 bool have_table_map_for_update= FALSE;
2608#endif2608#endif
2609 struct system_variables *per_query_variables_backup;2609 struct system_variables *per_query_variables_backup= NULL;
2610 bool reset_timer= false;2610 bool reset_timer= false;
26112611
2612 DBUG_ENTER("mysql_execute_command");2612 DBUG_ENTER("mysql_execute_command");
@@ -5490,7 +5490,10 @@
5490 if (reset_timer)5490 if (reset_timer)
5491 reset_statement_timer(thd);5491 reset_statement_timer(thd);
54925492
5493 if (lex->set_statement && !lex->var_list.is_empty()) {5493 if (per_query_variables_backup) {
5494 DBUG_ASSERT(lex->set_statement);
5495 DBUG_ASSERT(!lex->var_list.is_empty());
5496
5494 List_iterator_fast<set_var_base> it(thd->lex->var_list);5497 List_iterator_fast<set_var_base> it(thd->lex->var_list);
5495 set_var *var;5498 set_var *var;
54965499

Subscribers

People subscribed via source and target branches