From eb30a9d63391359e686cfffb36b4c0e4a7e2f5a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 26 Jul 2024 09:04:30 +0300 Subject: [PATCH] MDEV-34647 : 'INSERT...SELECT' on MyISAM table suddenly replicated by Galera Replication of MyISAM and Aria DML is experimental and best effort only. Earlier change make INSERT SELECT on both MyISAM and Aria to replicate using TOI and STATEMENT replication. Replication should happen only if user has set needed wsrep_mode setting. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MDEV-34647.result | 100 ++++++++++++++++++++ mysql-test/suite/galera/r/mdev-22063.result | 16 ++-- mysql-test/suite/galera/t/MDEV-34647.test | 53 +++++++++++ mysql-test/suite/galera/t/mdev-22063.test | 8 +- sql/sql_parse.cc | 8 +- 5 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 mysql-test/suite/galera/r/MDEV-34647.result create mode 100644 mysql-test/suite/galera/t/MDEV-34647.test diff --git a/mysql-test/suite/galera/r/MDEV-34647.result b/mysql-test/suite/galera/r/MDEV-34647.result new file mode 100644 index 00000000000..5a1d4530e52 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-34647.result @@ -0,0 +1,100 @@ +connection node_2; +connection node_1; +create table t1(id serial, val varchar(100)) engine=myisam; +insert into t1 values(null, 'a'); +insert into t1 values(null, 'b'); +insert into t1 select null, 'c'; +insert into t1 select null, 'd' from t1; +select * from t1; +id val +1 a +3 b +5 c +7 d +9 d +11 d +create table t2(id serial, val varchar(100)) engine=aria; +insert into t2 values(null, 'a'); +insert into t2 values(null, 'b'); +insert into t2 select null, 'c'; +insert into t2 select null, 'd' from t2; +select * from t2; +id val +1 a +3 b +5 c +7 d +9 d +11 d +create table t3(id serial, val varchar(100)) engine=innodb; +insert into t3 values(null, 'a'); +insert into t3 values(null, 'b'); +insert into t3 select null, 'c'; +insert into t3 select null, 'd' from t3; +select * from t3; +id val +1 a +3 b +5 c +7 d +9 d +11 d +set global wsrep_replicate_myisam=ON; +create table t4(id serial, val varchar(100)) engine=myisam; +insert into t4 values(null, 'a'); +insert into t4 values(null, 'b'); +insert into t4 select null, 'c'; +insert into t4 select null, 'd' from t4; +select * from t4; +id val +1 a +2 b +3 c +4 d +5 d +6 d +create table t5(id serial, val varchar(100)) engine=myisam; +insert into t5 values(null, 'a'); +insert into t5 values(null, 'b'); +insert into t5 select null, 'c'; +insert into t5 select null, 'd' from t5; +select * from t2; +id val +1 a +3 b +5 c +7 d +9 d +11 d +connection node_2; +select * from t1; +id val +select * from t2; +id val +select * from t3; +id val +1 a +3 b +5 c +7 d +9 d +11 d +select * from t4; +id val +1 a +2 b +3 c +4 d +5 d +6 d +select * from t5; +id val +1 a +2 b +3 c +4 d +5 d +6 d +connection node_1; +drop table t1,t2,t3,t4,t5; +set global wsrep_replicate_myisam=default; diff --git a/mysql-test/suite/galera/r/mdev-22063.result b/mysql-test/suite/galera/r/mdev-22063.result index 5773e70cc9d..f5007b2656c 100644 --- a/mysql-test/suite/galera/r/mdev-22063.result +++ b/mysql-test/suite/galera/r/mdev-22063.result @@ -114,7 +114,7 @@ EXPECT_1000 1000 SELECT COUNT(*) AS EXPECT_1000 FROM t3; EXPECT_1000 -1000 +0 SELECT COUNT(*) AS EXPECT_1000 FROM t4; EXPECT_1000 1000 @@ -127,9 +127,9 @@ EXPECT_1000 SELECT COUNT(*) AS EXPECT_1000 FROM t7; EXPECT_1000 1000 -SELECT COUNT(*) AS EXPECT_1000 FROM t8; -EXPECT_1000 -1000 +SELECT COUNT(*) AS EXPECT_0 FROM t8; +EXPECT_0 +0 connection node_1; DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; # Bigger INSERT INTO ... SELECT test @@ -182,7 +182,7 @@ EXPECT_1000 1000 SELECT COUNT(*) AS EXPECT_1000 FROM t3; EXPECT_1000 -1000 +0 SELECT COUNT(*) AS EXPECT_1000 FROM t4; EXPECT_1000 1000 @@ -195,9 +195,9 @@ EXPECT_1000 SELECT COUNT(*) AS EXPECT_1000 FROM t7; EXPECT_1000 1000 -SELECT COUNT(*) AS EXPECT_1000 FROM t8; -EXPECT_1000 -1000 +SELECT COUNT(*) AS EXPECT_0 FROM t8; +EXPECT_0 +0 connection node_1; DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; CREATE TABLE t1(pk int not null primary key) engine=innodb; diff --git a/mysql-test/suite/galera/t/MDEV-34647.test b/mysql-test/suite/galera/t/MDEV-34647.test new file mode 100644 index 00000000000..1697bf05f28 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-34647.test @@ -0,0 +1,53 @@ +--source include/galera_cluster.inc +--source include/have_aria.inc + +create table t1(id serial, val varchar(100)) engine=myisam; +insert into t1 values(null, 'a'); +insert into t1 values(null, 'b'); +insert into t1 select null, 'c'; +insert into t1 select null, 'd' from t1; +select * from t1; + +create table t2(id serial, val varchar(100)) engine=aria; +insert into t2 values(null, 'a'); +insert into t2 values(null, 'b'); +insert into t2 select null, 'c'; +insert into t2 select null, 'd' from t2; +select * from t2; + +create table t3(id serial, val varchar(100)) engine=innodb; +insert into t3 values(null, 'a'); +insert into t3 values(null, 'b'); +insert into t3 select null, 'c'; +insert into t3 select null, 'd' from t3; +select * from t3; + +set global wsrep_replicate_myisam=ON; + +create table t4(id serial, val varchar(100)) engine=myisam; +insert into t4 values(null, 'a'); +insert into t4 values(null, 'b'); +insert into t4 select null, 'c'; +insert into t4 select null, 'd' from t4; +select * from t4; + +create table t5(id serial, val varchar(100)) engine=myisam; +insert into t5 values(null, 'a'); +insert into t5 values(null, 'b'); +insert into t5 select null, 'c'; +insert into t5 select null, 'd' from t5; +select * from t2; + + +--connection node_2 +select * from t1; +select * from t2; +select * from t3; +select * from t4; +select * from t5; + + +--connection node_1 +drop table t1,t2,t3,t4,t5; +set global wsrep_replicate_myisam=default; + diff --git a/mysql-test/suite/galera/t/mdev-22063.test b/mysql-test/suite/galera/t/mdev-22063.test index ef16c0c8716..c3a7af7e0bb 100644 --- a/mysql-test/suite/galera/t/mdev-22063.test +++ b/mysql-test/suite/galera/t/mdev-22063.test @@ -97,7 +97,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t8; --connection node_2 --let $wait_condition = SELECT COUNT(*) = 8 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME LIKE 't_' --source include/wait_condition.inc ---let $wait_condition = SELECT COUNT(*) = 1000 FROM test.t8; +--let $wait_condition = SELECT COUNT(*) = 1000 FROM test.t7; --source include/wait_condition.inc SELECT COUNT(*) AS EXPECT_1000 FROM t1; @@ -107,7 +107,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t4; SELECT COUNT(*) AS EXPECT_1000 FROM t5; SELECT COUNT(*) AS EXPECT_1000 FROM t6; SELECT COUNT(*) AS EXPECT_1000 FROM t7; -SELECT COUNT(*) AS EXPECT_1000 FROM t8; +SELECT COUNT(*) AS EXPECT_0 FROM t8; --connection node_1 DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; @@ -145,7 +145,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t8; --connection node_2 --let $wait_condition = SELECT COUNT(*) = 8 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME LIKE 't_' --source include/wait_condition.inc ---let $wait_condition = SELECT COUNT(*) = 1000 FROM test.t8; +--let $wait_condition = SELECT COUNT(*) = 1000 FROM test.t7; --source include/wait_condition.inc SELECT COUNT(*) AS EXPECT_1000 FROM t1; @@ -155,7 +155,7 @@ SELECT COUNT(*) AS EXPECT_1000 FROM t4; SELECT COUNT(*) AS EXPECT_1000 FROM t5; SELECT COUNT(*) AS EXPECT_1000 FROM t6; SELECT COUNT(*) AS EXPECT_1000 FROM t7; -SELECT COUNT(*) AS EXPECT_1000 FROM t8; +SELECT COUNT(*) AS EXPECT_0 FROM t8; --connection node_1 DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 8a218290114..2d6c7621f7b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4761,7 +4761,13 @@ mysql_execute_command(THD *thd) // For !InnoDB we start TOI if it is not yet started and hope for the best if (!is_innodb && !wsrep_toi) - WSREP_TO_ISOLATION_BEGIN(first_table->db.str, first_table->table_name.str, NULL); + { + const legacy_db_type db_type= first_table->table->file->partition_ht()->db_type; + + /* Currently we support TOI for MyISAM only. */ + if (db_type == DB_TYPE_MYISAM && wsrep_replicate_myisam) + WSREP_TO_ISOLATION_BEGIN(first_table->db.str, first_table->table_name.str, NULL); + } } #endif /* WITH_WSREP */ /*