Skip to content

Commit 0bfae35

Browse files
author
Nirbhay Choubey
committed
MDEV-8166 : Adding index on new table from select crashes Galera cluster
In wsrep, CTAS should be handled like a regular transaction. Added a test case.
1 parent 8fdf8f0 commit 0bfae35

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

mysql-test/suite/galera/r/create.result

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,36 @@ SET @@GLOBAL.wsrep_forced_binlog_format=@wsrep_forced_binlog_format_saved;
2424
# MDEV-7673: CREATE TABLE SELECT fails on Galera cluster
2525
#
2626
CREATE TABLE t1 (i INT) ENGINE=INNODB DEFAULT CHARSET=utf8 SELECT 1 as i;
27+
SELECT * FROM t1;
28+
i
29+
1
30+
SELECT * FROM t1;
31+
i
32+
1
2733
DROP TABLE t1;
34+
#
35+
# MDEV-8166 : Adding index on new table from select crashes Galera
36+
# cluster
37+
#
38+
CREATE TABLE t1(i int(11) NOT NULL DEFAULT '0') ENGINE=InnoDB DEFAULT CHARSET=utf8;
39+
INSERT INTO t1(i) VALUES (1), (2), (3);
40+
CREATE TABLE t2 (i INT) SELECT i FROM t1;
41+
ALTER TABLE t2 ADD INDEX idx(i);
42+
SELECT * FROM t2;
43+
i
44+
1
45+
2
46+
3
47+
SELECT * FROM t2;
48+
i
49+
1
50+
2
51+
3
52+
SHOW CREATE TABLE t2;
53+
Table Create Table
54+
t2 CREATE TABLE `t2` (
55+
`i` int(11) DEFAULT NULL,
56+
KEY `idx` (`i`)
57+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
58+
DROP TABLE t1, t2;
2859
# End of tests

mysql-test/suite/galera/t/create.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,34 @@ SET @@GLOBAL.wsrep_forced_binlog_format=@wsrep_forced_binlog_format_saved;
2525
--echo #
2626
--echo # MDEV-7673: CREATE TABLE SELECT fails on Galera cluster
2727
--echo #
28+
--connection node_1
2829
CREATE TABLE t1 (i INT) ENGINE=INNODB DEFAULT CHARSET=utf8 SELECT 1 as i;
30+
SELECT * FROM t1;
2931

32+
--connection node_2
33+
SELECT * FROM t1;
3034
# Cleanup
3135
DROP TABLE t1;
3236

37+
--echo #
38+
--echo # MDEV-8166 : Adding index on new table from select crashes Galera
39+
--echo # cluster
40+
--echo #
41+
--connection node_1
42+
CREATE TABLE t1(i int(11) NOT NULL DEFAULT '0') ENGINE=InnoDB DEFAULT CHARSET=utf8;
43+
INSERT INTO t1(i) VALUES (1), (2), (3);
44+
45+
CREATE TABLE t2 (i INT) SELECT i FROM t1;
46+
ALTER TABLE t2 ADD INDEX idx(i);
47+
48+
SELECT * FROM t2;
49+
50+
--connection node_2
51+
SELECT * FROM t2;
52+
SHOW CREATE TABLE t2;
53+
54+
# Cleanup
55+
DROP TABLE t1, t2;
56+
3357
--echo # End of tests
3458

sql/sql_parse.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,17 +2917,10 @@ case SQLCOM_PREPARE:
29172917
if (create_info.options & HA_LEX_CREATE_TMP_TABLE)
29182918
thd->variables.option_bits|= OPTION_KEEP_LOG;
29192919

2920-
#ifdef WITH_WSREP
2921-
if (WSREP(thd) &&
2922-
(!thd->is_current_stmt_binlog_format_row() ||
2923-
!(create_info.options & HA_LEX_CREATE_TMP_TABLE)))
2924-
WSREP_TO_ISOLATION_BEGIN(create_table->db, create_table->table_name,
2925-
NULL)
2926-
#endif
2927-
29282920
/*
29292921
select_create is currently not re-execution friendly and
29302922
needs to be created for every execution of a PS/SP.
2923+
Note: In wsrep-patch, CTAS is handled like a regular transaction.
29312924
*/
29322925
if ((result= new select_create(create_table,
29332926
&create_info,

0 commit comments

Comments
 (0)