Commit ec0e9d6f authored by Teemu Ollakka's avatar Teemu Ollakka Committed by Jan Lindström

MDEV-22681 EXECUTE IMMEDIATE crashes server if wsrep is on.

A wsrep transaction was started for EXECUTE IMMEDIATE, which
caused assertion failure when the executed statement was
CREATE TABLE which should be executed in TOI mode.

As a fix, don't start wsrep transaction for EXECUTE IMMEDIATE
to let the wsrep state logic to be handled from inside stored
procedure codepath.
Reviewed-by: default avatarJan Lindström <jan.lindstrom@mariadb.com>
parent 46c27389
...@@ -107,6 +107,135 @@ i ...@@ -107,6 +107,135 @@ i
1 1
DROP TABLE t1; DROP TABLE t1;
connection node_1; connection node_1;
SET GLOBAL wsrep_replicate_myisam = 0; CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, b INT) ENGINE=MyISAM;
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10);
PREPARE upd from 'update t1 set b = 100 where id = 5';
PREPARE ins from 'insert into t1 values (11,11)';
PREPARE del from 'delete from t1 where id = 4';
PREPARE rep from 'replace into t1 values (12,12),(6,600)';
EXECUTE upd;
EXECUTE ins;
EXECUTE del;
EXECUTE rep;
SELECT * FROM t1 ORDER BY id;
id b
1 1
2 2
3 3
5 100
6 600
7 7
8 8
9 9
10 10
11 11
12 12
connection node_2;
SELECT * FROM t1 ORDER BY id;
id b
1 1
2 2
3 3
5 100
6 600
7 7
8 8
9 9
10 10
11 11
12 12
DROP TABLE t1;
connection node_1;
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, b INT) ENGINE=MyISAM;
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10);
CREATE PROCEDURE proc()
BEGIN
UPDATE t1 set b = 100 WHERE id = 5;
INSERT INTO t1 VALUES (11,11);
DELETE FROM t1 WHERE id = 4;
REPLACE INTO t1 VALUES (12,12),(6,600);
COMMIT;
END|
CALL proc();
SELECT * FROM t1 ORDER BY id;
id b
1 1
2 2
3 3
5 100
6 600
7 7
8 8
9 9
10 10
11 11
12 12
connection node_2;
SELECT * FROM t1 ORDER BY id;
id b
1 1
2 2
3 3
5 100
6 600
7 7
8 8
9 9
10 10
11 11
12 12
DROP PROCEDURE proc;
DROP TABLE t1;
connection node_1;
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, b INT) ENGINE=MyISAM;
CREATE TABLE t2 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT) ENGINE=MyISAM;
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10);
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, NEW.b);
CREATE TRIGGER tr2 BEFORE UPDATE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, OLD.b),(NULL, NEW.b);
CREATE TRIGGER tr3 BEFORE DELETE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, OLD.b);
INSERT INTO t1 VALUES (11,11);
UPDATE t1 SET b = 200 WHERE id = 2;
DELETE FROM t1 where id = 5;
SELECT * FROM t1 ORDER BY id;
id b
1 1
2 200
3 3
4 4
6 6
7 7
8 8
9 9
10 10
11 11
SELECT * FROM t2 ORDER BY id;
id b
1 11
2 2
3 200
4 5
connection node_2;
SELECT * FROM t1 ORDER BY id;
id b
1 1
2 200
3 3
4 4
6 6
7 7
8 8
9 9
10 10
11 11
SELECT * FROM t2 ORDER BY id;
id b
1 11
2 2
3 200
4 5
DROP TRIGGER tr1;
DROP TRIGGER tr2;
DROP TRIGGER tr3;
DROP TABLE t1,t2;
connection node_1;
connection node_2; connection node_2;
SET GLOBAL wsrep_replicate_myisam = 0;
...@@ -142,8 +142,88 @@ INSERT INTO t1 VALUES(1); ...@@ -142,8 +142,88 @@ INSERT INTO t1 VALUES(1);
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
#
# Test prepared staments
#
--connection node_1
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, b INT) ENGINE=MyISAM;
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10);
PREPARE upd from 'update t1 set b = 100 where id = 5';
PREPARE ins from 'insert into t1 values (11,11)';
PREPARE del from 'delete from t1 where id = 4';
PREPARE rep from 'replace into t1 values (12,12),(6,600)';
EXECUTE upd;
EXECUTE ins;
EXECUTE del;
EXECUTE rep;
SELECT * FROM t1 ORDER BY id;
--connection node_2
SELECT * FROM t1 ORDER BY id;
DROP TABLE t1;
#
# Test procedure
#
--connection node_1
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, b INT) ENGINE=MyISAM;
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10);
DELIMITER |;
CREATE PROCEDURE proc()
BEGIN
UPDATE t1 set b = 100 WHERE id = 5;
INSERT INTO t1 VALUES (11,11);
DELETE FROM t1 WHERE id = 4;
REPLACE INTO t1 VALUES (12,12),(6,600);
COMMIT;
END|
DELIMITER ;|
CALL proc();
SELECT * FROM t1 ORDER BY id;
--connection node_2
SELECT * FROM t1 ORDER BY id;
DROP PROCEDURE proc;
DROP TABLE t1;
#
# Test trigger
#
--connection node_1
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, b INT) ENGINE=MyISAM;
CREATE TABLE t2 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT) ENGINE=MyISAM;
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10);
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, NEW.b);
CREATE TRIGGER tr2 BEFORE UPDATE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, OLD.b),(NULL, NEW.b);
CREATE TRIGGER tr3 BEFORE DELETE ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NULL, OLD.b);
INSERT INTO t1 VALUES (11,11);
UPDATE t1 SET b = 200 WHERE id = 2;
DELETE FROM t1 where id = 5;
SELECT * FROM t1 ORDER BY id;
SELECT * FROM t2 ORDER BY id;
--connection node_2
SELECT * FROM t1 ORDER BY id;
SELECT * FROM t2 ORDER BY id;
DROP TRIGGER tr1;
DROP TRIGGER tr2;
DROP TRIGGER tr3;
DROP TABLE t1,t2;
--connection node_1 --connection node_1
--disable_query_log
--eval SET GLOBAL wsrep_replicate_myisam = $wsrep_replicate_myisam_orig --eval SET GLOBAL wsrep_replicate_myisam = $wsrep_replicate_myisam_orig
--enable_query_log
--connection node_2 --connection node_2
--disable_query_log
--eval SET GLOBAL wsrep_replicate_myisam = $wsrep_replicate_myisam_orig --eval SET GLOBAL wsrep_replicate_myisam = $wsrep_replicate_myisam_orig
--enable_query_log
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 ENGINE=InnoDB AS SELECT 1 AS b';
DROP TABLE t1;
!include ../my.cnf
[mysqld.1]
wsrep-on=ON
log-bin
binlog-format=ROW
innodb-flush-log-at-trx-commit=1
wsrep-cluster-address=gcomm://
wsrep-provider=@ENV.WSREP_PROVIDER
innodb-autoinc-lock-mode=2
#
# MDEV-22681: Server crashes in galera::ReplicatorSMM::CommitOrder::CommitOrder
# or assertion failed in wsrep::transaction::before_prepare.
#
# EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 ENGINE=InnoDB AS SELECT 1 AS b'
# crashes the server if binlog is on (see mdev_22681.cnf for configuration).
#
--source include/have_wsrep.inc
--source include/have_wsrep_provider.inc
--source include/have_innodb.inc
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 ENGINE=InnoDB AS SELECT 1 AS b';
DROP TABLE t1;
...@@ -3792,6 +3792,7 @@ mysql_execute_command(THD *thd) ...@@ -3792,6 +3792,7 @@ mysql_execute_command(THD *thd)
lex->sql_command != SQLCOM_BEGIN && lex->sql_command != SQLCOM_BEGIN &&
lex->sql_command != SQLCOM_CALL && lex->sql_command != SQLCOM_CALL &&
lex->sql_command != SQLCOM_EXECUTE && lex->sql_command != SQLCOM_EXECUTE &&
lex->sql_command != SQLCOM_EXECUTE_IMMEDIATE &&
!(sql_command_flags[lex->sql_command] & CF_AUTO_COMMIT_TRANS)) !(sql_command_flags[lex->sql_command] & CF_AUTO_COMMIT_TRANS))
{ {
wsrep_start_trx_if_not_started(thd); wsrep_start_trx_if_not_started(thd);
......
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