From 5b0a76078a8ea38e8e19e3e2c49f0f7e091e2f72 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Thu, 16 Sep 2021 16:52:20 +0600 Subject: [PATCH 1/4] MDEV-26621 assertion failue "index->table->persistent_autoinc" in /storage/innobase/btr/btr0btr.cc during IMPORT dict_index_t::clear_instant_alter(): when searhing for an AUTO_INCREMENT column don't skip the beginning of the list because the field can be at the beginning of the list --- .../innodb/r/instant_alter_import.result | 8 ++++++++ .../suite/innodb/t/instant_alter_import.test | 19 +++++++++++++++++++ storage/innobase/include/dict0mem.h | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/instant_alter_import.result b/mysql-test/suite/innodb/r/instant_alter_import.result index 2d9a39f788611..008a26ea6afae 100644 --- a/mysql-test/suite/innodb/r/instant_alter_import.result +++ b/mysql-test/suite/innodb/r/instant_alter_import.result @@ -70,3 +70,11 @@ select * from t1; ERROR HY000: Tablespace has been discarded for table `t1` drop table t2; drop table t1; +CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT) ENGINE=INNODB; +CREATE TABLE t2 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT, i2 INT) ENGINE=INNODB; +ALTER TABLE t2 DROP COLUMN i2, ALGORITHM=INSTANT; +ALTER TABLE t2 DISCARD TABLESPACE; +FLUSH TABLE t1 FOR EXPORT; +UNLOCK TABLES; +ALTER TABLE t2 IMPORT TABLESPACE; +DROP TABLE t2, t1; diff --git a/mysql-test/suite/innodb/t/instant_alter_import.test b/mysql-test/suite/innodb/t/instant_alter_import.test index fb187debb51af..d01f4325f1e4b 100644 --- a/mysql-test/suite/innodb/t/instant_alter_import.test +++ b/mysql-test/suite/innodb/t/instant_alter_import.test @@ -82,3 +82,22 @@ select * from t1; drop table t2; drop table t1; + + +--let $MYSQLD_DATADIR= `SELECT @@datadir` + +CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT) ENGINE=INNODB; + +CREATE TABLE t2 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT, i2 INT) ENGINE=INNODB; +ALTER TABLE t2 DROP COLUMN i2, ALGORITHM=INSTANT; +ALTER TABLE t2 DISCARD TABLESPACE; + +FLUSH TABLE t1 FOR EXPORT; + +--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd +--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg + +UNLOCK TABLES; +ALTER TABLE t2 IMPORT TABLESPACE; + +DROP TABLE t2, t1; diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index b0da5b4dc399e..fe029fc9fcf2c 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -2440,7 +2440,7 @@ inline void dict_index_t::clear_instant_alter() { return a.col->ind < b.col->ind; }); table->instant = NULL; if (ai_col) { - auto a = std::find_if(begin, end, + auto a = std::find_if(fields, end, [ai_col](const dict_field_t& f) { return f.col == ai_col; }); table->persistent_autoinc = (a == end) ? 0 : 1 + (a - fields); From d3b35598fcf8c83c8e2c1a004d507c95a42eb174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 16 Sep 2021 12:14:39 +0300 Subject: [PATCH 2/4] MDEV-26053 : TRUNCATE on table with Foreign Key Constraint no longer replicated to other nodes Problem was that there was extra condition !thd->lex->no_write_to_binlog before call to begin TOI. It seems that this variable is not initialized. TRUNCATE does not support [NO_WRITE_TO_BINLOG | LOCAL] keywords, thus we should not check this condition. All this was hidden in a macro, so I decided to remove those macros that were used only a few places with actual function calls. --- include/wsrep.h | 7 --- .../suite/galera/r/galera_fk_truncate.result | 47 +++++++++++++++++++ .../suite/galera/t/galera_fk_truncate.test | 39 +++++++++++++++ sql/sql_admin.cc | 15 +++--- sql/sql_truncate.cc | 12 ++--- sql/wsrep_mysqld.cc | 5 +- 6 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_fk_truncate.result create mode 100644 mysql-test/suite/galera/t/galera_fk_truncate.test diff --git a/include/wsrep.h b/include/wsrep.h index 5272b6877323f..2a9036956cc68 100644 --- a/include/wsrep.h +++ b/include/wsrep.h @@ -23,8 +23,6 @@ #define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A) #define WSREP_MYSQL_DB (char *)"mysql" -#define WSREP_TO_ISOLATION_BEGIN_IF(db_, table_, table_list_) \ - if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) #define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \ if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \ @@ -48,10 +46,6 @@ if (WSREP(thd) && !thd->lex->no_write_to_binlog \ && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto wsrep_error_label; -#define WSREP_TO_ISOLATION_BEGIN_FK_TABLES(db_, table_, table_list_, fk_tables) \ - if (WSREP(thd) && !thd->lex->no_write_to_binlog \ - && wsrep_to_isolation_begin(thd, db_, table_, table_list_, NULL, fk_tables)) - #define WSREP_DEBUG(...) \ if (wsrep_debug) WSREP_LOG(sql_print_information, ##__VA_ARGS__) #define WSREP_INFO(...) WSREP_LOG(sql_print_information, ##__VA_ARGS__) @@ -75,7 +69,6 @@ #define WSREP_ERROR(...) #define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0) #define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_) -#define WSREP_TO_ISOLATION_BEGIN_FK_TABLES(db_, table_, table_list_, fk_tables_) #define WSREP_TO_ISOLATION_END #define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) #define WSREP_SYNC_WAIT(thd_, before_) diff --git a/mysql-test/suite/galera/r/galera_fk_truncate.result b/mysql-test/suite/galera/r/galera_fk_truncate.result new file mode 100644 index 0000000000000..a90f3e27ab707 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_fk_truncate.result @@ -0,0 +1,47 @@ +connection node_2; +connection node_1; +CREATE TABLE author ( +id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, +name VARCHAR(100) NOT NULL +) ENGINE = InnoDB; +CREATE TABLE book ( +id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, +title VARCHAR(200) NOT NULL, +author_id SMALLINT UNSIGNED NOT NULL, +CONSTRAINT `fk_book_author` + FOREIGN KEY (author_id) REFERENCES author (id) +ON DELETE CASCADE +ON UPDATE RESTRICT +) ENGINE = InnoDB; +INSERT INTO author (name) VALUES ('Abdul Alhazred'); +INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID()); +TRUNCATE TABLE book; +SELECT * FROM author; +id name +1 Abdul Alhazred +SELECT * FROM book; +id title author_id +connection node_2; +SELECT * FROM author; +id name +1 Abdul Alhazred +SELECT * FROM book; +id title author_id +INSERT INTO author (name) VALUES ('Abdul Alhazred'); +INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID()); +TRUNCATE TABLE book; +SELECT * FROM author; +id name +1 Abdul Alhazred +2 Abdul Alhazred +SELECT * FROM book; +id title author_id +connection node_1; +TRUNCATE TABLE book; +SELECT * FROM author; +id name +1 Abdul Alhazred +2 Abdul Alhazred +SELECT * FROM book; +id title author_id +DROP TABLE book, author; diff --git a/mysql-test/suite/galera/t/galera_fk_truncate.test b/mysql-test/suite/galera/t/galera_fk_truncate.test new file mode 100644 index 0000000000000..9d54a7204325c --- /dev/null +++ b/mysql-test/suite/galera/t/galera_fk_truncate.test @@ -0,0 +1,39 @@ +--source include/galera_cluster.inc + +CREATE TABLE author ( + id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE book ( + id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(200) NOT NULL, + author_id SMALLINT UNSIGNED NOT NULL, + CONSTRAINT `fk_book_author` + FOREIGN KEY (author_id) REFERENCES author (id) + ON DELETE CASCADE + ON UPDATE RESTRICT +) ENGINE = InnoDB; + +INSERT INTO author (name) VALUES ('Abdul Alhazred'); +INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID()); + +TRUNCATE TABLE book; +SELECT * FROM author; +SELECT * FROM book; + +--connection node_2 +SELECT * FROM author; +SELECT * FROM book; +INSERT INTO author (name) VALUES ('Abdul Alhazred'); +INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID()); +TRUNCATE TABLE book; +SELECT * FROM author; +SELECT * FROM book; + +--connection node_1 +TRUNCATE TABLE book; +SELECT * FROM author; +SELECT * FROM book; + +DROP TABLE book, author; diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index b626200d29793..f692afb144043 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -466,16 +466,17 @@ static bool wsrep_toi_replication(THD *thd, TABLE_LIST *tables) /* now TOI replication, with no locks held */ if (keys.empty()) { - WSREP_TO_ISOLATION_BEGIN_WRTCHK(NULL, NULL, tables); - } else { - WSREP_TO_ISOLATION_BEGIN_FK_TABLES(NULL, NULL, tables, &keys) { + if (!thd->lex->no_write_to_binlog && + wsrep_to_isolation_begin(thd, NULL, NULL, tables)) + return true; + } + else + { + if (!thd->lex->no_write_to_binlog && + wsrep_to_isolation_begin(thd, NULL, NULL, tables, NULL, &keys)) return true; - } } return false; - - wsrep_error_label: - return true; } #endif /* WITH_WSREP */ diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index aca43021798b5..62f6f8a3f901e 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -424,15 +424,13 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) { if (keys.empty()) { - WSREP_TO_ISOLATION_BEGIN_IF(table_ref->db.str, table_ref->table_name.str, NULL) - { + if (wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, NULL)) DBUG_RETURN(TRUE); - } - } else { - WSREP_TO_ISOLATION_BEGIN_FK_TABLES(NULL, NULL, table_ref, &keys) - { + } + else + { + if (wsrep_to_isolation_begin(thd, NULL, NULL, table_ref, NULL, &keys)) DBUG_RETURN(TRUE); - } } } } diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index bf1e4e32b49ce..55564dbe23562 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2164,8 +2164,9 @@ int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, { /* No isolation for applier or replaying threads. - */ - if (!wsrep_thd_is_local(thd)) return 0; + */ + if (!wsrep_thd_is_local(thd)) + return 0; int ret= 0; mysql_mutex_lock(&thd->LOCK_thd_data); From a2e55131c64bee63b980e78cec92cf9c4bf1b7ec Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 16 Sep 2021 16:26:59 +0200 Subject: [PATCH 3/4] MDEV-19950 addendum: galera_ssl_upgrade removed from the list of disabled tests and adapted for 10.4+ --- mysql-test/suite/galera/disabled.def | 1 - mysql-test/suite/galera/r/galera_ssl_upgrade.result | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 590a86232235b..d742879bb10cb 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -31,7 +31,6 @@ galera_parallel_simple : MDEV-20318 galera.galera_parallel_simple fails galera_pc_ignore_sb : MDEV-20888 galera.galera_pc_ignore_sb galera_pc_recovery : MDEV-25199 cluster fails to start up galera_shutdown_nonprim : MDEV-21493 galera.galera_shutdown_nonprim -galera_ssl_upgrade : MDEV-19950 Galera test failure on galera_ssl_upgrade galera_toi_ddl_nonconflicting : MDEV-21518 galera.galera_toi_ddl_nonconflicting galera_toi_truncate : MDEV-22996 Hang on galera_toi_truncate test case galera_var_ignore_apply_errors : MDEV-20451: Lock wait timeout exceeded in galera_var_ignore_apply_errors diff --git a/mysql-test/suite/galera/r/galera_ssl_upgrade.result b/mysql-test/suite/galera/r/galera_ssl_upgrade.result index 1443e34d04195..134d1d1b60591 100644 --- a/mysql-test/suite/galera/r/galera_ssl_upgrade.result +++ b/mysql-test/suite/galera/r/galera_ssl_upgrade.result @@ -1,3 +1,5 @@ +connection node_2; +connection node_1; connection node_1; call mtr.add_suppression("WSREP: write_handler(): protocol is shutdown.*"); connection node_2; @@ -24,5 +26,6 @@ connection node_1; SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; VARIABLE_VALUE = 2 1 +connection node_2; disconnect node_2; disconnect node_1; From 03a10706ecfa5cf0a6252d436e341483f5c0827c Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 17 Sep 2021 16:07:00 +0300 Subject: [PATCH 4/4] Fixed alias.test to also works with ps The issue is that max_length for prepared statements are different from normal queries, which can optimize the max_length based on the result length. --- mysql-test/main/alias.result | 12 ++++++------ mysql-test/main/alias.test | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/alias.result b/mysql-test/main/alias.result index d8bb211539ff8..0d14607f613fe 100644 --- a/mysql-test/main/alias.result +++ b/mysql-test/main/alias.result @@ -223,16 +223,16 @@ disconnect c1; # create or replace table t1 (a int); create or replace table t2 (b int); -insert into t1 values(1),(2); +insert into t1 values(1<<30),(1<<29); insert into t2 values(1),(2); select t1.a as a1 from t1 as t1,t2 order by t2.b,t1.a; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def test t1 t1 a a1 3 11 1 Y 32768 0 63 +def test t1 t1 a a1 3 11 10 Y 32768 0 63 a1 -1 -2 -1 -2 +536870912 +1073741824 +536870912 +1073741824 drop table t1,t2; # # End of 10.4 tests diff --git a/mysql-test/main/alias.test b/mysql-test/main/alias.test index f0c4e13abfd46..2408509ba10b3 100644 --- a/mysql-test/main/alias.test +++ b/mysql-test/main/alias.test @@ -231,7 +231,7 @@ disconnect c1; --echo # create or replace table t1 (a int); create or replace table t2 (b int); -insert into t1 values(1),(2); +insert into t1 values(1<<30),(1<<29); insert into t2 values(1),(2); --enable_metadata select t1.a as a1 from t1 as t1,t2 order by t2.b,t1.a;