From 3228c08fa80963a9b18a59c2ac48d86eaaad30cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 7 Dec 2023 08:23:29 +0200 Subject: [PATCH 01/21] MDEV-22063 : Assertion `0' failed in wsrep::transaction::before_rollback Problem was that REPLACE was using consistency check that started TOI and we tried to rollback it. Do not use wsrep_before_rollback and wsrep_after_rollback if we are runing consistency check because no writeset keys are in that case added. Do not allow consistency check usage if table storage for target table is not InnoDB, instead give warning. REPLACE|SELECT INTO ... SELECT will use now TOI if table storage for target table is not InnoDB to maintain consistency between galera nodes. Signed-off-by: Julius Goryavsky --- .../galera/r/galera_myisam_autocommit.result | 40 ++- mysql-test/suite/galera/r/mdev-22063.result | 242 ++++++++++++++++++ .../galera/t/galera_myisam_autocommit.test | 24 +- mysql-test/suite/galera/t/mdev-22063.test | 186 ++++++++++++++ sql/handler.cc | 11 +- sql/sql_parse.cc | 28 +- 6 files changed, 516 insertions(+), 15 deletions(-) create mode 100644 mysql-test/suite/galera/r/mdev-22063.result create mode 100644 mysql-test/suite/galera/t/mdev-22063.test diff --git a/mysql-test/suite/galera/r/galera_myisam_autocommit.result b/mysql-test/suite/galera/r/galera_myisam_autocommit.result index 6213e8f6380..5878ea48bfe 100644 --- a/mysql-test/suite/galera/r/galera_myisam_autocommit.result +++ b/mysql-test/suite/galera/r/galera_myisam_autocommit.result @@ -1,5 +1,6 @@ connection node_2; connection node_1; +SET GLOBAL wsrep_replicate_myisam=ON; CREATE TABLE t1 (f1 INTEGER) ENGINE=MyISAM; INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (2), (3); @@ -14,14 +15,37 @@ UPDATE t1 SET f1 = 9; UPDATE t2 SET f1 = 9 WHERE f1 = 1; DELETE FROM t1 WHERE f1 = 9; DELETE FROM t2 WHERE f1 = 9; -TRUNCATE TABLE t1; -TRUNCATE TABLE t1; +SELECT * FROM t1 ORDER BY f1; +f1 +SELECT * FROM t2 ORDER BY f1; +f1 +2 +3 +4 +5 +6 connection node_2; -SELECT COUNT(*) = 0 FROM t1; -COUNT(*) = 0 -1 -SELECT COUNT(*) = 0 FROM t2; -COUNT(*) = 0 -1 +SELECT * FROM t1 ORDER BY f1; +f1 +SELECT * FROM t2 ORDER BY f1; +f1 +2 +3 +4 +5 +6 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +SELECT * FROM t1 ORDER BY f1; +f1 +SELECT * FROM t2 ORDER BY f1; +f1 +connection node_2; +SELECT * FROM t1 ORDER BY f1; +f1 +SELECT * FROM t2 ORDER BY f1; +f1 +connection node_1; +SET GLOBAL wsrep_replicate_myisam=OFF; DROP TABLE t1; DROP TABLE t2; diff --git a/mysql-test/suite/galera/r/mdev-22063.result b/mysql-test/suite/galera/r/mdev-22063.result new file mode 100644 index 00000000000..5773e70cc9d --- /dev/null +++ b/mysql-test/suite/galera/r/mdev-22063.result @@ -0,0 +1,242 @@ +connection node_2; +connection node_1; +# Case 1 CREATE SEQUENCE with no NOCACHE +CREATE SEQUENCE s ENGINE=InnoDB; +ERROR 42000: This version of MariaDB doesn't yet support 'CACHE without INCREMENT BY 0 in Galera cluster' +CREATE SEQUENCE s NOCACHE ENGINE=InnoDB; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +START TRANSACTION; +REPLACE INTO s VALUES (1,1,9223372036854775806,1,1,1000,0,0); +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note Table does not support optimize, doing recreate + analyze instead +test.t1 optimize status OK +SELECT * FROM t1; +a +SELECT * FROM s; +next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count +1 1 9223372036854775806 1 1 1000 0 0 +connection node_2; +SELECT * FROM t1; +a +SELECT * FROM s; +next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count +1 1 9223372036854775806 1 1 1000 0 0 +connection node_1; +DROP TABLE t1; +DROP SEQUENCE s; +# Case 2 REPLACE INTO ... SELECT with error +CREATE TABLE t (id INT KEY,a YEAR,INDEX (id,a)) engine=innodb; +REPLACE INTO t (id,a)SELECT /*!99997 */ 1; +ERROR 21S01: Column count doesn't match value count at row 1 +REPLACE INTO t (id,a)SELECT /*!99997 */ 1,2; +SELECT * FROM t; +id a +1 2002 +CREATE TABLE t2 (id INT KEY,a YEAR,INDEX (id,a)) engine=myisam; +REPLACE INTO t2 (id,a)SELECT /*!99997 */ 1; +ERROR 21S01: Column count doesn't match value count at row 1 +REPLACE INTO t2 (id,a)SELECT /*!99997 */ 1,2; +Warnings: +Warning 138 Galera cluster does support consistency check only for InnoDB tables. +SELECT * FROM t2; +id a +1 2002 +CREATE TABLE t3 (id INT KEY,a YEAR,INDEX (id,a)) engine=aria; +REPLACE INTO t3 (id,a)SELECT /*!99997 */ 1; +ERROR 21S01: Column count doesn't match value count at row 1 +REPLACE INTO t3 (id,a)SELECT /*!99997 */ 1,2; +Warnings: +Warning 138 Galera cluster does support consistency check only for InnoDB tables. +SELECT * FROM t3; +id a +1 2002 +connection node_2; +SELECT * FROM t; +id a +1 2002 +SELECT * FROM t2; +id a +1 2002 +SELECT * FROM t3; +id a +1 2002 +connection node_1; +DROP TABLE t,t2,t3; +# Bigger REPLACE ... AS SELECT test +SET GLOBAL wsrep_replicate_myisam=ON; +CREATE TABLE t1(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t2(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t3(id int not null primary key ,b int) ENGINE=Aria; +CREATE TABLE t4(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t5(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t6(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t7(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t8(id int not null primary key ,b int) ENGINE=Aria; +INSERT INTO t1(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t2(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; +REPLACE INTO t4 SELECT * FROM t1; +REPLACE INTO t5 SELECT * FROM t2; +REPLACE INTO t6 SELECT * FROM t3; +REPLACE INTO t7 SELECT * FROM t2; +REPLACE INTO t8 SELECT * FROM t3; +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t4; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t5; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t7; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t8; +EXPECT_1000 +1000 +connection node_2; +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t4; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t5; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t7; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t8; +EXPECT_1000 +1000 +connection node_1; +DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; +# Bigger INSERT INTO ... SELECT test +CREATE TABLE t1(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t2(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t3(id int not null primary key ,b int) ENGINE=Aria; +CREATE TABLE t4(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t5(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t6(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t7(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t8(id int not null primary key ,b int) ENGINE=Aria; +INSERT INTO t1(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t2(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t4 SELECT * FROM t1; +INSERT INTO t5 SELECT * FROM t2; +INSERT INTO t6 SELECT * FROM t3; +INSERT INTO t7 SELECT * FROM t2; +INSERT INTO t8 SELECT * FROM t3; +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t4; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t5; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t7; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t8; +EXPECT_1000 +1000 +connection node_2; +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t4; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t5; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t6; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t7; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_1000 FROM t8; +EXPECT_1000 +1000 +connection node_1; +DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; +CREATE TABLE t1(pk int not null primary key) engine=innodb; +INSERT INTO t1 values (1),(2),(3),(4); +CREATE VIEW view_t1 AS SELECT * FROM t1; +INSERT INTO view_t1 VALUES (5); +SELECT * FROM t1; +pk +1 +2 +3 +4 +5 +DROP TABLE t1; +DROP VIEW view_t1; +CREATE TABLE t1(pk int not null primary key) engine=myisam; +INSERT INTO t1 values (1),(2),(3),(4); +CREATE VIEW view_t1 AS SELECT * FROM t1; +INSERT INTO view_t1 VALUES (5); +SELECT * FROM t1; +pk +1 +2 +3 +4 +5 +DROP TABLE t1; +DROP VIEW view_t1; +CREATE TABLE t1(pk int not null primary key) engine=aria; +INSERT INTO t1 values (1),(2),(3),(4); +CREATE VIEW view_t1 AS SELECT * FROM t1; +INSERT INTO view_t1 VALUES (5); +SELECT * FROM t1; +pk +1 +2 +3 +4 +5 +DROP TABLE t1; +DROP VIEW view_t1; +SET GLOBAL wsrep_replicate_myisam=OFF; diff --git a/mysql-test/suite/galera/t/galera_myisam_autocommit.test b/mysql-test/suite/galera/t/galera_myisam_autocommit.test index b01b5dc07f7..65f957e8422 100644 --- a/mysql-test/suite/galera/t/galera_myisam_autocommit.test +++ b/mysql-test/suite/galera/t/galera_myisam_autocommit.test @@ -2,20 +2,24 @@ --source include/have_innodb.inc # -# This tests simple autocommit replication of MyISAM tables. No updates arrive on the slave. +# This tests simple autocommit replication of MyISAM tables. # +SET GLOBAL wsrep_replicate_myisam=ON; + # Without a PK CREATE TABLE t1 (f1 INTEGER) ENGINE=MyISAM; INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (2), (3); +# This is TOI INSERT INTO t1 SELECT 4 FROM DUAL UNION ALL SELECT 5 FROM DUAL; CREATE TABLE t2 (f1 INTEGER PRIMARY KEY) ENGINE=MyISAM; INSERT INTO t2 VALUES (1); INSERT INTO t2 VALUES (2), (3); +# This is TOI INSERT INTO t2 SELECT 4 FROM DUAL UNION ALL SELECT 5 FROM DUAL; # Error @@ -32,14 +36,26 @@ UPDATE t2 SET f1 = 9 WHERE f1 = 1; DELETE FROM t1 WHERE f1 = 9; DELETE FROM t2 WHERE f1 = 9; +SELECT * FROM t1 ORDER BY f1; +SELECT * FROM t2 ORDER BY f1; + +--connection node_2 +SELECT * FROM t1 ORDER BY f1; +SELECT * FROM t2 ORDER BY f1; + # TRUNCATE TRUNCATE TABLE t1; -TRUNCATE TABLE t1; +TRUNCATE TABLE t2; + +SELECT * FROM t1 ORDER BY f1; +SELECT * FROM t2 ORDER BY f1; --connection node_2 -SELECT COUNT(*) = 0 FROM t1; -SELECT COUNT(*) = 0 FROM t2; +SELECT * FROM t1 ORDER BY f1; +SELECT * FROM t2 ORDER BY f1; +--connection node_1 +SET GLOBAL wsrep_replicate_myisam=OFF; DROP TABLE t1; DROP TABLE t2; diff --git a/mysql-test/suite/galera/t/mdev-22063.test b/mysql-test/suite/galera/t/mdev-22063.test new file mode 100644 index 00000000000..fa0e4d350d9 --- /dev/null +++ b/mysql-test/suite/galera/t/mdev-22063.test @@ -0,0 +1,186 @@ +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/have_log_bin.inc +--source include/have_sequence.inc +--source include/have_aria.inc + +--echo # Case 1 CREATE SEQUENCE with no NOCACHE +--error ER_NOT_SUPPORTED_YET +CREATE SEQUENCE s ENGINE=InnoDB; +CREATE SEQUENCE s NOCACHE ENGINE=InnoDB; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +START TRANSACTION; +REPLACE INTO s VALUES (1,1,9223372036854775806,1,1,1000,0,0); +OPTIMIZE TABLE t1; +SELECT * FROM t1; +SELECT * FROM s; + +--connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1' +--source include/wait_condition.inc +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 's' +--source include/wait_condition.inc +--let $wait_condition = SELECT COUNT(*) = 1 FROM test.s; +--source include/wait_condition.inc + +SELECT * FROM t1; +SELECT * FROM s; + +--connection node_1 +DROP TABLE t1; +DROP SEQUENCE s; + +--echo # Case 2 REPLACE INTO ... SELECT with error +CREATE TABLE t (id INT KEY,a YEAR,INDEX (id,a)) engine=innodb; +--error ER_WRONG_VALUE_COUNT_ON_ROW +REPLACE INTO t (id,a)SELECT /*!99997 */ 1; +REPLACE INTO t (id,a)SELECT /*!99997 */ 1,2; +SELECT * FROM t; + +CREATE TABLE t2 (id INT KEY,a YEAR,INDEX (id,a)) engine=myisam; +--error ER_WRONG_VALUE_COUNT_ON_ROW +REPLACE INTO t2 (id,a)SELECT /*!99997 */ 1; +REPLACE INTO t2 (id,a)SELECT /*!99997 */ 1,2; +SELECT * FROM t2; + +CREATE TABLE t3 (id INT KEY,a YEAR,INDEX (id,a)) engine=aria; +--error ER_WRONG_VALUE_COUNT_ON_ROW +REPLACE INTO t3 (id,a)SELECT /*!99997 */ 1; +REPLACE INTO t3 (id,a)SELECT /*!99997 */ 1,2; +SELECT * FROM t3; + +--connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't3' +--source include/wait_condition.inc +--let $wait_condition = SELECT COUNT(*) = 1 FROM test.t3; +--source include/wait_condition.inc + +SELECT * FROM t; +SELECT * FROM t2; +SELECT * FROM t3; + +--connection node_1 +DROP TABLE t,t2,t3; + +--echo # Bigger REPLACE ... AS SELECT test + +SET GLOBAL wsrep_replicate_myisam=ON; + +CREATE TABLE t1(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t2(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t3(id int not null primary key ,b int) ENGINE=Aria; +CREATE TABLE t4(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t5(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t6(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t7(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t8(id int not null primary key ,b int) ENGINE=Aria; + +INSERT INTO t1(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t2(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; + +REPLACE INTO t4 SELECT * FROM t1; +REPLACE INTO t5 SELECT * FROM t2; +REPLACE INTO t6 SELECT * FROM t3; +REPLACE INTO t7 SELECT * FROM t2; +REPLACE INTO t8 SELECT * FROM t3; + +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +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; + +--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.t6; +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +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; + +--connection node_1 +DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; + +--echo # Bigger INSERT INTO ... SELECT test + +CREATE TABLE t1(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t2(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t3(id int not null primary key ,b int) ENGINE=Aria; +CREATE TABLE t4(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t5(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t6(id int not null primary key ,b int) ENGINE=InnoDB; +CREATE TABLE t7(id int not null primary key ,b int) ENGINE=MyISAM; +CREATE TABLE t8(id int not null primary key ,b int) ENGINE=Aria; + +INSERT INTO t1(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t2(id) SELECT seq FROM seq_1_to_1000; +INSERT INTO t3(id) SELECT seq FROM seq_1_to_1000; + +INSERT INTO t4 SELECT * FROM t1; +INSERT INTO t5 SELECT * FROM t2; +INSERT INTO t6 SELECT * FROM t3; +INSERT INTO t7 SELECT * FROM t2; +INSERT INTO t8 SELECT * FROM t3; + +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +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; + +--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.t6; +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +SELECT COUNT(*) AS EXPECT_1000 FROM t2; +SELECT COUNT(*) AS EXPECT_1000 FROM t3; +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; + +--connection node_1 +DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8; +# +# View +# +CREATE TABLE t1(pk int not null primary key) engine=innodb; +INSERT INTO t1 values (1),(2),(3),(4); +CREATE VIEW view_t1 AS SELECT * FROM t1; +INSERT INTO view_t1 VALUES (5); +SELECT * FROM t1; +DROP TABLE t1; +DROP VIEW view_t1; +CREATE TABLE t1(pk int not null primary key) engine=myisam; +INSERT INTO t1 values (1),(2),(3),(4); +CREATE VIEW view_t1 AS SELECT * FROM t1; +INSERT INTO view_t1 VALUES (5); +SELECT * FROM t1; +DROP TABLE t1; +DROP VIEW view_t1; +CREATE TABLE t1(pk int not null primary key) engine=aria; +INSERT INTO t1 values (1),(2),(3),(4); +CREATE VIEW view_t1 AS SELECT * FROM t1; +INSERT INTO view_t1 VALUES (5); +SELECT * FROM t1; +DROP TABLE t1; +DROP VIEW view_t1; +SET GLOBAL wsrep_replicate_myisam=OFF; diff --git a/sql/handler.cc b/sql/handler.cc index 45721d6cfbb..486beb56788 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1940,8 +1940,11 @@ int ha_rollback_trans(THD *thd, bool all) } #ifdef WITH_WSREP - (void) wsrep_before_rollback(thd, all); + // REPLACE|INSERT INTO ... SELECT uses TOI in consistency check + if (thd->wsrep_consistency_check != CONSISTENCY_CHECK_RUNNING) + (void) wsrep_before_rollback(thd, all); #endif /* WITH_WSREP */ + if (ha_info) { /* Close all cursors that can not survive ROLLBACK */ @@ -1977,8 +1980,12 @@ int ha_rollback_trans(THD *thd, bool all) thd->thread_id, all?"TRUE":"FALSE", wsrep_thd_query(thd), thd->get_stmt_da()->message(), is_real_trans); } - (void) wsrep_after_rollback(thd, all); + + // REPLACE|INSERT INTO ... SELECT uses TOI in consistency check + if (thd->wsrep_consistency_check != CONSISTENCY_CHECK_RUNNING) + (void) wsrep_after_rollback(thd, all); #endif /* WITH_WSREP */ + /* Always cleanup. Even if nht==0. There may be savepoints. */ if (is_real_trans) { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d6ad9dc270b..7ca63b06c6b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4658,10 +4658,15 @@ mysql_execute_command(THD *thd) if ((res= insert_precheck(thd, all_tables))) break; + #ifdef WITH_WSREP - if (WSREP(thd) && thd->wsrep_consistency_check == CONSISTENCY_CHECK_DECLARED) + bool wsrep_toi= false; + const bool wsrep= WSREP(thd); + + if (wsrep && thd->wsrep_consistency_check == CONSISTENCY_CHECK_DECLARED) { thd->wsrep_consistency_check = CONSISTENCY_CHECK_RUNNING; + wsrep_toi= true; WSREP_TO_ISOLATION_BEGIN(first_table->db.str, first_table->table_name.str, NULL); } #endif /* WITH_WSREP */ @@ -4696,6 +4701,27 @@ mysql_execute_command(THD *thd) if (!(res=open_and_lock_tables(thd, all_tables, TRUE, 0))) { MYSQL_INSERT_SELECT_START(thd->query()); + +#ifdef WITH_WSREP + if (wsrep && !first_table->view) + { + bool is_innodb= (first_table->table->file->ht->db_type == DB_TYPE_INNODB); + + // For consistency check inserted table needs to be InnoDB + if (!is_innodb && thd->wsrep_consistency_check != NO_CONSISTENCY_CHECK) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + HA_ERR_UNSUPPORTED, + "Galera cluster does support consistency check only" + " for InnoDB tables."); + thd->wsrep_consistency_check= NO_CONSISTENCY_CHECK; + } + + // 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); + } +#endif /* WITH_WSREP */ /* Only the INSERT table should be merged. Other will be handled by select. From daaa16a47f67a89e57c4679e54e6b7376b1bfa1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 1 Nov 2023 11:07:16 +0200 Subject: [PATCH 02/21] MDEV-25089 : Assertion `error.len > 0' failed in galera::ReplicatorSMM::handle_apply_error() Problem is that Galera starts TOI (total order isolation) i.e. it sends query to all nodes. Later it is discovered that used engine or other feature is not supported by Galera. Because TOI is executed parallelly in all nodes appliers could execute given TOI and ignore the error and start inconsistency voting causing node to leave from cluster or we might have a crash as reported. For example SEQUENCE engine does not support GEOMETRY data type causing either inconsistency between nodes (because some errors are ignored on applier) or crash. Fixed my adding new function wsrep_check_support to check can Galera support provided CREATE TABLE/SEQUENCE before TOI is started and if not clear error message is provided to the user. Currently, not supported cases: * CREATE TABLE ... AS SELECT when streaming replication is used * CREATE TABLE ... WITH SYSTEM VERSIONING AS SELECT * CREATE TABLE ... ENGINE=SEQUENCE * CREATE SEQUENCE ... ENGINE!=InnoDB * ALTER TABLE t ... ENGINE!=InnoDB where table t is SEQUENCE Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MDEV-24143.result | 2 +- .../galera/r/galera_sequence_engine.result | 12 ++ mysql-test/suite/galera/r/mdev-31285.result | 21 +--- mysql-test/suite/galera/t/MDEV-24143.test | 6 +- .../galera/t/galera_sequence_engine.test | 16 +++ mysql-test/suite/galera/t/mdev-31285.test | 35 ++---- sql/sql_sequence.cc | 6 +- sql/sql_table.cc | 104 ++++++++++++------ sql/sql_table.h | 4 - 9 files changed, 122 insertions(+), 84 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_sequence_engine.result create mode 100644 mysql-test/suite/galera/t/galera_sequence_engine.test diff --git a/mysql-test/suite/galera/r/MDEV-24143.result b/mysql-test/suite/galera/r/MDEV-24143.result index 860d8a35834..879e7d9c32c 100644 --- a/mysql-test/suite/galera/r/MDEV-24143.result +++ b/mysql-test/suite/galera/r/MDEV-24143.result @@ -14,7 +14,7 @@ c1 INSERT INTO t1 VALUES (4),(3),(1),(2); ERROR 40001: Deadlock found when trying to get lock; try restarting transaction CREATE TABLE t1 (pk INT PRIMARY KEY, b INT) ENGINE=SEQUENCE; -ERROR 42S01: Table 't1' already exists +ERROR 42000: This version of MariaDB doesn't yet support 'non-InnoDB sequences in Galera cluster' ALTER TABLE t1 DROP COLUMN c2; ERROR 42000: Can't DROP COLUMN `c2`; check that it exists SELECT get_lock ('test', 1.5); diff --git a/mysql-test/suite/galera/r/galera_sequence_engine.result b/mysql-test/suite/galera/r/galera_sequence_engine.result new file mode 100644 index 00000000000..93e6c46bd7a --- /dev/null +++ b/mysql-test/suite/galera/r/galera_sequence_engine.result @@ -0,0 +1,12 @@ +connection node_2; +connection node_1; +SET GLOBAL wsrep_ignore_apply_errors=0; +SET SESSION AUTOCOMMIT=0; +SET SESSION max_error_count=0; +CREATE TABLE t0 (id GEOMETRY,parent_id GEOMETRY)ENGINE=SEQUENCE; +ERROR 42000: This version of MariaDB doesn't yet support 'non-InnoDB sequences in Galera cluster' +connection node_2; +SHOW CREATE TABLE t0; +ERROR 42S02: Table 'test.t0' doesn't exist +connection node_1; +SET GLOBAL wsrep_ignore_apply_errors=DEFAULT; diff --git a/mysql-test/suite/galera/r/mdev-31285.result b/mysql-test/suite/galera/r/mdev-31285.result index 228f62fa305..58fcb385b1a 100644 --- a/mysql-test/suite/galera/r/mdev-31285.result +++ b/mysql-test/suite/galera/r/mdev-31285.result @@ -1,23 +1,8 @@ connection node_2; connection node_1; connection node_1; -connection node_2; -connection node_1; CREATE TABLE t ENGINE=InnoDB WITH SYSTEM VERSIONING AS SELECT 1 AS i; +ERROR 42000: This version of MariaDB doesn't yet support 'SYSTEM VERSIONING AS SELECT in Galera cluster' +connection node_2; SHOW CREATE TABLE t; -Table Create Table -t CREATE TABLE `t` ( - `i` int(1) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING -SELECT * from t; -i -1 -DROP TABLE IF EXISTS t; -COMMIT; -connection node_2; -SET SESSION wsrep_sync_wait=0; -Killing server ... -Starting server ... -connection node_2; -call mtr.add_suppression("WSREP: Event .*Write_rows_v1 apply failed:.*"); -call mtr.add_suppression("SREP: Failed to apply write set: gtid:.*"); +ERROR 42S02: Table 'test.t' doesn't exist diff --git a/mysql-test/suite/galera/t/MDEV-24143.test b/mysql-test/suite/galera/t/MDEV-24143.test index e58f147cb7c..3aecac8cb07 100644 --- a/mysql-test/suite/galera/t/MDEV-24143.test +++ b/mysql-test/suite/galera/t/MDEV-24143.test @@ -11,7 +11,11 @@ SET SESSION autocommit=0; SELECT * FROM t1 WHERE c1 <=0 ORDER BY c1 DESC; --error ER_LOCK_DEADLOCK INSERT INTO t1 VALUES (4),(3),(1),(2); ---error ER_TABLE_EXISTS_ERROR +# +# This is because support for CREATE TABLE ENGINE=SEQUENCE +# is done before we check does table exists already. +# +--error ER_NOT_SUPPORTED_YET CREATE TABLE t1 (pk INT PRIMARY KEY, b INT) ENGINE=SEQUENCE; --error ER_CANT_DROP_FIELD_OR_KEY ALTER TABLE t1 DROP COLUMN c2; diff --git a/mysql-test/suite/galera/t/galera_sequence_engine.test b/mysql-test/suite/galera/t/galera_sequence_engine.test new file mode 100644 index 00000000000..47107dcce84 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_sequence_engine.test @@ -0,0 +1,16 @@ +--source include/galera_cluster.inc +--source include/have_sequence.inc + +SET GLOBAL wsrep_ignore_apply_errors=0; +SET SESSION AUTOCOMMIT=0; +SET SESSION max_error_count=0; +--error ER_NOT_SUPPORTED_YET +CREATE TABLE t0 (id GEOMETRY,parent_id GEOMETRY)ENGINE=SEQUENCE; + +--connection node_2 +--error ER_NO_SUCH_TABLE +SHOW CREATE TABLE t0; + +--connection node_1 +SET GLOBAL wsrep_ignore_apply_errors=DEFAULT; + diff --git a/mysql-test/suite/galera/t/mdev-31285.test b/mysql-test/suite/galera/t/mdev-31285.test index d2749165ef7..5abef37cccd 100644 --- a/mysql-test/suite/galera/t/mdev-31285.test +++ b/mysql-test/suite/galera/t/mdev-31285.test @@ -1,34 +1,15 @@ --source include/galera_cluster.inc ---let $node_1 = node_1 ---let $node_2 = node_2 ---source include/auto_increment_offset_save.inc - --connection node_1 +# +# Below should not cause nodes to be inconsistent (they could if we +# allow TOI as some error are ignored on applier +# +--error ER_NOT_SUPPORTED_YET CREATE TABLE t ENGINE=InnoDB WITH SYSTEM VERSIONING AS SELECT 1 AS i; + +--connection node_2 +--error ER_NO_SUCH_TABLE SHOW CREATE TABLE t; -SELECT * from t; -DROP TABLE IF EXISTS t; -COMMIT; -# -# Restart node_2, force SST because database is inconsistent compared to node_1 -# ---connection node_2 -SET SESSION wsrep_sync_wait=0; ---source include/kill_galera.inc ---remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat ---echo Starting server ... -let $restart_noprint=2; ---source include/start_mysqld.inc ---let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; ---source include/wait_condition.inc ---let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; ---source include/wait_condition.inc - ---connection node_2 -call mtr.add_suppression("WSREP: Event .*Write_rows_v1 apply failed:.*"); -call mtr.add_suppression("SREP: Failed to apply write set: gtid:.*"); - ---source include/auto_increment_offset_restore.inc diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc index 405b2d5b003..364d8e3fd51 100644 --- a/sql/sql_sequence.cc +++ b/sql/sql_sequence.cc @@ -27,6 +27,9 @@ #include "sql_acl.h" #ifdef WITH_WSREP #include "wsrep_mysqld.h" +bool wsrep_check_sequence(THD* thd, + const sequence_definition *seq, + const bool used_engine); #endif struct Field_definition @@ -945,7 +948,8 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) #ifdef WITH_WSREP if (WSREP(thd) && wsrep_thd_is_local(thd)) { - if (wsrep_check_sequence(thd, new_seq)) + const bool used_engine= lex->create_info.used_fields & HA_CREATE_USED_ENGINE; + if (wsrep_check_sequence(thd, new_seq, used_engine)) DBUG_RETURN(TRUE); if (wsrep_to_isolation_begin(thd, first_table->db.str, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 897027cc73d..4a4d6f9cca2 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5343,18 +5343,21 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db, #ifdef WITH_WSREP /** Additional sequence checks for Galera cluster. -@param thd thread handle -@param seq sequence definition +@param thd thread handle +@param seq sequence definition +@param used_engine create used ENGINE= @retval false success @retval true failure */ -bool wsrep_check_sequence(THD* thd, const sequence_definition *seq) +bool wsrep_check_sequence(THD* thd, + const sequence_definition *seq, + const bool used_engine) { enum legacy_db_type db_type; DBUG_ASSERT(WSREP(thd)); - if (thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE) + if (used_engine) { db_type= thd->lex->create_info.db_type->db_type; } @@ -5385,6 +5388,57 @@ bool wsrep_check_sequence(THD* thd, const sequence_definition *seq) return (false); } + +/** Additional CREATE TABLE/SEQUENCE checks for Galera cluster. + +@param thd thread handle +@param wsrep_ctas CREATE TABLE AS SELECT ? +@param used_engine CREATE TABLE ... ENGINE = ? +@param create_info Create information + +@retval false Galera cluster does support used clause +@retval true Galera cluster does not support used clause +*/ +static +bool wsrep_check_support(THD* thd, + const bool wsrep_ctas, + const bool used_engine, + const HA_CREATE_INFO* create_info) +{ + /* CREATE TABLE ... AS SELECT */ + if (wsrep_ctas && + thd->variables.wsrep_trx_fragment_size > 0) + { + my_message(ER_NOT_ALLOWED_COMMAND, + "CREATE TABLE AS SELECT is not supported with streaming replication", + MYF(0)); + return true; + } + /* CREATE TABLE .. WITH SYSTEM VERSIONING AS SELECT + is not supported in Galera cluster. + */ + if (wsrep_ctas && + create_info->versioned()) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), + "SYSTEM VERSIONING AS SELECT in Galera cluster"); + return true; + } + /* + CREATE TABLE ... ENGINE=SEQUENCE is not supported in + Galera cluster. + CREATE SEQUENCE ... ENGINE=xxx Galera cluster supports + only InnoDB-sequences. + */ + if (((used_engine && create_info->db_type && + (create_info->db_type->db_type == DB_TYPE_SEQUENCE || + create_info->db_type->db_type >= DB_TYPE_FIRST_DYNAMIC)) || + thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE) && + wsrep_check_sequence(thd, create_info->seq_create_info, used_engine)) + return true; + + return false; +} #endif /* WITH_WSREP */ /** @@ -5442,15 +5496,6 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, if (!opt_explicit_defaults_for_timestamp) promote_first_timestamp_column(&alter_info->create_list); -#ifdef WITH_WSREP - if (thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE && - WSREP(thd) && wsrep_thd_is_local_toi(thd)) - { - if (wsrep_check_sequence(thd, create_info->seq_create_info)) - DBUG_RETURN(true); - } -#endif /* WITH_WSREP */ - /* We can abort create table for any table type */ thd->abort_on_warning= thd->is_strict_mode(); @@ -9764,6 +9809,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, TODO: this design is obsolete and will be removed. */ int table_kind= check_if_log_table(table_list, FALSE, NullS); + const bool used_engine= create_info->used_fields & HA_CREATE_USED_ENGINE; if (table_kind) { @@ -9775,7 +9821,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, } /* Disable alter of log tables to unsupported engine */ - if ((create_info->used_fields & HA_CREATE_USED_ENGINE) && + if ((used_engine) && (!create_info->db_type || /* unknown engine */ !(create_info->db_type->flags & HTON_SUPPORT_LOG_TABLES))) { @@ -9826,7 +9872,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, if we can support implementing storage engine. */ if (WSREP(thd) && table && table->s->sequence && - wsrep_check_sequence(thd, thd->lex->create_info.seq_create_info)) + wsrep_check_sequence(thd, thd->lex->create_info.seq_create_info, used_engine)) DBUG_RETURN(TRUE); #endif /* WITH_WSREP */ @@ -10285,12 +10331,10 @@ do_continue:; #endif #ifdef WITH_WSREP + // ALTER TABLE for sequence object, check can we support it if (table->s->sequence && WSREP(thd) && - wsrep_thd_is_local_toi(thd)) - { - if (wsrep_check_sequence(thd, create_info->seq_create_info)) + wsrep_check_sequence(thd, create_info->seq_create_info, used_engine)) DBUG_RETURN(TRUE); - } #endif /* WITH_WSREP */ /* @@ -11744,17 +11788,11 @@ bool Sql_cmd_create_table_like::execute(THD *thd) #endif #ifdef WITH_WSREP - if (wsrep_ctas) + if (WSREP(thd) && + wsrep_check_support(thd, wsrep_ctas, used_engine, &create_info)) { - if (thd->variables.wsrep_trx_fragment_size > 0) - { - my_message( - ER_NOT_ALLOWED_COMMAND, - "CREATE TABLE AS SELECT is not supported with streaming replication", - MYF(0)); - res= 1; - goto end_with_restore_list; - } + res= 1; + goto end_with_restore_list; } #endif /* WITH_WSREP */ @@ -11906,6 +11944,7 @@ bool Sql_cmd_create_table_like::execute(THD *thd) create_table->table_name, create_table->db)) goto end_with_restore_list; +#ifdef WITH_WSREP /* In STATEMENT format, we probably have to replicate also temporary tables, like mysql replication does. Also check if the requested @@ -11914,15 +11953,15 @@ bool Sql_cmd_create_table_like::execute(THD *thd) if (WSREP(thd)) { handlerton *orig_ht= create_info.db_type; + if (!check_engine(thd, create_table->db.str, create_table->table_name.str, &create_info) && (!thd->is_current_stmt_binlog_format_row() || !create_info.tmp_table())) { -#ifdef WITH_WSREP if (thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE && - wsrep_check_sequence(thd, lex->create_info.seq_create_info)) + wsrep_check_sequence(thd, lex->create_info.seq_create_info, used_engine)) DBUG_RETURN(true); WSREP_TO_ISOLATION_BEGIN_ALTER(create_table->db.str, create_table->table_name.str, @@ -11932,13 +11971,14 @@ bool Sql_cmd_create_table_like::execute(THD *thd) res= true; goto end_with_restore_list; } -#endif /* WITH_WSREP */ } // check_engine will set db_type to NULL if e.g. TEMPORARY is // not supported by the storage engine, this case is checked // again in mysql_create_table create_info.db_type= orig_ht; } +#endif /* WITH_WSREP */ + /* Regular CREATE TABLE */ res= mysql_create_table(thd, create_table, &create_info, &alter_info); } diff --git a/sql/sql_table.h b/sql/sql_table.h index cf61ad6a4fa..e51b5ec0f0f 100644 --- a/sql/sql_table.h +++ b/sql/sql_table.h @@ -285,8 +285,4 @@ extern mysql_mutex_t LOCK_gdl; bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *); -#ifdef WITH_WSREP -bool wsrep_check_sequence(THD* thd, const class sequence_definition *seq); -#endif - #endif /* SQL_TABLE_INCLUDED */ From c768ac6208114d58c7365273fcbc627fff568c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 4 Sep 2023 12:22:51 +0300 Subject: [PATCH 03/21] MDEV-25731 : Assertion `mode_ == m_local' failed in wsrep::client_state::streaming_params() Problem was that if wsrep_load_data_splitting was used streaming replication (SR) parameters were set for MyISAM table. Galera does not currently support SR for MyISAM. Fix is to ignore wsrep_load_data_splitting setting (with warning) if table is not InnoDB table. This is 10.4-10.5 case of fix. Signed-off-by: Julius Goryavsky --- mysql-test/std_data/mdev-25731.dat | 6 +++ mysql-test/suite/galera/r/MDEV-25731.result | 34 +++++++++++++++++ mysql-test/suite/galera/t/MDEV-25731.test | 27 ++++++++++++++ sql/sql_load.cc | 41 ++++++++++++++++----- 4 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 mysql-test/std_data/mdev-25731.dat create mode 100644 mysql-test/suite/galera/r/MDEV-25731.result create mode 100644 mysql-test/suite/galera/t/MDEV-25731.test diff --git a/mysql-test/std_data/mdev-25731.dat b/mysql-test/std_data/mdev-25731.dat new file mode 100644 index 00000000000..e6c779a8292 --- /dev/null +++ b/mysql-test/std_data/mdev-25731.dat @@ -0,0 +1,6 @@ +1 +2 +3 +1 +5 +6 diff --git a/mysql-test/suite/galera/r/MDEV-25731.result b/mysql-test/suite/galera/r/MDEV-25731.result new file mode 100644 index 00000000000..93afc74afde --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-25731.result @@ -0,0 +1,34 @@ +connection node_2; +connection node_1; +connection node_1; +SET GLOBAL wsrep_load_data_splitting=ON; +Warnings: +Warning 1287 '@@wsrep_load_data_splitting' is deprecated and will be removed in a future release +SET GLOBAL wsrep_replicate_myisam=ON; +CREATE TABLE t1 (c1 int) ENGINE=MYISAM; +LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +Warnings: +Warning 1235 wsrep_load_data_splitting for other than InnoDB tables +SELECT COUNT(*) AS EXPECT_6 FROM t1; +EXPECT_6 +6 +connection node_2; +SELECT COUNT(*) AS EXPECT_6 FROM t1; +EXPECT_6 +6 +connection node_1; +ALTER TABLE t1 ENGINE=InnoDB; +LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +SELECT COUNT(*) AS EXPECT_12 FROM t1; +EXPECT_12 +12 +connection node_2; +SELECT COUNT(*) AS EXPECT_12 FROM t1; +EXPECT_12 +12 +connection node_1; +DROP TABLE t1; +SET GLOBAL wsrep_load_data_splitting=OFF; +Warnings: +Warning 1287 '@@wsrep_load_data_splitting' is deprecated and will be removed in a future release +SET GLOBAL wsrep_replicate_myisam=OFF; diff --git a/mysql-test/suite/galera/t/MDEV-25731.test b/mysql-test/suite/galera/t/MDEV-25731.test new file mode 100644 index 00000000000..c26fad2fa6a --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-25731.test @@ -0,0 +1,27 @@ +--source include/galera_cluster.inc +--source include/have_aria.inc + +--connection node_1 +SET GLOBAL wsrep_load_data_splitting=ON; +SET GLOBAL wsrep_replicate_myisam=ON; +CREATE TABLE t1 (c1 int) ENGINE=MYISAM; +LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +SELECT COUNT(*) AS EXPECT_6 FROM t1; + +--connection node_2 +SELECT COUNT(*) AS EXPECT_6 FROM t1; + +--connection node_1 +ALTER TABLE t1 ENGINE=InnoDB; +LOAD DATA INFILE '../../std_data/mdev-25731.dat' IGNORE INTO TABLE t1 LINES TERMINATED BY '\n'; +SELECT COUNT(*) AS EXPECT_12 FROM t1; + +--connection node_2 +SELECT COUNT(*) AS EXPECT_12 FROM t1; + +--connection node_1 +DROP TABLE t1; +SET GLOBAL wsrep_load_data_splitting=OFF; +SET GLOBAL wsrep_replicate_myisam=OFF; + + diff --git a/sql/sql_load.cc b/sql/sql_load.cc index cc4361b0472..aef649309fc 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -105,23 +105,41 @@ public: class Wsrep_load_data_split { public: - Wsrep_load_data_split(THD *thd) + Wsrep_load_data_split(THD *thd, TABLE *table) : m_thd(thd) - , m_load_data_splitting(wsrep_load_data_splitting) + , m_load_data_splitting(false) , m_fragment_unit(thd->wsrep_trx().streaming_context().fragment_unit()) , m_fragment_size(thd->wsrep_trx().streaming_context().fragment_size()) { - if (WSREP(m_thd) && m_load_data_splitting) + /* + We support load data splitting for InnoDB only as it will use + streaming replication (SR). + */ + if (WSREP(thd) && wsrep_load_data_splitting) { - /* Override streaming settings with backward compatible values for - load data splitting */ - m_thd->wsrep_cs().streaming_params(wsrep::streaming_context::row, 10000); + handlerton *ht= table->s->db_type(); + // For partitioned tables find underlying hton + if (table->file->partition_ht()) + ht= table->file->partition_ht(); + if (ht->db_type != DB_TYPE_INNODB) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_NOT_SUPPORTED_YET, + "wsrep_load_data_splitting for other than InnoDB tables"); + } + else + { + /* Override streaming settings with backward compatible values for + load data splitting */ + m_thd->wsrep_cs().streaming_params(wsrep::streaming_context::row, 10000); + m_load_data_splitting= true; + } } } ~Wsrep_load_data_split() { - if (WSREP(m_thd) && m_load_data_splitting) + if (m_load_data_splitting) { /* Restore original settings */ m_thd->wsrep_cs().streaming_params(m_fragment_unit, m_fragment_size); @@ -346,6 +364,7 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list, bool is_concurrent; #endif const char *db= table_list->db.str; // This is never null + /* If path for file is not defined, we will use the current database. If this is not set, we will use the directory where the table to be @@ -356,9 +375,6 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list, bool transactional_table __attribute__((unused)); DBUG_ENTER("mysql_load"); -#ifdef WITH_WSREP - Wsrep_load_data_split wsrep_load_data_split(thd); -#endif /* WITH_WSREP */ /* Bug #34283 mysqlbinlog leaves tmpfile after termination if binlog contains @@ -422,6 +438,11 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list, { DBUG_RETURN(TRUE); } + +#ifdef WITH_WSREP + Wsrep_load_data_split wsrep_load_data_split(thd, table_list->table); +#endif /* WITH_WSREP */ + thd_proc_info(thd, "Executing"); /* Let us emit an error if we are loading data to table which is used From e4f221a5f2a103320015cd20bac8412040d0fc2e Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Mon, 29 Jan 2024 15:17:57 -0700 Subject: [PATCH 04/21] MDEV-33327: rpl_seconds_behind_master_spike Sensitive to IO Thread Stop Position rpl.rpl_seconds_behind_master_spike uses the DEBUG_SYNC mechanism to count how many format descriptor events (FDEs) have been executed, to attempt to pause on a specific relay log FDE after executing transactions. However, depending on when the IO thread is stopped, it can send an extra FDE before sending the transactions, forcing the test to pause before executing any transactions, resulting in a table not existing, that is attempted to be read for COUNT. This patch fixes this by no longer counting FDEs, but rather by programmatically waiting until the SQL thread has executed the transaction and then automatically activating the DEBUG_SYNC point to trigger at the next relay log FDE. --- .../rpl/r/rpl_seconds_behind_master_spike.result | 8 ++------ .../rpl/t/rpl_seconds_behind_master_spike.test | 9 ++------- sql/slave.cc | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_seconds_behind_master_spike.result b/mysql-test/suite/rpl/r/rpl_seconds_behind_master_spike.result index bb71f6c92b0..3234a512d86 100644 --- a/mysql-test/suite/rpl/r/rpl_seconds_behind_master_spike.result +++ b/mysql-test/suite/rpl/r/rpl_seconds_behind_master_spike.result @@ -3,7 +3,8 @@ include/master-slave.inc connection slave; include/stop_slave.inc SET @save_dbug= @@GLOBAL.debug_dbug; -SET @@global.debug_dbug="+d,pause_sql_thread_on_fde,negate_clock_diff_with_master"; +SET @@global.debug_dbug="+d,pause_sql_thread_on_relay_fde_after_trans"; +SET @@global.debug_dbug="+d,negate_clock_diff_with_master"; include/start_slave.inc # Future events must be logged at least 2 seconds after # the slave starts @@ -15,11 +16,6 @@ insert into t1 values (1); # event in its relay log flush logs; connection slave; -# Ignore FDEs that happen before the CREATE/INSERT commands -SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; -SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; -SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; -SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; # On the next FDE, the slave should have the master CREATE/INSERT events SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; select count(*)=1 from t1; diff --git a/mysql-test/suite/rpl/t/rpl_seconds_behind_master_spike.test b/mysql-test/suite/rpl/t/rpl_seconds_behind_master_spike.test index 9e73e6678a2..cd6311c5e19 100644 --- a/mysql-test/suite/rpl/t/rpl_seconds_behind_master_spike.test +++ b/mysql-test/suite/rpl/t/rpl_seconds_behind_master_spike.test @@ -27,7 +27,8 @@ --connection slave --source include/stop_slave.inc SET @save_dbug= @@GLOBAL.debug_dbug; -SET @@global.debug_dbug="+d,pause_sql_thread_on_fde,negate_clock_diff_with_master"; +SET @@global.debug_dbug="+d,pause_sql_thread_on_relay_fde_after_trans"; +SET @@global.debug_dbug="+d,negate_clock_diff_with_master"; --source include/start_slave.inc --let $sleep_time=2 @@ -46,12 +47,6 @@ insert into t1 values (1); flush logs; --connection slave ---echo # Ignore FDEs that happen before the CREATE/INSERT commands -SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; -SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; -SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; -SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; - --echo # On the next FDE, the slave should have the master CREATE/INSERT events SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; select count(*)=1 from t1; diff --git a/sql/slave.cc b/sql/slave.cc index f4d76e447cd..d37b00f2888 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -4301,6 +4301,15 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli, { Gtid_log_event *gev= static_cast(ev); +#ifdef ENABLED_DEBUG_SYNC + DBUG_EXECUTE_IF( + "pause_sql_thread_on_relay_fde_after_trans", + { + DBUG_SET("-d,pause_sql_thread_on_relay_fde_after_trans"); + DBUG_SET("+d,pause_sql_thread_on_next_relay_fde"); + }); +#endif + /* For GTID, allocate a new sub_id for the given domain_id. The sub_id must be allocated in increasing order of binlog order. @@ -4451,12 +4460,14 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli, #endif /* WITH_WSREP */ #ifdef ENABLED_DEBUG_SYNC DBUG_EXECUTE_IF( - "pause_sql_thread_on_fde", - if (ev && typ == FORMAT_DESCRIPTION_EVENT) { + "pause_sql_thread_on_next_relay_fde", + if (ev && typ == FORMAT_DESCRIPTION_EVENT && + ((Format_description_log_event *) ev)->is_relay_log_event()) { DBUG_ASSERT(!debug_sync_set_action( thd, STRING_WITH_LEN( "now SIGNAL paused_on_fde WAIT_FOR sql_thread_continue"))); + DBUG_SET("-d,pause_sql_thread_on_next_relay_fde"); }); #endif From 736e429320c28d963bc66f80e2c8a35b7db72ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 5 Jan 2024 13:35:41 +0200 Subject: [PATCH 05/21] MDEV-32635: galera_shutdown_nonprim: mysql_shutdown failed Add wait_condition after cluster membership change Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/disabled.def | 1 - .../galera/r/galera_shutdown_nonprim.result | 7 ++++- .../galera/t/galera_shutdown_nonprim.test | 26 ++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index a05ee3f8880..1f41e521bd3 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -13,7 +13,6 @@ galera_as_slave_ctas : MDEV-28378 timeout galera_pc_recovery : MDEV-25199 cluster fails to start up galera_sequences : MDEV-32561 WSREP FSM failure: no such a transition REPLICATING -> COMMITTED -galera_shutdown_nonprim : MDEV-32635 galera_shutdown_nonprim: mysql_shutdown failed versioning_trx_id : MDEV-18590 : galera.versioning_trx_id: Test failure: mysqltest: Result content mismatch galera_concurrent_ctas : MDEV-32779 galera_concurrent_ctas: assertion in the galera::ReplicatorSMM::finish_cert() galera_as_slave_replay : MDEV-32780 galera_as_slave_replay: assertion in the wsrep::transaction::before_rollback() diff --git a/mysql-test/suite/galera/r/galera_shutdown_nonprim.result b/mysql-test/suite/galera/r/galera_shutdown_nonprim.result index 8b7697432a3..d577eab9f1a 100644 --- a/mysql-test/suite/galera/r/galera_shutdown_nonprim.result +++ b/mysql-test/suite/galera/r/galera_shutdown_nonprim.result @@ -5,7 +5,12 @@ connection node_2; connection node_1; SET GLOBAL wsrep_provider_options = 'pc.weight=2'; connection node_2; -SET GLOBAL wsrep_provider_options = 'gmcast.isolate = 1'; SET SESSION wsrep_sync_wait = 0; +SET GLOBAL wsrep_provider_options = 'gmcast.isolate = 1'; +connection node_1; +connection node_2; +SHOW STATUS LIKE 'wsrep_cluster_status'; +Variable_name Value +wsrep_cluster_status non-Primary connection node_1; SET GLOBAL wsrep_provider_options = 'pc.weight = 1'; diff --git a/mysql-test/suite/galera/t/galera_shutdown_nonprim.test b/mysql-test/suite/galera/t/galera_shutdown_nonprim.test index cf7018cd751..d1a1c91456b 100644 --- a/mysql-test/suite/galera/t/galera_shutdown_nonprim.test +++ b/mysql-test/suite/galera/t/galera_shutdown_nonprim.test @@ -16,21 +16,27 @@ SET GLOBAL wsrep_provider_options = 'pc.weight=2'; --connection node_2 # Isolate node_2 from the group and wait until wsrep_ready becomes OFF. -SET GLOBAL wsrep_provider_options = 'gmcast.isolate = 1'; SET SESSION wsrep_sync_wait = 0; ---let $wait_condition = SELECT VARIABLE_VALUE = 'OFF' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready' ---source include/wait_condition.inc - -# Verify that graceful shutdown succeeds. ---source include/shutdown_mysqld.inc ---source include/start_mysqld.inc - ---let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; ---source include/wait_condition.inc +SET GLOBAL wsrep_provider_options = 'gmcast.isolate = 1'; --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc + +--connection node_2 +--let $wait_condition = SELECT VARIABLE_VALUE = 'OFF' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready' +--source include/wait_condition.inc +SHOW STATUS LIKE 'wsrep_cluster_status'; +# Verify that graceful shutdown succeeds. +--source include/shutdown_mysqld.inc + +--source include/start_mysqld.inc + +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc # Restore original settings. SET GLOBAL wsrep_provider_options = 'pc.weight = 1'; + --source include/auto_increment_offset_restore.inc From 49fa5f6b5f573b25d7712859ca404d086f4f5223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 5 Jan 2024 11:33:53 +0200 Subject: [PATCH 06/21] MDEV-33138 : Galera test case MW-336 unstable Add more inserts before wsrep_slave_threads is set to 1 and add wait_condition to wait all of them are replicated before wait_condition about number of wsrep_slave_threads. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MW-336.result | 46 ++++-------------- mysql-test/suite/galera/t/MW-336.cnf | 2 + mysql-test/suite/galera/t/MW-336.test | 62 +++++++++++-------------- 3 files changed, 39 insertions(+), 71 deletions(-) diff --git a/mysql-test/suite/galera/r/MW-336.result b/mysql-test/suite/galera/r/MW-336.result index 8996b85c77c..e0cb1ee0464 100644 --- a/mysql-test/suite/galera/r/MW-336.result +++ b/mysql-test/suite/galera/r/MW-336.result @@ -1,7 +1,8 @@ connection node_2; connection node_1; connection node_1; -CREATE TABLE t1 (f1 INTEGER) Engine=InnoDB; +SET @wsrep_slave_threads_orig = @@wsrep_slave_threads; +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT) Engine=InnoDB; SET GLOBAL wsrep_slave_threads = 10; # Set slave threads to 10 step 1 SELECT VARIABLE_VALUE AS EXPECT_10 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; @@ -9,7 +10,7 @@ EXPECT_10 10 SET GLOBAL wsrep_slave_threads = 1; connection node_2; -INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (NULL); connection node_1; # Wait until one of the appliers has exited SELECT VARIABLE_VALUE AS EXPECT_9 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; @@ -27,33 +28,14 @@ EXPECT_20 20 SET GLOBAL wsrep_slave_threads = 1; connection node_2; -INSERT INTO t1 VALUES (1); -INSERT INTO t1 VALUES (2); -INSERT INTO t1 VALUES (3); -INSERT INTO t1 VALUES (4); -INSERT INTO t1 VALUES (5); -INSERT INTO t1 VALUES (6); -INSERT INTO t1 VALUES (7); -INSERT INTO t1 VALUES (8); -INSERT INTO t1 VALUES (9); -INSERT INTO t1 VALUES (10); -INSERT INTO t1 VALUES (11); -INSERT INTO t1 VALUES (12); -INSERT INTO t1 VALUES (13); -INSERT INTO t1 VALUES (14); -INSERT INTO t1 VALUES (16); -INSERT INTO t1 VALUES (17); -INSERT INTO t1 VALUES (18); -INSERT INTO t1 VALUES (19); -INSERT INTO t1 VALUES (20); connection node_1; # Wait until 19 of the appliers has exited SELECT VARIABLE_VALUE AS EXPECT_1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; EXPECT_1 1 -SELECT COUNT(*) FROM t1; -COUNT(*) -20 +SELECT COUNT(*) AS EXPECT_51 FROM t1; +EXPECT_51 +51 SET GLOBAL wsrep_slave_threads = 10; # Set slave threads to 10 step 3 SELECT VARIABLE_VALUE AS EXPECT_10 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; @@ -62,22 +44,12 @@ EXPECT_10 connection node_1; SET GLOBAL wsrep_slave_threads = 1; connection node_2; -INSERT INTO t1 VALUES (21); -INSERT INTO t1 VALUES (22); -INSERT INTO t1 VALUES (23); -INSERT INTO t1 VALUES (24); -INSERT INTO t1 VALUES (25); -INSERT INTO t1 VALUES (26); -INSERT INTO t1 VALUES (27); -INSERT INTO t1 VALUES (28); -INSERT INTO t1 VALUES (29); -INSERT INTO t1 VALUES (30); connection node_1; # Wait until slave threads back to 1 SELECT VARIABLE_VALUE AS EXPECT_1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; EXPECT_1 1 -SELECT COUNT(*) FROM t1; -COUNT(*) -30 +SELECT COUNT(*) AS EXPECT_101 FROM t1; +EXPECT_101 +101 DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/MW-336.cnf b/mysql-test/suite/galera/t/MW-336.cnf index e68f891792c..da97be5f86d 100644 --- a/mysql-test/suite/galera/t/MW-336.cnf +++ b/mysql-test/suite/galera/t/MW-336.cnf @@ -2,6 +2,8 @@ [mysqld.1] wsrep-debug=SERVER +loose-wsrep-mw-336=1 [mysqld.2] wsrep-debug=SERVER +loose-wsrep-mw-336=2 diff --git a/mysql-test/suite/galera/t/MW-336.test b/mysql-test/suite/galera/t/MW-336.test index 83943c7d8ea..29a70978e5e 100644 --- a/mysql-test/suite/galera/t/MW-336.test +++ b/mysql-test/suite/galera/t/MW-336.test @@ -3,11 +3,12 @@ # --source include/galera_cluster.inc ---source include/have_innodb.inc --source include/force_restart.inc +--source include/have_sequence.inc --connection node_1 -CREATE TABLE t1 (f1 INTEGER) Engine=InnoDB; +SET @wsrep_slave_threads_orig = @@wsrep_slave_threads; +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT) Engine=InnoDB; SET GLOBAL wsrep_slave_threads = 10; @@ -22,7 +23,7 @@ SELECT VARIABLE_VALUE AS EXPECT_10 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE V SET GLOBAL wsrep_slave_threads = 1; --connection node_2 -INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (NULL); --connection node_1 --echo # Wait until one of the appliers has exited @@ -54,27 +55,19 @@ SELECT VARIABLE_VALUE AS EXPECT_20 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE V SET GLOBAL wsrep_slave_threads = 1; --connection node_2 -INSERT INTO t1 VALUES (1); -INSERT INTO t1 VALUES (2); -INSERT INTO t1 VALUES (3); -INSERT INTO t1 VALUES (4); -INSERT INTO t1 VALUES (5); -INSERT INTO t1 VALUES (6); -INSERT INTO t1 VALUES (7); -INSERT INTO t1 VALUES (8); -INSERT INTO t1 VALUES (9); -INSERT INTO t1 VALUES (10); -INSERT INTO t1 VALUES (11); -INSERT INTO t1 VALUES (12); -INSERT INTO t1 VALUES (13); -INSERT INTO t1 VALUES (14); -INSERT INTO t1 VALUES (16); -INSERT INTO t1 VALUES (17); -INSERT INTO t1 VALUES (18); -INSERT INTO t1 VALUES (19); -INSERT INTO t1 VALUES (20); +--disable_query_log +let $c = 50; +while ($c) { +INSERT INTO t1 VALUES(NULL); COMMIT; +dec $c; +} +--enable_query_log --connection node_1 +--let $wait_condition = SELECT COUNT(*) = 51 FROM t1; +--let $wait_condition_on_error_output = SELECT COUNT(*) FROM t1; +--source include/wait_condition_with_debug.inc + --echo # Wait until 19 of the appliers has exited --let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; --let $wait_condition_on_error_output = SELECT COUNT(*), 1 as EXPECTED_VALUE FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'wsrep applier idle'; show processlist @@ -82,7 +75,7 @@ INSERT INTO t1 VALUES (20); SELECT VARIABLE_VALUE AS EXPECT_1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; -SELECT COUNT(*) FROM t1; +SELECT COUNT(*) AS EXPECT_51 FROM t1; SET GLOBAL wsrep_slave_threads = 10; --echo # Set slave threads to 10 step 3 @@ -96,16 +89,13 @@ SELECT VARIABLE_VALUE AS EXPECT_10 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE V SET GLOBAL wsrep_slave_threads = 1; --connection node_2 -INSERT INTO t1 VALUES (21); -INSERT INTO t1 VALUES (22); -INSERT INTO t1 VALUES (23); -INSERT INTO t1 VALUES (24); -INSERT INTO t1 VALUES (25); -INSERT INTO t1 VALUES (26); -INSERT INTO t1 VALUES (27); -INSERT INTO t1 VALUES (28); -INSERT INTO t1 VALUES (29); -INSERT INTO t1 VALUES (30); +--disable_query_log +let $c = 50; +while ($c) { +INSERT INTO t1 VALUES(NULL); COMMIT; +dec $c; +} +--enable_query_log --connection node_1 --echo # Wait until slave threads back to 1 @@ -115,6 +105,10 @@ INSERT INTO t1 VALUES (30); SELECT VARIABLE_VALUE AS EXPECT_1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_applier_thread_count'; -SELECT COUNT(*) FROM t1; +SELECT COUNT(*) AS EXPECT_101 FROM t1; DROP TABLE t1; + +--disable_query_log +SET GLOBAL wsrep_slave_threads = @wsrep_slave_threads_orig; +--enable_query_log From 5b4456b38a4cac479a03f09e55620d263481d8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 29 Dec 2023 10:20:51 +0200 Subject: [PATCH 07/21] MDEV-33036 : Galera test case galera_3nodes.galera_ist_gcache_rollover has warning Correct used configuration and force server restarts before test case. Add wait condition instead of sleep to verify that all expected nodes are back to cluster. Signed-off-by: Julius Goryavsky --- .../r/galera_ist_gcache_rollover.result | 27 ++++++++------- .../r/galera_join_with_cc_B.result | 7 ++++ .../t/galera_ist_gcache_rollover.cnf | 14 +++++++- .../t/galera_ist_gcache_rollover.test | 33 ++++++++++++++----- .../t/galera_join_with_cc_B.test | 13 ++++++++ 5 files changed, 73 insertions(+), 21 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/galera_ist_gcache_rollover.result b/mysql-test/suite/galera_3nodes/r/galera_ist_gcache_rollover.result index 9f1d3fec16e..a69cef11358 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ist_gcache_rollover.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ist_gcache_rollover.result @@ -9,6 +9,7 @@ INSERT INTO t1 VALUES (01), (02), (03), (04), (05); connection node_2; Unloading wsrep provider ... SET GLOBAL wsrep_cluster_address = ''; +connection node_1; connection node_3; Unloading wsrep provider ... SET GLOBAL wsrep_cluster_address = ''; @@ -33,14 +34,16 @@ SET GLOBAL wsrep_provider_options = 'dbug='; SET GLOBAL wsrep_provider_options = 'signal=ist_sender_send_after_get_buffers'; INSERT INTO t1 VALUES (51), (52), (53), (54), (55); connection node_2; +connection node_1; connection node_3; +connection node_1; connection node_2; -SELECT COUNT(*) = 30 FROM t1; -COUNT(*) = 30 -1 -SELECT COUNT(*) = 3 FROM t2; -COUNT(*) = 3 -1 +SELECT COUNT(*) AS EXPECT_30 FROM t1; +EXPECT_30 +30 +SELECT COUNT(*) AS EXPECT_3 FROM t2; +EXPECT_3 +3 SELECT LENGTH(f1) = 512 * 1024 FROM t2; LENGTH(f1) = 512 * 1024 1 @@ -48,12 +51,12 @@ LENGTH(f1) = 512 * 1024 1 CALL mtr.add_suppression("WSREP: Unsupported protocol downgrade: incremental data collection disabled"); connection node_3; -SELECT COUNT(*) = 30 FROM t1; -COUNT(*) = 30 -1 -SELECT COUNT(*) = 3 FROM t2; -COUNT(*) = 3 -1 +SELECT COUNT(*) AS EXPECT_30 FROM t1; +EXPECT_30 +30 +SELECT COUNT(*) AS EXPECT_3 FROM t2; +EXPECT_3 +3 SELECT LENGTH(f1) = 512 * 1024 FROM t2; LENGTH(f1) = 512 * 1024 1 diff --git a/mysql-test/suite/galera_3nodes/r/galera_join_with_cc_B.result b/mysql-test/suite/galera_3nodes/r/galera_join_with_cc_B.result index 7e75bc4b08a..a88909f4bfb 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_join_with_cc_B.result +++ b/mysql-test/suite/galera_3nodes/r/galera_join_with_cc_B.result @@ -1,6 +1,9 @@ connection node_2; connection node_1; connection node_1; +connection node_2; +connection node_3; +connection node_1; CREATE TABLE t1 (pk INT PRIMARY KEY, node INT) ENGINE=innodb; INSERT INTO t1 VALUES (1, 1); connection node_2; @@ -89,3 +92,7 @@ connection node_2; call mtr.add_suppression("WSREP: Rejecting JOIN message from \(.*\): new State Transfer required."); connection node_3; call mtr.add_suppression("WSREP: Rejecting JOIN message from \(.*\): new State Transfer required."); +disconnect node_1a; +disconnect node_3; +disconnect node_2; +disconnect node_1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.cnf b/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.cnf index 303087dffbb..29563657262 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.cnf @@ -2,10 +2,22 @@ [mysqld.1] wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.1.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.ignore_sb=true;gcache.size=1M' +auto_increment_increment=1 +auto_increment_offset=1 +# this will force server restarts before this test +loose-galera-ist-gcache-rollover=1 +wsrep-debug=1 [mysqld.2] wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.2.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.ignore_sb=true;gcache.size=1M' +auto_increment_increment=2 +auto_increment_offset=2 +loose-galera-ist-gcache-rollover=2 +wsrep-debug=1 [mysqld.3] wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.3.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.ignore_sb=true;gcache.size=1M' - +auto_increment_increment=3 +auto_increment_offset=3 +loose-galera-ist-gcache-rollover=3 +wsrep-debug=1 diff --git a/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.test b/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.test index 210a4c2331e..16b9bdb2d02 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ist_gcache_rollover.test @@ -12,6 +12,7 @@ --source include/have_innodb.inc --source include/have_debug_sync.inc --source include/galera_have_debug_sync.inc +--source include/force_restart.inc --let $galera_connection_name = node_3 --let $galera_server_number = 3 @@ -24,6 +25,9 @@ --source ../galera/include/auto_increment_offset_save.inc --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--let $wait_condition_on_error_output = SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME LIKE 'wsrep%'; show processlist +--source include/wait_condition_with_debug.inc CREATE TABLE t1 (f1 INTEGER PRIMARY KEY); INSERT INTO t1 VALUES (01), (02), (03), (04), (05); @@ -32,12 +36,15 @@ INSERT INTO t1 VALUES (01), (02), (03), (04), (05); --let $wsrep_cluster_address_orig2 = `select @@wsrep_cluster_address` --source suite/galera/include/galera_stop_replication.inc +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + --connection node_3 --let $wsrep_cluster_address_orig3 = `select @@wsrep_cluster_address` --source suite/galera/include/galera_stop_replication.inc --connection node_1 ---source include/wait_until_connected_again.inc INSERT INTO t1 VALUES (11), (12), (13), (14), (15); # Wait until nodes #2 and #3 have left @@ -88,29 +95,39 @@ INSERT INTO t1 VALUES (51), (52), (53), (54), (55); --connection node_2 --source include/wait_until_connected_again.inc +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 OR VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + --connection node_3 --source include/wait_until_connected_again.inc -sleep 5; +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc # Final checks --connection node_2 -SELECT COUNT(*) = 30 FROM t1; -SELECT COUNT(*) = 3 FROM t2; +--let $wait_condition = SELECT COUNT(*) = 30 FROM t1 +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_30 FROM t1; +SELECT COUNT(*) AS EXPECT_3 FROM t2; SELECT LENGTH(f1) = 512 * 1024 FROM t2; CALL mtr.add_suppression("WSREP: Unsupported protocol downgrade: incremental data collection disabled"); # Final checks --connection node_3 -SELECT COUNT(*) = 30 FROM t1; -SELECT COUNT(*) = 3 FROM t2; +--let $wait_condition = SELECT COUNT(*) = 30 FROM t1 +--source include/wait_condition.inc +SELECT COUNT(*) AS EXPECT_30 FROM t1; +SELECT COUNT(*) AS EXPECT_3 FROM t2; SELECT LENGTH(f1) = 512 * 1024 FROM t2; CALL mtr.add_suppression("WSREP: Unsupported protocol downgrade: incremental data collection disabled"); DROP TABLE t1, t2; # Restore original auto_increment_offset values. ---source ../galera/include/auto_increment_offset_restore.inc - --let $galera_cluster_size=3 +--source ../galera/include/auto_increment_offset_restore.inc --source include/galera_end.inc diff --git a/mysql-test/suite/galera_3nodes/t/galera_join_with_cc_B.test b/mysql-test/suite/galera_3nodes/t/galera_join_with_cc_B.test index 2fb0e78c759..d06cdcc8ae4 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_join_with_cc_B.test +++ b/mysql-test/suite/galera_3nodes/t/galera_join_with_cc_B.test @@ -15,6 +15,12 @@ --let $galera_server_number = 3 --source include/galera_connect.inc +# Save original auto_increment_offset values. +--let $node_1=node_1 +--let $node_2=node_2 +--let $node_3=node_3 +--source ../galera/include/auto_increment_offset_save.inc + --connection node_1 --let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc @@ -271,3 +277,10 @@ call mtr.add_suppression("WSREP: Rejecting JOIN message from \(.*\): new State T --connection node_3 call mtr.add_suppression("WSREP: Rejecting JOIN message from \(.*\): new State Transfer required."); + +--disconnect node_1a + +# Restore original auto_increment_offset values. +--let $galera_cluster_size=3 +--source ../galera/include/auto_increment_offset_restore.inc +--source include/galera_end.inc From ddb27a29b1381c35bde970c41c6f0bbe674661c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 4 Jan 2024 15:27:15 +0200 Subject: [PATCH 08/21] MDEV-33172 : Galera test case galera_mdl_race unstable Add wait_condition between debug sync SIGNAL points and other expected state conditions and refactor actual sync point for easier to use in test case. Signed-off-by: Julius Goryavsky --- .../suite/galera/r/galera_mdl_race.result | 50 +++++++++++---- .../suite/galera/t/galera_mdl_race.test | 62 +++++++++++++------ sql/mdl.cc | 11 +--- 3 files changed, 81 insertions(+), 42 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_mdl_race.result b/mysql-test/suite/galera/r/galera_mdl_race.result index cf747ed8efb..a7f0bc8e672 100644 --- a/mysql-test/suite/galera/r/galera_mdl_race.result +++ b/mysql-test/suite/galera/r/galera_mdl_race.result @@ -1,44 +1,68 @@ connection node_2; connection node_1; +connection node_1; CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) engine=innodb; CREATE TABLE t2 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) engine=innodb; INSERT INTO t1 VALUES (1, 'a'); INSERT INTO t1 VALUES (2, 'a'); -connection node_1; SET AUTOCOMMIT=ON; START TRANSACTION; UPDATE t1 SET f2 = 'b' WHERE f1 = 1; connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; connection node_1a; +SET SESSION wsrep_sync_wait=0; LOCK TABLE t2 WRITE; connection node_1; -SET @@debug_dbug = "d,sync.wsrep_before_mdl_wait"; +SET DEBUG_SYNC= 'wsrep_before_mdl_wait SIGNAL before_mdl_wait WAIT_FOR mdl_wait_continue'; SELECT * FROM t2;; connection node_1a; +# Wait until select is blocked before MDL lock wait +SET DEBUG_SYNC= 'now WAIT_FOR before_mdl_wait'; +connection node_1a; SET @@debug_dbug = "d,sync.wsrep_after_BF_victim_lock"; connection node_2; UPDATE t1 SET f2 = 'c' WHERE f1 = 1; -connection node_1a; -SET @@debug_dbug = ""; -SET DEBUG_SYNC = "now SIGNAL signal.wsrep_before_mdl_wait"; +connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1b; +SET SESSION wsrep_sync_wait=0; +# Wait for conflicting update to block SET DEBUG_SYNC = "now SIGNAL signal.wsrep_after_BF_victim_lock"; +connect node_1c, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1c; +connection node_1a; +SET DEBUG_SYNC = "now SIGNAL BF_victim_continue"; UNLOCK TABLES; connection node_1; ERROR 40001: Deadlock found when trying to get lock; try restarting transaction -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a'; -COUNT(*) = 1 +connection node_1; +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'a'; +EXPECT_1 1 -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'c'; +EXPECT_1 1 +SELECT * FROM t1; +f1 f2 +1 c +2 a connection node_2; -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a'; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'a'; +EXPECT_1 1 -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'c'; +EXPECT_1 1 +SELECT * FROM t1; +f1 f2 +1 c +2 a DROP TABLE t1; DROP TABLE t2; connection node_1a; SET DEBUG_SYNC = "RESET"; +connection node_1b; +SET DEBUG_SYNC = "RESET"; +connection node_1; +disconnect node_1a; +disconnect node_1b; +disconnect node_1c; diff --git a/mysql-test/suite/galera/t/galera_mdl_race.test b/mysql-test/suite/galera/t/galera_mdl_race.test index ad6770f9991..3341a3792f1 100644 --- a/mysql-test/suite/galera/t/galera_mdl_race.test +++ b/mysql-test/suite/galera/t/galera_mdl_race.test @@ -3,70 +3,92 @@ # --source include/galera_cluster.inc +--source include/have_debug.inc --source include/have_debug_sync.inc +--connection node_1 CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) engine=innodb; CREATE TABLE t2 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) engine=innodb; INSERT INTO t1 VALUES (1, 'a'); INSERT INTO t1 VALUES (2, 'a'); ---connection node_1 SET AUTOCOMMIT=ON; START TRANSACTION; - UPDATE t1 SET f2 = 'b' WHERE f1 = 1; # block access to t2 --connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 --connection node_1a +SET SESSION wsrep_sync_wait=0; +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2' +--let $wait_condition_on_error_output = SELECT * FROM INFORMATION_SCHEMA.TABLES +--source include/wait_condition_with_debug.inc LOCK TABLE t2 WRITE; -# Block before MLD lock wait +# Block before MDL lock wait --connection node_1 - SET @@debug_dbug = "d,sync.wsrep_before_mdl_wait"; +SET DEBUG_SYNC= 'wsrep_before_mdl_wait SIGNAL before_mdl_wait WAIT_FOR mdl_wait_continue'; --send SELECT * FROM t2; -# Wait for SELECT to be blocked --connection node_1a -#--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIS WHERE STATE = 'System lock'; -#--source include/wait_condition.inc -#--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE = 'init' AND INFO = 'COMMIT'; -#--source include/wait_condition.inc +--echo # Wait until select is blocked before MDL lock wait +SET DEBUG_SYNC= 'now WAIT_FOR before_mdl_wait'; # block applier to wait after BF victim is locked +--connection node_1a SET @@debug_dbug = "d,sync.wsrep_after_BF_victim_lock"; # Issue a conflicting update on node #2 --connection node_2 UPDATE t1 SET f2 = 'c' WHERE f1 = 1; -# Unblock the SELECT, to enter wsrep_thd_is_BF ---connection node_1a -SET @@debug_dbug = ""; -SET DEBUG_SYNC = "now SIGNAL signal.wsrep_before_mdl_wait"; +--connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--connection node_1b +SET SESSION wsrep_sync_wait=0; +--echo # Wait for conflicting update to block +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE 'Update_rows_log_event:%'; +--source include/wait_condition.inc -# unblock applier to try to BF the SELECT +# Unblock the SELECT, to enter wsrep_thd_is_BF SET DEBUG_SYNC = "now SIGNAL signal.wsrep_after_BF_victim_lock"; +--connect node_1c, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--connection node_1c +--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE 'Update_rows_log_event:%'; +--source include/wait_condition.inc + +--connection node_1a +# unblock applier to try to BF the SELECT +SET DEBUG_SYNC = "now SIGNAL BF_victim_continue"; + # table lock is not needed anymore UNLOCK TABLES; -# SELECT succeeds +# SELECT returns deadlock --connection node_1 - --error ER_LOCK_DEADLOCK --reap -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a'; -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; +--connection node_1 +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'a'; +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'c'; +SELECT * FROM t1; --connection node_2 -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a'; -SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c'; +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'a'; +SELECT COUNT(*) AS EXPECT_1 FROM t1 WHERE f2 = 'c'; +SELECT * FROM t1; DROP TABLE t1; DROP TABLE t2; --connection node_1a SET DEBUG_SYNC = "RESET"; +--connection node_1b +SET DEBUG_SYNC = "RESET"; + +--connection node_1 +--disconnect node_1a +--disconnect node_1b +--disconnect node_1c diff --git a/sql/mdl.cc b/sql/mdl.cc index 7aae1c16022..b2a9d52bd82 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -1176,15 +1176,8 @@ MDL_wait::timed_wait(MDL_context_owner *owner, struct timespec *abs_timeout, { #ifdef WITH_WSREP # ifdef ENABLED_DEBUG_SYNC - // Allow tests to block the applier thread using the DBUG facilities - DBUG_EXECUTE_IF("sync.wsrep_before_mdl_wait", - { - const char act[]= - "now " - "wait_for signal.wsrep_before_mdl_wait"; - DBUG_ASSERT(!debug_sync_set_action((owner->get_thd()), - STRING_WITH_LEN(act))); - };); + // Allow tests to block thread before MDL-wait + DEBUG_SYNC(owner->get_thd(), "wsrep_before_mdl_wait"); # endif if (WSREP_ON && wsrep_thd_is_BF(owner->get_thd(), false)) { From f8fa3c55c66e6ebec889299ec9db3e4e83b38c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 4 Jan 2024 16:46:47 +0200 Subject: [PATCH 09/21] MDEV-33173 : Galera test case galera_sr_kill_slave_before_apply unstable Add wait_condition to make sure tables are created before next operations. Signed-off-by: Julius Goryavsky --- .../r/galera_sr_kill_slave_before_apply.result | 16 ++++++++-------- .../t/galera_sr_kill_slave_before_apply.test | 13 +++++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/galera_3nodes_sr/r/galera_sr_kill_slave_before_apply.result b/mysql-test/suite/galera_3nodes_sr/r/galera_sr_kill_slave_before_apply.result index 933038e00f1..ef2bd7a45e1 100644 --- a/mysql-test/suite/galera_3nodes_sr/r/galera_sr_kill_slave_before_apply.result +++ b/mysql-test/suite/galera_3nodes_sr/r/galera_sr_kill_slave_before_apply.result @@ -7,11 +7,11 @@ connection node_3; connection node_1; CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; connection node_2; -SELECT COUNT(*) = 0 FROM t1; -COUNT(*) = 0 -1 +SELECT COUNT(*) AS EXPECT_0 FROM t1; +EXPECT_0 +0 connection node_1; -CREATE TABLE t2 (f1 INTEGER); +CREATE TABLE t2 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; LOCK TABLE t2 WRITE; connection node_1; @@ -37,12 +37,12 @@ count_match count_match 1 connection node_1; -SELECT COUNT(*) FROM mysql.wsrep_streaming_log; -COUNT(*) +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 0 connection node_2; -SELECT COUNT(*) FROM mysql.wsrep_streaming_log; -COUNT(*) +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 0 connection node_1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes_sr/t/galera_sr_kill_slave_before_apply.test b/mysql-test/suite/galera_3nodes_sr/t/galera_sr_kill_slave_before_apply.test index 08a59296e41..355db2de456 100644 --- a/mysql-test/suite/galera_3nodes_sr/t/galera_sr_kill_slave_before_apply.test +++ b/mysql-test/suite/galera_3nodes_sr/t/galera_sr_kill_slave_before_apply.test @@ -15,18 +15,23 @@ --source ../galera/include/auto_increment_offset_save.inc --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc + CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; # Block node #2's applier before table t1's inserts have come into play --connection node_2 -SELECT COUNT(*) = 0 FROM t1; +SELECT COUNT(*) AS EXPECT_0 FROM t1; --connection node_1 -CREATE TABLE t2 (f1 INTEGER); +CREATE TABLE t2 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2' +--source include/wait_condition.inc LOCK TABLE t2 WRITE; --connection node_1 @@ -77,10 +82,10 @@ if ($mysql_errno == 1213) { --enable_query_log --connection node_1 -SELECT COUNT(*) FROM mysql.wsrep_streaming_log; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; --connection node_2 -SELECT COUNT(*) FROM mysql.wsrep_streaming_log; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; --connection node_1 DROP TABLE t1; From 57ffcd686ffa6c3b26a0da5f3f08f1f2117677d7 Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 29 Jan 2024 15:51:29 +0200 Subject: [PATCH 10/21] MDEV-21472: ALTER TABLE ... ANALYZE PARTITION ... with EITS reads and locks all rows This was fixed in 10.2 in 2020 but merging the code to 10.3 caused the bug to come back. --- .../main/column_compression_parts.result | 1 - mysql-test/main/partition.result | 1 - mysql-test/main/partition_binlog.result | 1 - mysql-test/main/stat_tables_partition.result | 3 +-- mysql-test/main/stat_tables_rbr.result | 1 - .../parts/r/partition_alter4_innodb.result | 24 ------------------- .../parts/r/partition_alter4_myisam.result | 24 ------------------- .../parts/r/partition_mgm_lc0_innodb.result | 1 - .../parts/r/partition_mgm_lc0_memory.result | 1 - .../parts/r/partition_mgm_lc0_myisam.result | 1 - .../parts/r/partition_mgm_lc1_innodb.result | 1 - .../parts/r/partition_mgm_lc1_memory.result | 1 - .../parts/r/partition_mgm_lc1_myisam.result | 1 - .../rpl/r/rpl_mark_optimize_tbl_ddl.result | 1 - sql/sql_admin.cc | 2 +- 15 files changed, 2 insertions(+), 62 deletions(-) diff --git a/mysql-test/main/column_compression_parts.result b/mysql-test/main/column_compression_parts.result index fa12217ce22..5f5539b723c 100644 --- a/mysql-test/main/column_compression_parts.result +++ b/mysql-test/main/column_compression_parts.result @@ -12,7 +12,6 @@ INSERT INTO t1 VALUES (1,REPEAT('a',100)),(2,REPEAT('v',200)),(3,REPEAT('r',300) INSERT INTO t1 VALUES (5,REPEAT('k',500)),(6,'April'),(7,7),(8,""),(9,"M"),(10,DEFAULT); ALTER TABLE t1 ANALYZE PARTITION p1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK ALTER TABLE t1 CHECK PARTITION p2; Table Op Msg_type Msg_text diff --git a/mysql-test/main/partition.result b/mysql-test/main/partition.result index 79bfef652f4..b847b6b1b50 100644 --- a/mysql-test/main/partition.result +++ b/mysql-test/main/partition.result @@ -2063,7 +2063,6 @@ ALTER TABLE t1 ANALYZE PARTITION p1 EXTENDED; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXTENDED' at line 1 ALTER TABLE t1 ANALYZE PARTITION p1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK ALTER TABLE t1 CHECK PARTITION p1; Table Op Msg_type Msg_text diff --git a/mysql-test/main/partition_binlog.result b/mysql-test/main/partition_binlog.result index 3e6100b51d8..21eca8f1c00 100644 --- a/mysql-test/main/partition_binlog.result +++ b/mysql-test/main/partition_binlog.result @@ -27,7 +27,6 @@ Table Op Msg_type Msg_text test.t1 repair error Error in list of partitions to test.t1 ALTER TABLE t1 ANALYZE PARTITION p0; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK ALTER TABLE t1 CHECK PARTITION p0; Table Op Msg_type Msg_text diff --git a/mysql-test/main/stat_tables_partition.result b/mysql-test/main/stat_tables_partition.result index 2619026b231..2dd63e858d4 100644 --- a/mysql-test/main/stat_tables_partition.result +++ b/mysql-test/main/stat_tables_partition.result @@ -34,13 +34,12 @@ set session use_stat_tables='preferably'; # Must NOT show "Engine-independent statistics collected": alter table t1 analyze partition p0; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK # Should not have Handler_read_rnd_next=34 show session status like 'Handler_read_rnd%'; Variable_name Value Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 34 +Handler_read_rnd_next 0 drop table t1; SET use_stat_tables = DEFAULT; diff --git a/mysql-test/main/stat_tables_rbr.result b/mysql-test/main/stat_tables_rbr.result index 38f774412bd..9d5e7f85530 100644 --- a/mysql-test/main/stat_tables_rbr.result +++ b/mysql-test/main/stat_tables_rbr.result @@ -17,7 +17,6 @@ SET use_stat_tables = PREFERABLY; CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; ALTER TABLE t1 ANALYZE PARTITION p1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info diff --git a/mysql-test/suite/parts/r/partition_alter4_innodb.result b/mysql-test/suite/parts/r/partition_alter4_innodb.result index c9a80c6035b..c91d140b393 100644 --- a/mysql-test/suite/parts/r/partition_alter4_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter4_innodb.result @@ -60,7 +60,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -521,7 +520,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -993,7 +991,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -1466,7 +1463,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -1933,7 +1929,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -2406,7 +2401,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -2884,7 +2878,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -3360,7 +3353,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -3826,7 +3818,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -4287,7 +4278,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -4759,7 +4749,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -5232,7 +5221,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -5699,7 +5687,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -6172,7 +6159,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -6650,7 +6636,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -7126,7 +7111,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -15108,7 +15092,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -15569,7 +15552,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -16041,7 +16023,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -16514,7 +16495,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -16981,7 +16961,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -17454,7 +17433,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -17932,7 +17910,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -18408,7 +18385,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template diff --git a/mysql-test/suite/parts/r/partition_alter4_myisam.result b/mysql-test/suite/parts/r/partition_alter4_myisam.result index 4e9e5c83248..01d368dbe75 100644 --- a/mysql-test/suite/parts/r/partition_alter4_myisam.result +++ b/mysql-test/suite/parts/r/partition_alter4_myisam.result @@ -60,7 +60,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -530,7 +529,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -1017,7 +1015,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -1511,7 +1508,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -1995,7 +1991,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -2489,7 +2484,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -2988,7 +2982,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -3485,7 +3478,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -3974,7 +3966,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -4444,7 +4435,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -4931,7 +4921,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -5425,7 +5414,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -5909,7 +5897,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -6403,7 +6390,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -6902,7 +6888,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -7399,7 +7384,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -15700,7 +15684,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -16170,7 +16153,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -16657,7 +16639,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -17151,7 +17132,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -17635,7 +17615,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -18129,7 +18108,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -18628,7 +18606,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template @@ -19125,7 +19102,6 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 ANALYZE PARTITION ALL; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result b/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result index 88784224723..28dcddd9aef 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result @@ -1020,7 +1020,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -MySQL_Test_DB.t1 analyze status Engine-independent statistics collected MySQL_Test_DB.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result b/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result index 92457a21043..204ef94da6e 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result @@ -1020,7 +1020,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -MySQL_Test_DB.t1 analyze status Engine-independent statistics collected MySQL_Test_DB.t1 analyze note The storage engine for the table doesn't support analyze # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result b/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result index fea80a3feb3..10f8fbe11a4 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result @@ -1020,7 +1020,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -MySQL_Test_DB.t1 analyze status Engine-independent statistics collected MySQL_Test_DB.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result b/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result index 418650eb438..d9b677acf5a 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result @@ -987,7 +987,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -mysql_test_db.t1 analyze status Engine-independent statistics collected mysql_test_db.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result b/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result index 96e72cbfb41..601f6cb7812 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result @@ -987,7 +987,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -mysql_test_db.t1 analyze status Engine-independent statistics collected mysql_test_db.t1 analyze note The storage engine for the table doesn't support analyze # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result b/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result index 0ab07cdc993..936f972ddb8 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result @@ -987,7 +987,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -mysql_test_db.t1 analyze status Engine-independent statistics collected mysql_test_db.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result b/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result index 9aa31a73e49..09edd28827b 100644 --- a/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result +++ b/mysql-test/suite/rpl/r/rpl_mark_optimize_tbl_ddl.result @@ -55,7 +55,6 @@ PARTITION pmax VALUES LESS THAN (MAXVALUE)); INSERT INTO t1 VALUES (1), (10), (100), (1000); ALTER TABLE t1 ANALYZE PARTITION p0; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK ALTER TABLE t1 OPTIMIZE PARTITION p0; Table Op Msg_type Msg_text diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 09deef9f590..8c9c185781e 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -853,7 +853,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, */ collect_eis= (table->table->s->table_category == TABLE_CATEGORY_USER && - !(lex->alter_info.flags & ALTER_PARTITION_ADMIN) && + !(lex->alter_info.partition_flags & ALTER_PARTITION_ADMIN) && (check_eits_collection_allowed(thd) || lex->with_persistent_for_clause)); } From bc2849579b4ababc7f990255245e0d26ba36c87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 30 Jan 2024 13:10:46 +0200 Subject: [PATCH 11/21] MDEV-33251 Redundant check on prebuilt::n_rows_fetched overflow row_search_mvcc(): Revise an overflow check, disabling it on 64-bit systems. The maximum number of consecutive record reads in a key range scan should be limited by the maximum number of records per page (less than 2^13) and the maximum number of pages per tablespace (2^32) to less than 2^45. On 32-bit systems we can simplify the overflow check. Reviewed by: Vladislav Lesin --- storage/innobase/row/row0sel.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 4504fabd4e0..b217f6d20fe 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -4406,13 +4406,11 @@ row_search_mvcc( goto func_exit; } +#if SIZEOF_SIZE_T < 8 + if (UNIV_LIKELY(~prebuilt->n_rows_fetched)) +#endif prebuilt->n_rows_fetched++; - if (prebuilt->n_rows_fetched > 1000000000) { - /* Prevent wrap-over */ - prebuilt->n_rows_fetched = 500000000; - } - mode = pcur->search_mode; } From b7d1f65b819296dde35beb92771958e9ab8c0e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 30 Jan 2024 13:10:53 +0200 Subject: [PATCH 12/21] MDEV-12266 fixup: Remove dead code Ever since commit 5e84ea9634ac491f3da84f6c15987d4c1b1a5a3a this "else if" branch was unreachable because the preceding "if" condition covered it. --- storage/innobase/handler/ha_innodb.cc | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 1f181032333..62fe6bda283 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -14840,16 +14840,6 @@ ha_innobase::check( table->s->table_name.str); DBUG_RETURN(HA_ADMIN_CORRUPT); - - } else if (!m_prebuilt->table->is_readable() && - !m_prebuilt->table->space) { - - ib_senderrf( - thd, IB_LOG_LEVEL_ERROR, - ER_TABLESPACE_MISSING, - table->s->table_name.str); - - DBUG_RETURN(HA_ADMIN_CORRUPT); } m_prebuilt->trx->op_info = "checking table"; From f4ee7c110cd6faee3fa80b61ae572f471341c906 Mon Sep 17 00:00:00 2001 From: Denis Protivensky Date: Thu, 30 Nov 2023 12:52:53 +0300 Subject: [PATCH 13/21] MDEV-22232 Fix test after changing behavior of ALTER DROP FOREIGN KEY Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MDEV-22232.result | 12 +++++----- mysql-test/suite/galera/t/MDEV-22232.test | 26 ++++++++------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/mysql-test/suite/galera/r/MDEV-22232.result b/mysql-test/suite/galera/r/MDEV-22232.result index a6a619458f0..79db271bc50 100644 --- a/mysql-test/suite/galera/r/MDEV-22232.result +++ b/mysql-test/suite/galera/r/MDEV-22232.result @@ -3,21 +3,21 @@ connection node_1; connect con1,127.0.0.1,root,,test,$NODE_MYPORT_1; --- CTAS with empty result set --- CREATE TABLE t1 (a INT) ENGINE=InnoDB; -SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_alter WAIT_FOR bf_abort'; +SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_run WAIT_FOR bf_abort'; CREATE TABLE t2 SELECT * FROM t1; connection node_1; -SET DEBUG_SYNC = 'now WAIT_FOR may_alter'; -ALTER TABLE t1 DROP FOREIGN KEY b, ALGORITHM=COPY; +SET DEBUG_SYNC = 'now WAIT_FOR may_run'; +TRUNCATE TABLE t1; connection con1; ERROR 70100: Query execution was interrupted SET DEBUG_SYNC = 'RESET'; --- CTAS with non-empty result set --- INSERT INTO t1 VALUES (10), (20), (30); -SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_alter WAIT_FOR bf_abort'; +SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_run WAIT_FOR bf_abort'; CREATE TABLE t2 SELECT * FROM t1; connection node_1; -SET DEBUG_SYNC = 'now WAIT_FOR may_alter'; -ALTER TABLE t1 DROP FOREIGN KEY b, ALGORITHM=COPY; +SET DEBUG_SYNC = 'now WAIT_FOR may_run'; +TRUNCATE TABLE t1; connection con1; ERROR 70100: Query execution was interrupted SET DEBUG_SYNC = 'RESET'; diff --git a/mysql-test/suite/galera/t/MDEV-22232.test b/mysql-test/suite/galera/t/MDEV-22232.test index edb42ee603c..087d6417b01 100644 --- a/mysql-test/suite/galera/t/MDEV-22232.test +++ b/mysql-test/suite/galera/t/MDEV-22232.test @@ -18,19 +18,16 @@ CREATE TABLE t1 (a INT) ENGINE=InnoDB; # Run CTAS until the resulting table gets created, -# then it gets BF aborted by ALTER. -SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_alter WAIT_FOR bf_abort'; +# then it gets BF aborted by other DDL. +SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_run WAIT_FOR bf_abort'; --send CREATE TABLE t2 SELECT * FROM t1; # Wait for CTAS to reach the table create point, -# start executing ALTER and BF abort CTAS. +# start executing other DDL and BF abort CTAS. --connection node_1 -SET DEBUG_SYNC = 'now WAIT_FOR may_alter'; ---disable_result_log ---error ER_ERROR_ON_RENAME -ALTER TABLE t1 DROP FOREIGN KEY b, ALGORITHM=COPY; ---enable_result_log +SET DEBUG_SYNC = 'now WAIT_FOR may_run'; +TRUNCATE TABLE t1; --connection con1 # CTAS gets BF aborted. @@ -46,19 +43,16 @@ SET DEBUG_SYNC = 'RESET'; INSERT INTO t1 VALUES (10), (20), (30); # Run CTAS until the resulting table gets created, -# then it gets BF aborted by ALTER. -SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_alter WAIT_FOR bf_abort'; +# then it gets BF aborted by other DDL. +SET DEBUG_SYNC = 'create_table_select_before_create SIGNAL may_run WAIT_FOR bf_abort'; --send CREATE TABLE t2 SELECT * FROM t1; # Wait for CTAS to reach the table create point, -# start executing ALTER and BF abort CTAS. +# start executing other DDL and BF abort CTAS. --connection node_1 -SET DEBUG_SYNC = 'now WAIT_FOR may_alter'; ---disable_result_log ---error ER_ERROR_ON_RENAME -ALTER TABLE t1 DROP FOREIGN KEY b, ALGORITHM=COPY; ---enable_result_log +SET DEBUG_SYNC = 'now WAIT_FOR may_run'; +TRUNCATE TABLE t1; --connection con1 # CTAS gets BF aborted. From 05314ed0d48cb5a505a8f884015448d0023f81f5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 31 Jan 2024 23:50:41 -0800 Subject: [PATCH 14/21] MDEV-31305 Crash caused by query with aggregation over materialized derived This bug was fixed by the patch for bug MDEV-30706. Only a test case is added in this commit. --- mysql-test/main/derived_view.result | 34 +++++++++++++++++++++++++++ mysql-test/main/derived_view.test | 36 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/mysql-test/main/derived_view.result b/mysql-test/main/derived_view.result index ca96b741bdd..32cc48a4bc6 100644 --- a/mysql-test/main/derived_view.result +++ b/mysql-test/main/derived_view.result @@ -4217,4 +4217,38 @@ a drop table t1, t2; drop view v1; drop procedure aproc; +# +# MDEV-31305: Aggregation over materialized derived table +# +CREATE VIEW v AS +SELECT seq1.seq AS dim1, seq2.seq AS dim2, seq3.seq AS dim3, +FLOOR(RAND(13) * 5) AS p +FROM seq_100_to_105 seq1 +JOIN seq_10_to_15 seq2 +JOIN seq_1_to_5 seq3; +SELECT v.*, SUM(p) from v; +dim1 dim2 dim3 p SUM(p) +100 10 1 2 371 +SELECT d.*, SUM(p) +FROM ( +SELECT seq1.seq AS dim1, seq2.seq AS dim2, seq3.seq AS dim3, +FLOOR(RAND(13) * 5) AS p +FROM seq_100_to_105 seq1 +JOIN seq_10_to_15 seq2 +JOIN seq_1_to_5 seq3 +) d; +dim1 dim2 dim3 p SUM(p) +100 10 1 2 371 +WITH demo AS +( +SELECT seq1.seq AS dim1, seq2.seq AS dim2, seq3.seq AS dim3, +FLOOR(RAND(13) * 5) AS p +FROM seq_100_to_105 seq1 +JOIN seq_10_to_15 seq2 +JOIN seq_1_to_5 seq3 +) +SELECT d.*, SUM(p) FROM demo d; +dim1 dim2 dim3 p SUM(p) +100 10 1 2 371 +DROP VIEW v; # End of 10.4 tests diff --git a/mysql-test/main/derived_view.test b/mysql-test/main/derived_view.test index 48ed2a0a4b7..f9ab0443bc0 100644 --- a/mysql-test/main/derived_view.test +++ b/mysql-test/main/derived_view.test @@ -2795,4 +2795,40 @@ drop table t1, t2; drop view v1; drop procedure aproc; +--echo # +--echo # MDEV-31305: Aggregation over materialized derived table +--echo # + +--source include/have_sequence.inc + +CREATE VIEW v AS + SELECT seq1.seq AS dim1, seq2.seq AS dim2, seq3.seq AS dim3, + FLOOR(RAND(13) * 5) AS p + FROM seq_100_to_105 seq1 + JOIN seq_10_to_15 seq2 + JOIN seq_1_to_5 seq3; + +SELECT v.*, SUM(p) from v; + +SELECT d.*, SUM(p) + FROM ( + SELECT seq1.seq AS dim1, seq2.seq AS dim2, seq3.seq AS dim3, + FLOOR(RAND(13) * 5) AS p + FROM seq_100_to_105 seq1 + JOIN seq_10_to_15 seq2 + JOIN seq_1_to_5 seq3 +) d; + +WITH demo AS +( + SELECT seq1.seq AS dim1, seq2.seq AS dim2, seq3.seq AS dim3, + FLOOR(RAND(13) * 5) AS p + FROM seq_100_to_105 seq1 + JOIN seq_10_to_15 seq2 + JOIN seq_1_to_5 seq3 +) +SELECT d.*, SUM(p) FROM demo d; + +DROP VIEW v; + --echo # End of 10.4 tests From 3812e1c95886c23aba418c4ecaed0d3d6aeec3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Sun, 4 Feb 2024 11:58:31 -0800 Subject: [PATCH 15/21] Fix commit 179424db: No test file or result files should be executable In commit 179424db the file lowercase_table2.result was made executable for no known reason, most likely just a mistake. Test result files definitely should not be executable. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/lowercase_table2.result | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 mysql-test/main/lowercase_table2.result diff --git a/mysql-test/main/lowercase_table2.result b/mysql-test/main/lowercase_table2.result old mode 100755 new mode 100644 From 23101304887e9e1987c45f001377382e3fdfd88f Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Tue, 6 Feb 2024 12:15:02 -0500 Subject: [PATCH 16/21] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ed7e2ff7acf..40ebea15b87 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=4 -MYSQL_VERSION_PATCH=33 +MYSQL_VERSION_PATCH=34 SERVER_MATURITY=stable From 85db5347311340e39753b0200fb9d459a5024535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 7 Feb 2024 12:26:59 +0200 Subject: [PATCH 17/21] MDEV-33400 Adaptive hash index corruption after DISCARD TABLESPACE row_discard_tablespace(): Do not invoke dict_index_t::clear_instant_alter() because that would corrupt any adaptive hash index entries in the table. row_import_for_mysql(): Invoke dict_index_t::clear_instant_alter() after detaching any adaptive hash index entries. --- mysql-test/suite/innodb/r/import_bugs.result | 16 ++++++++++ mysql-test/suite/innodb/t/import_bugs.test | 19 ++++++++++++ storage/innobase/row/row0import.cc | 32 +++++++++++--------- storage/innobase/row/row0mysql.cc | 1 - 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/mysql-test/suite/innodb/r/import_bugs.result b/mysql-test/suite/innodb/r/import_bugs.result index a52fe6abbd6..7ed73296954 100644 --- a/mysql-test/suite/innodb/r/import_bugs.result +++ b/mysql-test/suite/innodb/r/import_bugs.result @@ -10,3 +10,19 @@ ALTER TABLE imp_t1 IMPORT TABLESPACE; ERROR HY000: Schema mismatch (ROW_FORMAT mismatch) DROP TABLE imp_t1, t1; SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm; +# +# MDEV-33400 Adaptive hash index corruption after DISCARD TABLESPACE +# +SET @save_adaptive=@@GLOBAL.innodb_adaptive_hash_index; +SET GLOBAL innodb_adaptive_hash_index=ON; +CREATE TABLE t (a INT PRIMARY KEY) ENGINE=INNODB; +INSERT INTO t SELECT * FROM seq_1_to_131; +ALTER TABLE t ADD hid INT DEFAULT 2; +INSERT INTO t VALUES (251,1); +ALTER TABLE t DISCARD TABLESPACE; +CHECK TABLE mysql.innodb_table_stats; +Table Op Msg_type Msg_text +mysql.innodb_table_stats check status OK +DROP TABLE t; +SET GLOBAL innodb_adaptive_hash_index=@save_adaptive; +# End of 10.4 tests diff --git a/mysql-test/suite/innodb/t/import_bugs.test b/mysql-test/suite/innodb/t/import_bugs.test index 42bb5d90ef9..32e349f1791 100644 --- a/mysql-test/suite/innodb/t/import_bugs.test +++ b/mysql-test/suite/innodb/t/import_bugs.test @@ -1,4 +1,5 @@ --source include/have_innodb.inc +--source include/have_sequence.inc call mtr.add_suppression("Index for table 'imp_t1' is corrupt; try to repair it"); @@ -17,3 +18,21 @@ ALTER TABLE imp_t1 IMPORT TABLESPACE; DROP TABLE imp_t1, t1; SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm; + +--echo # +--echo # MDEV-33400 Adaptive hash index corruption after DISCARD TABLESPACE +--echo # + +SET @save_adaptive=@@GLOBAL.innodb_adaptive_hash_index; +SET GLOBAL innodb_adaptive_hash_index=ON; + +CREATE TABLE t (a INT PRIMARY KEY) ENGINE=INNODB; +INSERT INTO t SELECT * FROM seq_1_to_131; +ALTER TABLE t ADD hid INT DEFAULT 2; +INSERT INTO t VALUES (251,1); +ALTER TABLE t DISCARD TABLESPACE; +CHECK TABLE mysql.innodb_table_stats; +DROP TABLE t; +SET GLOBAL innodb_adaptive_hash_index=@save_adaptive; + +--echo # End of 10.4 tests diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index 608a739001c..a029873da90 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -4383,6 +4383,23 @@ row_import_for_mysql( ibuf_delete_for_discarded_space(table->space_id); +#ifdef BTR_CUR_HASH_ADAPT + /* On DISCARD TABLESPACE, we did not drop any adaptive hash + index entries. If we replaced the discarded tablespace with a + smaller one here, there could still be some adaptive hash + index entries that point to cached garbage pages in the buffer + pool, because PageConverter::operator() only evicted those + pages that were replaced by the imported pages. We must + detach any remaining adaptive hash index entries, because the + adaptive hash index must be a subset of the table contents; + false positives are not tolerated. */ + for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes); index; + index = UT_LIST_GET_NEXT(indexes, index)) { + index = index->clone_if_needed(); + } +#endif /* BTR_CUR_HASH_ADAPT */ + UT_LIST_GET_FIRST(table->indexes)->clear_instant_alter(); + trx_start_if_not_started(prebuilt->trx, true); trx = trx_create(); @@ -4540,21 +4557,6 @@ row_import_for_mysql( DBUG_EXECUTE_IF("ib_import_reset_space_and_lsn_failure", err = DB_TOO_MANY_CONCURRENT_TRXS;); -#ifdef BTR_CUR_HASH_ADAPT - /* On DISCARD TABLESPACE, we did not drop any adaptive hash - index entries. If we replaced the discarded tablespace with a - smaller one here, there could still be some adaptive hash - index entries that point to cached garbage pages in the buffer - pool, because PageConverter::operator() only evicted those - pages that were replaced by the imported pages. We must - detach any remaining adaptive hash index entries, because the - adaptive hash index must be a subset of the table contents; - false positives are not tolerated. */ - for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes); index; - index = UT_LIST_GET_NEXT(indexes, index)) { - index = index->clone_if_needed(); - } -#endif /* BTR_CUR_HASH_ADAPT */ if (err != DB_SUCCESS) { char table_name[MAX_FULL_NAME_LEN + 1]; diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index dc3d0ca2ade..2a594b0839c 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -3047,7 +3047,6 @@ row_discard_tablespace( dict_table_change_id_in_cache(table, new_id); dict_index_t* index = UT_LIST_GET_FIRST(table->indexes); - if (index) index->clear_instant_alter(); /* Reset the root page numbers. */ for (; index; index = UT_LIST_GET_NEXT(indexes, index)) { From 6b2cd7869522a140329a27583f965b8662d7f5f5 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 8 Feb 2024 12:12:57 +0700 Subject: [PATCH 18/21] MDEV-15703: Crash in EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT, UBSAN runtime error: member call on null pointer of type 'struct TABLE_LIST' in Item_param::save_in_field This is the prerequisite patch to refactor the method Item_default_value::fix_fields. The former implementation of this method was extracted and placed into the standalone function make_default_field() and the method Item_default_value::tie_field(). The motivation for this modification is upcoming changes for core implementation of the task MDEV-15703 since these functions will be used from several places within the source code. --- extra/wolfssl/wolfssl | 2 +- libmariadb | 2 +- sql/item.cc | 159 ++++++++++++++++++++++++++---------------- sql/item.h | 3 + 4 files changed, 104 insertions(+), 62 deletions(-) diff --git a/extra/wolfssl/wolfssl b/extra/wolfssl/wolfssl index 66596ad9e1d..3b3c175af0e 160000 --- a/extra/wolfssl/wolfssl +++ b/extra/wolfssl/wolfssl @@ -1 +1 @@ -Subproject commit 66596ad9e1d7efa8479656872cf09c9c1870a02e +Subproject commit 3b3c175af0e993ffaae251871421e206cc41963f diff --git a/libmariadb b/libmariadb index 9155b19b462..ae565eea90d 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit 9155b19b462ac15fc69d0b58ae51370b7523ced5 +Subproject commit ae565eea90dd3053a5a7857e7cdad93342dbc645 diff --git a/sql/item.cc b/sql/item.cc index 04b689f51af..8a52a0ec7c5 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4969,6 +4969,44 @@ bool Item_param::append_for_log(THD *thd, String *str) } +/** + Allocate a memory and create on it a copy of Field object. + + @param thd thread handler + @param field_arg an instance of Field the new Field object be based on + + @return a new created Field object on success, nullptr on error. +*/ + +static Field *make_default_field(THD *thd, Field *field_arg) +{ + Field *def_field; + + if (!(def_field= (Field*) thd->alloc(field_arg->size_of()))) + return nullptr; + + memcpy((void *)def_field, (void *)field_arg, field_arg->size_of()); + def_field->reset_fields(); + // If non-constant default value expression or a blob + if (def_field->default_value && + (def_field->default_value->flags || (def_field->flags & BLOB_FLAG))) + { + uchar *newptr= (uchar*) thd->alloc(1+def_field->pack_length()); + if (!newptr) + return nullptr; + + if (should_mark_column(thd->column_usage)) + def_field->default_value->expr->update_used_tables(); + def_field->move_field(newptr + 1, def_field->maybe_null() ? newptr : 0, 1); + } + else + def_field->move_field_offset((my_ptrdiff_t) + (def_field->table->s->default_values - + def_field->table->record[0])); + return def_field; +} + + /**************************************************************************** Item_copy_string ****************************************************************************/ @@ -9446,69 +9484,10 @@ bool Item_default_value::update_func_default_processor(void *) bool Item_default_value::fix_fields(THD *thd, Item **items) { - Item *real_arg; - Item_field *field_arg; - Field *def_field; DBUG_ASSERT(fixed == 0); DBUG_ASSERT(arg); - /* - DEFAULT() do not need table field so should not ask handler to bring - field value (mark column for read) - */ - enum_column_usage save_column_usage= thd->column_usage; - /* - Fields which has defult value could be read, so it is better hide system - invisible columns. - */ - thd->column_usage= COLUMNS_WRITE; - if (arg->fix_fields_if_needed(thd, &arg)) - { - thd->column_usage= save_column_usage; - goto error; - } - thd->column_usage= save_column_usage; - - real_arg= arg->real_item(); - if (real_arg->type() != FIELD_ITEM) - { - my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name.str); - goto error; - } - - field_arg= (Item_field *)real_arg; - if ((field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)) - { - my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), - field_arg->field->field_name.str); - goto error; - } - if (!(def_field= (Field*) thd->alloc(field_arg->field->size_of()))) - goto error; - memcpy((void *)def_field, (void *)field_arg->field, - field_arg->field->size_of()); - def_field->reset_fields(); - // If non-constant default value expression or a blob - if (def_field->default_value && - (def_field->default_value->flags || (def_field->flags & BLOB_FLAG))) - { - uchar *newptr= (uchar*) thd->alloc(1+def_field->pack_length()); - if (!newptr) - goto error; - if (should_mark_column(thd->column_usage)) - def_field->default_value->expr->update_used_tables(); - def_field->move_field(newptr+1, def_field->maybe_null() ? newptr : 0, 1); - } - else - def_field->move_field_offset((my_ptrdiff_t) - (def_field->table->s->default_values - - def_field->table->record[0])); - set_field(def_field); - return FALSE; - -error: - context->process_error(thd); - return TRUE; + return tie_field(thd); } void Item_default_value::cleanup() @@ -9696,6 +9675,66 @@ Item *Item_default_value::transform(THD *thd, Item_transformer transformer, } +/** + Call fix_fields for an item representing the default value, create + an instance of Field for representing the default value and assign it + to the Item_field::field. + + @param thd thread handler + + @return false on success, true on error +*/ + +bool Item_default_value::tie_field(THD *thd) +{ + Item *real_arg; + Item_field *field_arg; + Field *def_field; + + /* + DEFAULT() do not need table field so should not ask handler to bring + field value (mark column for read) + */ + enum_column_usage save_column_usage= thd->column_usage; + /* + Fields which has defult value could be read, so it is better hide system + invisible columns. + */ + thd->column_usage= COLUMNS_WRITE; + if (arg->fix_fields_if_needed(thd, &arg)) + { + thd->column_usage= save_column_usage; + goto error; + } + thd->column_usage= save_column_usage; + + real_arg= arg->real_item(); + if (real_arg->type() != FIELD_ITEM) + { + my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name.str); + goto error; + } + + field_arg= (Item_field *)real_arg; + if ((field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)) + { + my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), + field_arg->field->field_name.str); + goto error; + } + def_field= make_default_field(thd, field_arg->field); + if (!def_field) + goto error; + + set_field(def_field); + return false; + +error: + context->process_error(thd); + return true; + +} + bool Item_insert_value::eq(const Item *item, bool binary_cmp) const { return item->type() == INSERT_VALUE_ITEM && diff --git a/sql/item.h b/sql/item.h index 3d971230413..db4de2c035e 100644 --- a/sql/item.h +++ b/sql/item.h @@ -6580,6 +6580,9 @@ public: Item *transform(THD *thd, Item_transformer transformer, uchar *args); Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, const Tmp_field_param *param); + +private: + bool tie_field(THD *thd); }; From e48bd474a2aeb4ecb71fe2d773e11780ea4271fb Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 8 Feb 2024 12:17:02 +0700 Subject: [PATCH 19/21] MDEV-15703: Crash in EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT This patch fixes the issue with passing the DEFAULT or IGNORE values to positional parameters for some kind of SQL statements to be executed as prepared statements. The main idea of the patch is to associate an actual value being passed by the USING clause with the positional parameter represented by the Item_param class. Such association must be performed on execution of UPDATE statement in PS/SP mode. Other corner cases that results in server crash is on handling CREATE TABLE when positional parameter placed after the DEFAULT clause or CALL statement and passing either the value DEFAULT or IGNORE as an actual value for the positional parameter. This case is fixed by checking whether an error is set in diagnostics area at the function pack_vcols() on return from the function pack_expression() --- mysql-test/main/ps.result | 118 +++++++++++++++++++++ mysql-test/main/ps.test | 119 ++++++++++++++++++++++ mysql-test/main/table_value_constr.result | 4 +- mysql-test/main/table_value_constr.test | 4 +- sql/field.cc | 27 +++++ sql/field.h | 9 ++ sql/item.cc | 70 ++++++++++++- sql/item.h | 40 +++++++- sql/sql_base.cc | 11 +- sql/sql_base.h | 3 +- sql/sql_expression_cache.cc | 3 +- sql/sql_select.cc | 3 +- sql/sql_show.cc | 2 +- sql/sql_union.cc | 6 +- sql/sql_update.cc | 6 +- sql/unireg.cc | 10 +- 16 files changed, 418 insertions(+), 17 deletions(-) diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index 32560ab2b2c..4ed0e71a29a 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -5815,5 +5815,123 @@ GROUP_CONCAT(@x) 0 DROP TABLE t; # +# MDEV-15703: Crash in EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT +# +PREPARE stmt FROM 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)'; +EXECUTE stmt USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)'; +EXECUTE stmt USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +DEALLOCATE PREPARE stmt; +EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'BEGIN NOT ATOMIC DECLARE a INT DEFAULT ?; END' USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'BEGIN NOT ATOMIC DECLARE a INT DEFAULT ?; END' USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +CREATE PROCEDURE p1(a INT) SELECT 1; +EXECUTE IMMEDIATE 'CALL p1(?)' USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'CALL p1(?)' USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +DROP PROCEDURE p1; +EXECUTE IMMEDIATE 'SELECT ? UNION SELECT 1' USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'SELECT ? UNION SELECT 1' USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION ALL SELECT 1) AS derived' USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION ALL SELECT 1) AS derived' USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION DISTINCT SELECT 1) AS derived' USING DEFAULT; +ERROR HY000: Default/ignore value is not supported for such parameter usage +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION DISTINCT SELECT 1) AS derived' USING IGNORE; +ERROR HY000: Default/ignore value is not supported for such parameter usage +# multi-update and DEFAULT +CREATE TABLE t1 (a INT, b INT DEFAULT a); +INSERT into t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT DEFAULT a); +INSERT INTO t2 VALUES (1,10),(2,30); +UPDATE t1,t2 SET t1.b = DEFAULT, t2.b = DEFAULT WHERE t1.a=t2.a; +SELECT * FROM t1; +a b +1 1 +2 2 +SELECT * FROM t2; +a b +1 1 +2 2 +# re-check the case for Prepared Statement with parameters +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES (1,2),(2,3); +INSERT INTO t2 VALUES (1,10),(2,30); +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING DEFAULT, DEFAULT; +SELECT * FROM t1; +a b +1 1 +2 2 +SELECT * FROM t2; +a b +1 1 +2 2 +DROP TABLE t1, t2; +# multi-update and IGNORE +CREATE TABLE t1 (a INT, b INT default a); +INSERT INTO t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT default a); +INSERT INTO t2 VALUES (1,10),(2,30); +UPDATE t1,t2 SET t1.b = IGNORE, t2.b = IGNORE WHERE t1.a=t2.a; +SELECT * FROM t1; +a b +1 2 +2 3 +SELECT * FROM t2; +a b +1 NULL +2 NULL +# re-check the case for Prepared Statement with parameters +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES (1,2),(2,3); +INSERT INTO t2 VALUES (1,10),(2,30); +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING IGNORE, IGNORE; +SELECT * FROM t1; +a b +1 2 +2 3 +SELECT * FROM t2; +a b +1 10 +2 30 +DROP TABLE t1, t2; +# multi-update and DEFAULT parameter (no default) +CREATE TABLE t1 (a INT, b INT NOT NULL); +INSERT INTO t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT NOT NULL); +INSERT INTO t2 VALUES (1,10),(2,30); +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING DEFAULT, DEFAULT; +ERROR HY000: Field 'b' doesn't have a default value +DROP TABLE t1, t2; +# multi-update and IGNORE parameter (no default) +CREATE TABLE t1 (a INT, b INT NOT NULL); +INSERT INTO t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT NOT NULL); +INSERT INTO t2 VALUES (1,10),(2,30); +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING IGNORE, IGNORE; +SELECT * FROM t1; +a b +1 2 +2 3 +SELECT * FROM t2; +a b +1 10 +2 30 +DROP TABLE t1, t2; +# # End of 10.4 tests # diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test index 70213e05391..e710050cb48 100644 --- a/mysql-test/main/ps.test +++ b/mysql-test/main/ps.test @@ -5243,6 +5243,125 @@ EXECUTE IMMEDIATE 'SELECT GROUP_CONCAT(@x) FROM t GROUP BY @x := f'; DROP TABLE t; +--echo # +--echo # MDEV-15703: Crash in EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT +--echo # + +PREPARE stmt FROM 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)'; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE stmt USING DEFAULT; +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)'; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE stmt USING IGNORE; +DEALLOCATE PREPARE stmt; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING IGNORE; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'BEGIN NOT ATOMIC DECLARE a INT DEFAULT ?; END' USING DEFAULT; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'BEGIN NOT ATOMIC DECLARE a INT DEFAULT ?; END' USING IGNORE; + +CREATE PROCEDURE p1(a INT) SELECT 1; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'CALL p1(?)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'CALL p1(?)' USING IGNORE; +DROP PROCEDURE p1; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT ? UNION SELECT 1' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT ? UNION SELECT 1' USING IGNORE; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION ALL SELECT 1) AS derived' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION ALL SELECT 1) AS derived' USING IGNORE; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION DISTINCT SELECT 1) AS derived' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT * FROM (SELECT ? UNION DISTINCT SELECT 1) AS derived' USING IGNORE; + +--echo # multi-update and DEFAULT +CREATE TABLE t1 (a INT, b INT DEFAULT a); +INSERT into t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT DEFAULT a); +INSERT INTO t2 VALUES (1,10),(2,30); + +UPDATE t1,t2 SET t1.b = DEFAULT, t2.b = DEFAULT WHERE t1.a=t2.a; +SELECT * FROM t1; +SELECT * FROM t2; + +--echo # re-check the case for Prepared Statement with parameters +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES (1,2),(2,3); +INSERT INTO t2 VALUES (1,10),(2,30); + +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING DEFAULT, DEFAULT; +SELECT * FROM t1; +SELECT * FROM t2; + +# Cleanup +DROP TABLE t1, t2; + +--echo # multi-update and IGNORE +CREATE TABLE t1 (a INT, b INT default a); +INSERT INTO t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT default a); +INSERT INTO t2 VALUES (1,10),(2,30); + +UPDATE t1,t2 SET t1.b = IGNORE, t2.b = IGNORE WHERE t1.a=t2.a; +SELECT * FROM t1; +SELECT * FROM t2; + +--echo # re-check the case for Prepared Statement with parameters +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES (1,2),(2,3); +INSERT INTO t2 VALUES (1,10),(2,30); + +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING IGNORE, IGNORE; +SELECT * FROM t1; +SELECT * FROM t2; + +# Cleanup +DROP TABLE t1, t2; + +--echo # multi-update and DEFAULT parameter (no default) +CREATE TABLE t1 (a INT, b INT NOT NULL); +INSERT INTO t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT NOT NULL); +INSERT INTO t2 VALUES (1,10),(2,30); + +--error ER_NO_DEFAULT_FOR_FIELD +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING DEFAULT, DEFAULT; + +# Cleanup +DROP TABLE t1, t2; + +--echo # multi-update and IGNORE parameter (no default) +CREATE TABLE t1 (a INT, b INT NOT NULL); +INSERT INTO t1 VALUES (1,2),(2,3); +CREATE TABLE t2 (a INT, b INT NOT NULL); +INSERT INTO t2 VALUES (1,10),(2,30); + +EXECUTE IMMEDIATE 'UPDATE t1,t2 SET t1.b = ?, t2.b = ? WHERE t1.a=t2.a' USING IGNORE, IGNORE; +SELECT * FROM t1; +SELECT * FROM t2; + +# Cleanup +DROP TABLE t1, t2; + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result index bd0aac5edce..d5eb8a599e5 100644 --- a/mysql-test/main/table_value_constr.result +++ b/mysql-test/main/table_value_constr.result @@ -2594,9 +2594,9 @@ ERROR HY000: 'ignore' is not allowed in this context VALUES (DEFAULT); ERROR HY000: 'default' is not allowed in this context EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE; -ERROR HY000: 'ignore' is not allowed in this context +ERROR HY000: Default/ignore value is not supported for such parameter usage EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT; -ERROR HY000: 'default' is not allowed in this context +ERROR HY000: Default/ignore value is not supported for such parameter usage # # MDEV-24675: TVC using subqueries # diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test index 1d58cd0819d..21e066dec41 100644 --- a/mysql-test/main/table_value_constr.test +++ b/mysql-test/main/table_value_constr.test @@ -1349,9 +1349,9 @@ DELIMITER ;$$ VALUES (IGNORE); --error ER_UNKNOWN_ERROR VALUES (DEFAULT); ---error ER_UNKNOWN_ERROR +--error ER_INVALID_DEFAULT_PARAM EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE; ---error ER_UNKNOWN_ERROR +--error ER_INVALID_DEFAULT_PARAM EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT; --echo # diff --git a/sql/field.cc b/sql/field.cc index e37b4801f6b..185aed9cdb9 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1353,6 +1353,9 @@ bool Field::sp_prepare_and_store_item(THD *thd, Item **value) if (!(expr_item= thd->sp_prepare_func_item(value, 1))) goto error; + if (expr_item->check_is_evaluable_expression_or_error()) + goto error; + /* expr_item is now fixed, it's safe to call cmp_type() */ @@ -11424,6 +11427,30 @@ bool Field::validate_value_in_record_with_warn(THD *thd, const uchar *record) } +/** + Find which reaction should be for IGNORE value. +*/ + +ignore_value_reaction find_ignore_reaction(THD *thd) +{ + enum_sql_command com= thd->lex->sql_command; + + // All insert-like commands + if (com == SQLCOM_INSERT || com == SQLCOM_REPLACE || + com == SQLCOM_INSERT_SELECT || com == SQLCOM_REPLACE_SELECT || + com == SQLCOM_LOAD) + { + return IGNORE_MEANS_DEFAULT; + } + // Update commands + if (com == SQLCOM_UPDATE || com == SQLCOM_UPDATE_MULTI) + { + return IGNORE_MEANS_FIELD_VALUE; + } + return IGNORE_MEANS_ERROR; +} + + bool Field::save_in_field_default_value(bool view_error_processing) { THD *thd= table->in_use; diff --git a/sql/field.h b/sql/field.h index 8d23a05e720..2bf9407feb1 100644 --- a/sql/field.h +++ b/sql/field.h @@ -60,6 +60,15 @@ enum enum_check_fields CHECK_FIELD_ERROR_FOR_NULL, }; +enum ignore_value_reaction +{ + IGNORE_MEANS_ERROR, + IGNORE_MEANS_DEFAULT, + IGNORE_MEANS_FIELD_VALUE +}; + +ignore_value_reaction find_ignore_reaction(THD *thd); + /* Common declarations for Field and Item */ diff --git a/sql/item.cc b/sql/item.cc index 8a52a0ec7c5..383c9e4b68e 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3991,7 +3991,9 @@ Item_param::Item_param(THD *thd, const LEX_CSTRING *name_arg, as an actual parameter. See Item_param::set_from_item(). */ m_is_settable_routine_parameter(true), - m_clones(thd->mem_root) + m_clones(thd->mem_root), + m_associated_field(nullptr), + m_default_field(nullptr) { name= *name_arg; /* @@ -4398,10 +4400,29 @@ int Item_param::save_in_field(Field *field, bool no_conversions) case NULL_VALUE: return set_field_to_null_with_conversions(field, no_conversions); case DEFAULT_VALUE: + if (m_associated_field) + return assign_default(field); return field->save_in_field_default_value(field->table->pos_in_table_list-> top_table() != field->table->pos_in_table_list); case IGNORE_VALUE: + if (m_associated_field) + { + switch (find_ignore_reaction(field->table->in_use)) + { + case IGNORE_MEANS_DEFAULT: + DBUG_ASSERT(0); // impossible now, but fully working code if needed + return assign_default(field); + case IGNORE_MEANS_FIELD_VALUE: + m_associated_field->save_val(field); + return false; + default: + ; // fall through to error + } + DBUG_ASSERT(0); //impossible + my_error(ER_INVALID_DEFAULT_PARAM, MYF(0)); + return true; + } return field->save_in_field_ignore_value(field->table->pos_in_table_list-> top_table() != field->table->pos_in_table_list); @@ -5007,6 +5028,44 @@ static Field *make_default_field(THD *thd, Field *field_arg) } +/** + Assign a default value of a table column to the positional parameter that + is performed on execution of a prepared statement with the clause + 'USING DEFAULT' + + @param field a field that should be assigned an actual value of positional + parameter passed via the clause 'USING DEFAULT' + + @return false on success, true on failure +*/ + +bool Item_param::assign_default(Field *field) +{ + DBUG_ASSERT(m_associated_field); + + if (m_associated_field->field->flags & NO_DEFAULT_VALUE_FLAG) + { + my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), + m_associated_field->field->field_name.str); + return true; + } + + if (!m_default_field) + { + m_default_field= make_default_field(field->table->in_use, + m_associated_field->field); + + if (!m_default_field) + return true; + } + + if (m_default_field->default_value) + m_default_field->set_default(); + + return field_conv(field, m_default_field); +} + + /**************************************************************************** Item_copy_string ****************************************************************************/ @@ -9675,6 +9734,15 @@ Item *Item_default_value::transform(THD *thd, Item_transformer transformer, } +bool Item_default_value::associate_with_target_field(THD *thd, + Item_field *field) +{ + m_associated= true; + arg= field; + return tie_field(thd); +} + + /** Call fix_fields for an item representing the default value, create an instance of Field for representing the default value and assign it diff --git a/sql/item.h b/sql/item.h index db4de2c035e..9fc5cc4068f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -834,7 +834,7 @@ protected: const Tmp_field_param *param, bool is_explicit_null); - void raise_error_not_evaluable(); + virtual void raise_error_not_evaluable(); void push_note_converted_to_negative_complement(THD *thd); void push_note_converted_to_positive_complement(THD *thd); @@ -2453,6 +2453,18 @@ public: Checks if this item consists in the left part of arg IN subquery predicate */ bool pushable_equality_checker_for_subquery(uchar *arg); + + /** + This method is to set relationship between a positional parameter + represented by the '?' and an actual argument value passed to the + call of PS/SP by the USING clause. The method is overridden in classes + Item_param and Item_default_value. + */ + virtual bool associate_with_target_field(THD *, Item_field *) + { + DBUG_ASSERT(is_fixed()); + return false; + } }; MEM_ROOT *get_thd_memroot(THD *thd); @@ -4192,6 +4204,10 @@ public: void sync_clones(); bool register_clone(Item_param *i) { return m_clones.push_back(i); } + virtual void raise_error_not_evaluable() + { + invalid_default_param(); + } private: void invalid_default_param() const; @@ -4206,6 +4222,17 @@ public: virtual void make_send_field(THD *thd, Send_field *field); + /** + See comments on @see Item::associate_with_target_field for method + description + */ + virtual bool associate_with_target_field(THD *, Item_field *field) + { + m_associated_field= field; + return false; + } + bool assign_default(Field *field); + private: Send_field *m_out_param_info; bool m_is_settable_routine_parameter; @@ -4215,6 +4242,8 @@ private: synchronize the actual value of the parameter with the values of the clones. */ Mem_root_array m_clones; + Item_field *m_associated_field; + Field *m_default_field; }; @@ -6512,6 +6541,8 @@ public: class Item_default_value : public Item_field { bool vcol_assignment_ok; + bool m_associated; + void calculate(); public: Item *arg; @@ -6519,6 +6550,7 @@ public: bool vcol_assignment_arg) :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, &null_clex_str), vcol_assignment_ok(vcol_assignment_arg), + m_associated(false), arg(a) {} enum Type type() const { return DEFAULT_VALUE_ITEM; } bool eq(const Item *item, bool binary_cmp) const; @@ -6581,6 +6613,12 @@ public: Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, const Tmp_field_param *param); + /** + See comments on @see Item::associate_with_target_field for method + description + */ + virtual bool associate_with_target_field(THD *thd, Item_field *field); + private: bool tie_field(THD *thd); }; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 4e8598a8d65..e6a7110d45b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8870,6 +8870,9 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, @param values values to fill with @param ignore_errors TRUE if we should ignore errors @param use_value forces usage of value of the items instead of result + @param check_for_computability whether to check for ability to invoke val_*() + methods (val_int () etc) against supplied + values @details fill_record() may set table->auto_increment_field_not_null and a @@ -8883,7 +8886,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, bool fill_record(THD *thd, TABLE *table, Field **ptr, List &values, - bool ignore_errors, bool use_value) + bool ignore_errors, bool use_value, bool check_for_computability) { List_iterator_fast v(values); List tbl_list; @@ -8921,6 +8924,10 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List &values, else value=v++; + if (check_for_computability && + value->check_is_evaluable_expression_or_error()) + goto err; + bool vers_sys_field= table->versioned() && field->vers_sys_field(); if (field->field_index == autoinc_index) @@ -8995,7 +9002,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, Field **ptr, bool result; Table_triggers_list *triggers= table->triggers; - result= fill_record(thd, table, ptr, values, ignore_errors, FALSE); + result= fill_record(thd, table, ptr, values, ignore_errors, false, false); if (!result && triggers && *ptr) result= triggers->process_triggers(thd, event, TRG_ACTION_BEFORE, TRUE) || diff --git a/sql/sql_base.h b/sql/sql_base.h index 56c6c82907a..d6c6fd943ab 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -184,7 +184,8 @@ void unfix_fields(List &items); bool fill_record(THD * thd, TABLE *table_arg, List &fields, List &values, bool ignore_errors, bool update); bool fill_record(THD *thd, TABLE *table, Field **field, List &values, - bool ignore_errors, bool use_value); + bool ignore_errors, bool use_value, + bool check_for_evaluability); Field * find_field_in_tables(THD *thd, Item_ident *item, diff --git a/sql/sql_expression_cache.cc b/sql/sql_expression_cache.cc index bc44ecd79fa..75197bbfce6 100644 --- a/sql/sql_expression_cache.cc +++ b/sql/sql_expression_cache.cc @@ -271,7 +271,8 @@ my_bool Expression_cache_tmptable::put_value(Item *value) } *(items.head_ref())= value; - fill_record(table_thd, cache_table, cache_table->field, items, TRUE, TRUE); + fill_record(table_thd, cache_table, cache_table->field, items, true, true, + true); if (unlikely(table_thd->is_error())) goto err;; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a871faec99e..dfbc3b6a70e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12732,7 +12732,8 @@ end_sj_materialize(JOIN *join, JOIN_TAB *join_tab, bool end_of_records) if (item->is_null()) DBUG_RETURN(NESTED_LOOP_OK); } - fill_record(thd, table, table->field, sjm->sjm_table_cols, TRUE, FALSE); + fill_record(thd, table, table->field, sjm->sjm_table_cols, true, false, + true); if (unlikely(thd->is_error())) DBUG_RETURN(NESTED_LOOP_ERROR); /* purecov: inspected */ if (unlikely((error= table->file->ha_write_tmp_row(table->record[0])))) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index d93dea50972..3c854ec0eb9 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3066,7 +3066,7 @@ int select_result_explain_buffer::send_data(List &items) memory. */ set_current_thd(thd); - fill_record(thd, dst_table, dst_table->field, items, TRUE, FALSE); + fill_record(thd, dst_table, dst_table->field, items, true, false, false); res= dst_table->file->ha_write_tmp_row(dst_table->record[0]); set_current_thd(cur_thd); DBUG_RETURN(MY_TEST(res)); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index bc33f827084..c536c859b98 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -122,11 +122,11 @@ int select_unit::send_data(List &values) table->null_catch_flags= CHECK_ROW_FOR_NULLS_TO_REJECT; if (intersect_mark) { - fill_record(thd, table, table->field + 1, values, TRUE, FALSE); + fill_record(thd, table, table->field + 1, values, true, false, true); table->field[0]->store((ulonglong) curr_step, 1); } else - fill_record(thd, table, table->field, values, TRUE, FALSE); + fill_record(thd, table, table->field, values, true, false, true); if (unlikely(thd->is_error())) { rc= 1; @@ -562,7 +562,7 @@ int select_union_direct::send_data(List &items) send_records++; } - fill_record(thd, table, table->field, items, true, false); + fill_record(thd, table, table->field, items, true, false, true); if (unlikely(thd->is_error())) return true; /* purecov: inspected */ diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 233ad49576e..a1789445ef0 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -2160,6 +2160,10 @@ int multi_update::prepare(List ¬_used_values, { Item *value= value_it++; uint offset= item->field->table->pos_in_table_list->shared; + + if (value->associate_with_target_field(thd, item)) + DBUG_RETURN(1); + fields_for_table[offset]->push_back(item, thd->mem_root); values_for_table[offset]->push_back(value, thd->mem_root); } @@ -2658,7 +2662,7 @@ int multi_update::send_data(List ¬_used_values) tmp_table_param[offset].func_count); fill_record(thd, tmp_table, tmp_table->field + 1 + unupdated_check_opt_tables.elements, - *values_for_table[offset], TRUE, FALSE); + *values_for_table[offset], true, false, false); /* Write row, ignoring duplicated updates to a row */ error= tmp_table->file->ha_write_tmp_row(tmp_table->record[0]); diff --git a/sql/unireg.cc b/sql/unireg.cc index f2d57e7549f..9b0f29963c7 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -649,7 +649,15 @@ static bool pack_vcols(THD *thd, String *buf, List &create_fields, ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL)) return 1; if (field->has_default_expression() && !field->has_default_now_unireg_check()) - if (pack_expression(buf, field->default_value, field_nr, VCOL_DEFAULT)) + if (pack_expression(buf, field->default_value, field_nr, VCOL_DEFAULT) || + /* + field->has_default_expression() can return error (e.g. because + the method Item_param::basic_const_item invokes + invalid_default_param() + in case either DEFAULT_VALUE or IGNORE_VALUE is handled). + Take this fact into account and return error in this case. + */ + thd->is_error()) return 1; if (field->check_constraint) if (pack_expression(buf, field->check_constraint, field_nr, From d816a5ca32d8b2673bc6e4483b53df73827b067e Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 8 Feb 2024 14:19:47 +0100 Subject: [PATCH 20/21] fix test --- mysql-test/suite/engines/funcs/r/tc_partition_analyze.result | 1 - storage/rocksdb/mysql-test/rocksdb/r/partition.result | 1 - .../mysql-test/tokudb_bugs/r/db757_part_alter_analyze.result | 4 ---- .../mysql-test/tokudb_parts/r/partition_mgm_lc0_tokudb.result | 1 - .../tokudb_parts/r/partition_mgm_lc10_tokudb.result | 1 - .../mysql-test/tokudb_parts/r/partition_mgm_lc1_tokudb.result | 1 - 6 files changed, 9 deletions(-) diff --git a/mysql-test/suite/engines/funcs/r/tc_partition_analyze.result b/mysql-test/suite/engines/funcs/r/tc_partition_analyze.result index cd4a0294ba5..ae3305b3fc2 100644 --- a/mysql-test/suite/engines/funcs/r/tc_partition_analyze.result +++ b/mysql-test/suite/engines/funcs/r/tc_partition_analyze.result @@ -33,7 +33,6 @@ t1 CREATE TABLE `t1` ( PARTITION `p5` VALUES LESS THAN MAXVALUE ENGINE = ENGINE) ALTER TABLE t1 ANALYZE PARTITION p1,p2; Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK SELECT * FROM t1 ORDER BY c1; c1 c2 diff --git a/storage/rocksdb/mysql-test/rocksdb/r/partition.result b/storage/rocksdb/mysql-test/rocksdb/r/partition.result index a7f2a6112c1..1ba966e9e07 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/partition.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/partition.result @@ -46,7 +46,6 @@ CREATE TABLE t1 (i INT, j INT, k INT, PRIMARY KEY (i)) ENGINE = ROCKSDB PARTITIO Table Op Msg_type Msg_text test.t1 optimize status OK Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK Table Op Msg_type Msg_text test.t1 repair status OK diff --git a/storage/tokudb/mysql-test/tokudb_bugs/r/db757_part_alter_analyze.result b/storage/tokudb/mysql-test/tokudb_bugs/r/db757_part_alter_analyze.result index c9b32d51471..2c2f7455be9 100644 --- a/storage/tokudb/mysql-test/tokudb_bugs/r/db757_part_alter_analyze.result +++ b/storage/tokudb/mysql-test/tokudb_bugs/r/db757_part_alter_analyze.result @@ -13,7 +13,6 @@ t 1 x 1 x A 5 NULL NULL YES BTREE t 1 y 1 y A 5 NULL NULL YES BTREE alter table t analyze partition p0; Table Op Msg_type Msg_text -test.t analyze status Engine-independent statistics collected test.t analyze status OK show indexes from t; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment @@ -22,7 +21,6 @@ t 1 x 1 x A 5 NULL NULL YES BTREE t 1 y 1 y A 5 NULL NULL YES BTREE alter table t analyze partition p1; Table Op Msg_type Msg_text -test.t analyze status Engine-independent statistics collected test.t analyze status OK show indexes from t; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment @@ -37,7 +35,6 @@ t 1 x 1 x A 9 NULL NULL YES BTREE t 1 y 1 y A 9 NULL NULL YES BTREE alter table t analyze partition p0; Table Op Msg_type Msg_text -test.t analyze status Engine-independent statistics collected test.t analyze status OK show indexes from t; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment @@ -46,7 +43,6 @@ t 1 x 1 x A 9 NULL NULL YES BTREE t 1 y 1 y A 9 NULL NULL YES BTREE alter table t analyze partition p1; Table Op Msg_type Msg_text -test.t analyze status Engine-independent statistics collected test.t analyze status OK show indexes from t; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment diff --git a/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc0_tokudb.result b/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc0_tokudb.result index 5624c77a235..bd0c38687f5 100644 --- a/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc0_tokudb.result +++ b/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc0_tokudb.result @@ -1020,7 +1020,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -MySQL_Test_DB.t1 analyze status Engine-independent statistics collected MySQL_Test_DB.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc10_tokudb.result b/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc10_tokudb.result index 3717ee0b232..246cb2f0f07 100644 --- a/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc10_tokudb.result +++ b/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc10_tokudb.result @@ -949,7 +949,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -MySQL_Test_DB.t1 analyze status Engine-independent statistics collected MySQL_Test_DB.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; diff --git a/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc1_tokudb.result b/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc1_tokudb.result index 2928baedbd4..0985889b7e7 100644 --- a/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc1_tokudb.result +++ b/storage/tokudb/mysql-test/tokudb_parts/r/partition_mgm_lc1_tokudb.result @@ -987,7 +987,6 @@ a b 2001 Second in MAX ALTER TABLE t1 ANALYZE PARTITION MAX; Table Op Msg_type Msg_text -mysql_test_db.t1 analyze status Engine-independent statistics collected mysql_test_db.t1 analyze status OK # Truncate without FLUSH ALTER TABLE t1 TRUNCATE PARTITION MAX; From 36f51d9748fba2e36c34864c2a228ee8e92d9665 Mon Sep 17 00:00:00 2001 From: Rex Date: Fri, 17 Feb 2023 08:28:38 +1200 Subject: [PATCH 21/21] MDEV-29179 Condition pushdown from HAVING into WHERE is not shown in optimizer trace JOIN::optimize_inner(), Condition pushdown from HAVING into WHERE not shown in optimizer trace. --- mysql-test/main/opt_trace.result | 19 +++++++++++++++++++ mysql-test/main/opt_trace.test | 11 +++++++++++ sql/sql_select.cc | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 3b7961c2349..8530c31e5c9 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -9041,5 +9041,24 @@ JS drop table t1,t2,t3,t10,t11; set optimizer_trace=DEFAULT; # +# MDEV-29179 Condition pushdown from HAVING into WHERE is not shown in optimizer trace +# +CREATE TABLE t1 (a INT, b VARCHAR(1), KEY (a), KEY(b,a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES (4,'n'),(1,'h'),(NULL,'w'); +SET optimizer_trace= 'enabled=on'; +SELECT b, a FROM t1 WHERE b <> 'p' OR a = 4 GROUP BY b, a HAVING a <= 7; +b a +h 1 +n 4 +SELECT json_detailed(json_extract(trace, '$**.steps[*].join_optimization.steps[*].condition_pushdown_from_having') ), JSON_VALID(trace) FROM information_schema.optimizer_trace; +json_detailed(json_extract(trace, '$**.steps[*].join_optimization.steps[*].condition_pushdown_from_having') ) JSON_VALID(trace) +[ + { + "conds": "(t1.b <> 'p' or multiple equal(4, t1.a)) and t1.a <= 7", + "having": null + } +] 1 +DROP TABLE t1; +# # End of 10.4 tests # diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test index 5ae00c8236f..94b6d855279 100644 --- a/mysql-test/main/opt_trace.test +++ b/mysql-test/main/opt_trace.test @@ -790,6 +790,17 @@ from information_schema.optimizer_trace; drop table t1,t2,t3,t10,t11; set optimizer_trace=DEFAULT; +--echo # +--echo # MDEV-29179 Condition pushdown from HAVING into WHERE is not shown in optimizer trace +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(1), KEY (a), KEY(b,a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES (4,'n'),(1,'h'),(NULL,'w'); +SET optimizer_trace= 'enabled=on'; +SELECT b, a FROM t1 WHERE b <> 'p' OR a = 4 GROUP BY b, a HAVING a <= 7; +SELECT json_detailed(json_extract(trace, '$**.steps[*].join_optimization.steps[*].condition_pushdown_from_having') ), JSON_VALID(trace) FROM information_schema.optimizer_trace; +DROP TABLE t1; + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/sql_select.cc b/sql/sql_select.cc index dfbc3b6a70e..978bd4ebe26 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2164,6 +2164,10 @@ JOIN::optimize_inner() select_lex->attach_to_conds, &cond_value); sel->attach_to_conds.empty(); + Json_writer_object wrapper(thd); + Json_writer_object pushd(thd, "condition_pushdown_from_having"); + pushd.add("conds", conds); + pushd.add("having", having); } }