From 85192553ae2c3cb5fb26ace4cd85377525ac7845 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Fri, 11 Mar 2022 21:18:34 +0700 Subject: [PATCH 01/37] MDEV-24560 SIGSEGV in st_join_table::cleanup If JOIN::create_postjoin_aggr_table encounters errors during execution then free_tmp_table() is then called twice for JOIN_TAB::aggr. The solution is to initialize JOIN_TAB::aggr only on successful completion of JOIN::create_postjoin_aggr_table --- mysql-test/r/select.result | 27 +++++++++++++++++++++++++++ mysql-test/r/select_jcl6.result | 27 +++++++++++++++++++++++++++ mysql-test/r/select_pkeycache.result | 27 +++++++++++++++++++++++++++ mysql-test/t/select.test | 28 ++++++++++++++++++++++++++++ sql/sql_select.cc | 14 +++++++------- 5 files changed, 116 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index f4a6d17dc9c..2fef3361617 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -5548,4 +5548,31 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)) NULL drop table t1; +# +# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon +# erroneous GROUP_CONCAT +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,10),(2,20); +SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f; +ERROR 42S22: Unknown column '2' in 'order clause' +DROP TABLE t1; +# +# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client +# hang + cross-mysqld-interaction + double free or corruption (!prev) +# +CREATE TABLE t1 (c INT); +SET SESSION sql_buffer_result=1; +SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1; +GROUP_CONCAT(c ORDER BY 2) +NULL +SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1; +GROUP_CONCAT(c ORDER BY 0) +NULL +DROP TABLE t1; +CREATE TABLE t1 (grp INT,c CHAR); +SET sql_buffer_result=1; +SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; +grp GROUP_CONCAT(c ORDER BY 2) +DROP TABLE t1; End of 10.0 tests diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index 63c0968dc73..9e35af9cb78 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -5559,6 +5559,33 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)) NULL drop table t1; +# +# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon +# erroneous GROUP_CONCAT +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,10),(2,20); +SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f; +ERROR 42S22: Unknown column '2' in 'order clause' +DROP TABLE t1; +# +# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client +# hang + cross-mysqld-interaction + double free or corruption (!prev) +# +CREATE TABLE t1 (c INT); +SET SESSION sql_buffer_result=1; +SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1; +GROUP_CONCAT(c ORDER BY 2) +NULL +SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1; +GROUP_CONCAT(c ORDER BY 0) +NULL +DROP TABLE t1; +CREATE TABLE t1 (grp INT,c CHAR); +SET sql_buffer_result=1; +SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; +grp GROUP_CONCAT(c ORDER BY 2) +DROP TABLE t1; End of 10.0 tests set join_cache_level=default; set @@optimizer_switch=@save_optimizer_switch_jcl6; diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index f4a6d17dc9c..2fef3361617 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -5548,4 +5548,31 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)) NULL drop table t1; +# +# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon +# erroneous GROUP_CONCAT +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,10),(2,20); +SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f; +ERROR 42S22: Unknown column '2' in 'order clause' +DROP TABLE t1; +# +# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client +# hang + cross-mysqld-interaction + double free or corruption (!prev) +# +CREATE TABLE t1 (c INT); +SET SESSION sql_buffer_result=1; +SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1; +GROUP_CONCAT(c ORDER BY 2) +NULL +SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1; +GROUP_CONCAT(c ORDER BY 0) +NULL +DROP TABLE t1; +CREATE TABLE t1 (grp INT,c CHAR); +SET sql_buffer_result=1; +SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; +grp GROUP_CONCAT(c ORDER BY 2) +DROP TABLE t1; End of 10.0 tests diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 2567d189465..ea213be9fea 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -4670,4 +4670,32 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); drop table t1; +--echo # +--echo # Bug MDEV-24262 Server crashes in st_join_table::cleanup upon +--echo # erroneous GROUP_CONCAT +--echo # + +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,10),(2,20); +--error ER_BAD_FIELD_ERROR +SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f; + +DROP TABLE t1; + +--echo # +--echo # Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client +--echo # hang + cross-mysqld-interaction + double free or corruption (!prev) +--echo # + +CREATE TABLE t1 (c INT); +SET SESSION sql_buffer_result=1; +SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1; +SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (grp INT,c CHAR); +SET sql_buffer_result=1; +SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; +DROP TABLE t1; + --echo End of 10.0 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 22d3597de16..8d2a4929401 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2989,14 +2989,11 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List *table_fields, tmp_table_param.using_outer_summary_function= tab->tmp_table_param->using_outer_summary_function; tab->join= this; - DBUG_ASSERT(tab > tab->join->join_tab || !top_join_tab_count || !tables_list); + DBUG_ASSERT(tab > tab->join->join_tab || !top_join_tab_count || + !tables_list); + tab->table= table; if (tab > join_tab) (tab - 1)->next_select= sub_select_postjoin_aggr; - tab->aggr= new (thd->mem_root) AGGR_OP(tab); - if (!tab->aggr) - goto err; - tab->table= table; - table->reginfo.join_tab= tab; /* if group or order on first table, sort first */ if ((group_list && simple_group) || @@ -3047,12 +3044,15 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List *table_fields, order= NULL; } } - + if (!(tab->aggr= new (thd->mem_root) AGGR_OP(tab))) + goto err; + table->reginfo.join_tab= tab; DBUG_RETURN(false); err: if (table != NULL) free_tmp_table(thd, table); + tab->table= NULL; DBUG_RETURN(true); } From 53b580a91c12e9272623fc45496631be65313dd8 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Thu, 24 Mar 2022 14:57:23 +0700 Subject: [PATCH 02/37] MDEV-28077 'Wrong create options' error with 'big_tables' enabled The cause of the bug is overflow of uint16 KEY_PART_INFO::length and/or uint16 KEY_PART_INFO::store_length. The solution is to increase the size of those variables to the 'uint' type (which is 32-bit long) --- mysql-test/r/select.result | 19 +++++++++++++++++++ mysql-test/r/select_jcl6.result | 19 +++++++++++++++++++ mysql-test/r/select_pkeycache.result | 19 +++++++++++++++++++ mysql-test/t/select.test | 18 ++++++++++++++++++ sql/sql_select.cc | 1 + sql/structs.h | 4 ++-- 6 files changed, 78 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 2fef3361617..3b8af811a4b 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -5575,4 +5575,23 @@ SET sql_buffer_result=1; SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; grp GROUP_CONCAT(c ORDER BY 2) DROP TABLE t1; +# +# Bug MDEV-28077 "Wrong create options" with "big_tables" option enabled +# +CREATE TABLE t1(a VARCHAR(16383) CHARACTER SET UTF32, KEY k(a)); +Warnings: +Note 1071 Specified key was too long; max key length is 1000 bytes +INSERT INTO t1 VALUES ('abc'), ('def'), ('FFF'), ('abc'), ('FFF'); +SET SESSION big_tables=ON; +SELECT DISTINCT COUNT(DISTINCT a) FROM t1; +COUNT(DISTINCT a) +3 +PREPARE stmt FROM 'SELECT DISTINCT COUNT(DISTINCT a) FROM t1'; +EXECUTE stmt; +COUNT(DISTINCT a) +3 +EXECUTE stmt; +COUNT(DISTINCT a) +3 +DROP TABLE t1; End of 10.0 tests diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index 9e35af9cb78..a50df7d6081 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -5586,6 +5586,25 @@ SET sql_buffer_result=1; SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; grp GROUP_CONCAT(c ORDER BY 2) DROP TABLE t1; +# +# Bug MDEV-28077 "Wrong create options" with "big_tables" option enabled +# +CREATE TABLE t1(a VARCHAR(16383) CHARACTER SET UTF32, KEY k(a)); +Warnings: +Note 1071 Specified key was too long; max key length is 1000 bytes +INSERT INTO t1 VALUES ('abc'), ('def'), ('FFF'), ('abc'), ('FFF'); +SET SESSION big_tables=ON; +SELECT DISTINCT COUNT(DISTINCT a) FROM t1; +COUNT(DISTINCT a) +3 +PREPARE stmt FROM 'SELECT DISTINCT COUNT(DISTINCT a) FROM t1'; +EXECUTE stmt; +COUNT(DISTINCT a) +3 +EXECUTE stmt; +COUNT(DISTINCT a) +3 +DROP TABLE t1; End of 10.0 tests set join_cache_level=default; set @@optimizer_switch=@save_optimizer_switch_jcl6; diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index 2fef3361617..3b8af811a4b 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -5575,4 +5575,23 @@ SET sql_buffer_result=1; SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; grp GROUP_CONCAT(c ORDER BY 2) DROP TABLE t1; +# +# Bug MDEV-28077 "Wrong create options" with "big_tables" option enabled +# +CREATE TABLE t1(a VARCHAR(16383) CHARACTER SET UTF32, KEY k(a)); +Warnings: +Note 1071 Specified key was too long; max key length is 1000 bytes +INSERT INTO t1 VALUES ('abc'), ('def'), ('FFF'), ('abc'), ('FFF'); +SET SESSION big_tables=ON; +SELECT DISTINCT COUNT(DISTINCT a) FROM t1; +COUNT(DISTINCT a) +3 +PREPARE stmt FROM 'SELECT DISTINCT COUNT(DISTINCT a) FROM t1'; +EXECUTE stmt; +COUNT(DISTINCT a) +3 +EXECUTE stmt; +COUNT(DISTINCT a) +3 +DROP TABLE t1; End of 10.0 tests diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index ea213be9fea..0878cbf8306 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -4698,4 +4698,22 @@ SET sql_buffer_result=1; SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp; DROP TABLE t1; +--echo # +--echo # Bug MDEV-28077 "Wrong create options" with "big_tables" option enabled +--echo # +CREATE TABLE t1(a VARCHAR(16383) CHARACTER SET UTF32, KEY k(a)); +INSERT INTO t1 VALUES ('abc'), ('def'), ('FFF'), ('abc'), ('FFF'); + +# big_tables are deprecated after some version +--disable_warnings +SET SESSION big_tables=ON; +SELECT DISTINCT COUNT(DISTINCT a) FROM t1; + +PREPARE stmt FROM 'SELECT DISTINCT COUNT(DISTINCT a) FROM t1'; +EXECUTE stmt; +EXECUTE stmt; + +--enable_warnings +DROP TABLE t1; + --echo End of 10.0 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8d2a4929401..2a646a9931d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12419,6 +12419,7 @@ void JOIN::cleanup(bool full) if (curr_tab->aggr) { free_tmp_table(thd, curr_tab->table); + curr_tab->table= NULL; delete curr_tab->tmp_table_param; curr_tab->tmp_table_param= NULL; curr_tab->aggr= NULL; diff --git a/sql/structs.h b/sql/structs.h index 27b9725815b..106f2900683 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -71,14 +71,14 @@ typedef struct st_key_part_info { /* Info about a key part */ uint offset; /* Offset in record (from 0) */ uint null_offset; /* Offset to null_bit in record */ /* Length of key part in bytes, excluding NULL flag and length bytes */ - uint16 length; + uint length; /* Number of bytes required to store the keypart value. This may be different from the "length" field as it also counts - possible NULL-flag byte (see HA_KEY_NULL_LENGTH) - possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length. */ - uint16 store_length; + uint store_length; uint16 key_type; uint16 fieldnr; /* Fieldnr begins counting from 1 */ uint16 key_part_flag; /* 0 or HA_REVERSE_SORT */ From 7a03128faf8bbbc36021fbf418a31b1a604e29e2 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Tue, 5 Apr 2022 14:02:52 +0200 Subject: [PATCH 03/37] MDEV-28205: SST via mariabackup stops on failure while archiving logs Currenly SST script for mariabackup stops on any failure while archiving logs, e.g. when unable to create directory, insufficient permissions, gzip failure, etc. However, in case of such problems, the script should issue a warning and continue without archiving, but not exit with a fatal error. This commit adds this fix to the SST script for mariabackup. --- ...era_sst_mariabackup_logarchive,debug.rdiff | 116 +++++++ .../galera_sst_mariabackup_logarchive.result | 292 ++++++++++++++++++ .../t/galera_sst_mariabackup_logarchive.cnf | 17 + .../t/galera_sst_mariabackup_logarchive.test | 63 ++++ scripts/wsrep_sst_mariabackup.sh | 31 +- 5 files changed, 511 insertions(+), 8 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive,debug.rdiff create mode 100644 mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive.result create mode 100644 mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.cnf create mode 100644 mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.test diff --git a/mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive,debug.rdiff b/mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive,debug.rdiff new file mode 100644 index 00000000000..5b7d7b4139a --- /dev/null +++ b/mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive,debug.rdiff @@ -0,0 +1,116 @@ +--- r/galera_sst_mariabackup_logarachive.result ++++ r/galera_sst_mariabackup_logarachive.reject +@@ -286,5 +286,113 @@ + DROP TABLE t1; + COMMIT; + SET AUTOCOMMIT=ON; ++Performing State Transfer on a server that has been killed and restarted ++while a DDL was in progress on it ++connection node_1; ++CREATE TABLE t1 (f1 CHAR(255)) ENGINE=InnoDB; ++SET AUTOCOMMIT=OFF; ++START TRANSACTION; ++INSERT INTO t1 VALUES ('node1_committed_before'); ++INSERT INTO t1 VALUES ('node1_committed_before'); ++INSERT INTO t1 VALUES ('node1_committed_before'); ++INSERT INTO t1 VALUES ('node1_committed_before'); ++INSERT INTO t1 VALUES ('node1_committed_before'); ++connection node_2; ++START TRANSACTION; ++INSERT INTO t1 VALUES ('node2_committed_before'); ++INSERT INTO t1 VALUES ('node2_committed_before'); ++INSERT INTO t1 VALUES ('node2_committed_before'); ++INSERT INTO t1 VALUES ('node2_committed_before'); ++INSERT INTO t1 VALUES ('node2_committed_before'); ++COMMIT; ++SET GLOBAL debug_dbug = 'd,sync.alter_opened_table'; ++connection node_1; ++ALTER TABLE t1 ADD COLUMN f2 INTEGER; ++connection node_2; ++SET wsrep_sync_wait = 0; ++Killing server ... ++connection node_1; ++SET AUTOCOMMIT=OFF; ++START TRANSACTION; ++INSERT INTO t1 (f1) VALUES ('node1_committed_during'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_during'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_during'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_during'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_during'); ++COMMIT; ++START TRANSACTION; ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++connect node_1a_galera_st_kill_slave_ddl, 127.0.0.1, root, , test, $NODE_MYPORT_1; ++SET AUTOCOMMIT=OFF; ++START TRANSACTION; ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++connection node_2; ++Performing --wsrep-recover ... ++connection node_2; ++Starting server ... ++Using --wsrep-start-position when starting mysqld ... ++SET AUTOCOMMIT=OFF; ++START TRANSACTION; ++INSERT INTO t1 (f1) VALUES ('node2_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node2_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node2_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node2_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node2_committed_after'); ++COMMIT; ++connection node_1; ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_committed_after'); ++COMMIT; ++SET AUTOCOMMIT=OFF; ++START TRANSACTION; ++INSERT INTO t1 (f1) VALUES ('node1_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_after'); ++INSERT INTO t1 (f1) VALUES ('node1_committed_after'); ++COMMIT; ++connection node_1a_galera_st_kill_slave_ddl; ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ++ROLLBACK; ++SELECT COUNT(*) = 2 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 't1'; ++COUNT(*) = 2 ++1 ++SELECT COUNT(*) = 35 FROM t1; ++COUNT(*) = 35 ++1 ++SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; ++COUNT(*) = 0 ++1 ++COMMIT; ++SET AUTOCOMMIT=ON; ++connection node_1; ++SELECT COUNT(*) = 2 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 't1'; ++COUNT(*) = 2 ++1 ++SELECT COUNT(*) = 35 FROM t1; ++COUNT(*) = 35 ++1 ++SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; ++COUNT(*) = 0 ++1 ++DROP TABLE t1; ++COMMIT; ++SET AUTOCOMMIT=ON; ++SET GLOBAL debug_dbug = $debug_orig; + disconnect node_2; + disconnect node_1; diff --git a/mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive.result b/mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive.result new file mode 100644 index 00000000000..09e49e6f717 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_sst_mariabackup_logarchive.result @@ -0,0 +1,292 @@ +connection node_1; +connection node_2; +connection node_2; +connection node_1; +Performing State Transfer on a server that has been shut down cleanly and restarted +connection node_1; +CREATE TABLE t1 (f1 CHAR(255)) ENGINE=InnoDB; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +COMMIT; +connection node_2; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +COMMIT; +Shutting down server ... +connection node_1; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +COMMIT; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +connect node_1a_galera_st_shutdown_slave, 127.0.0.1, root, , test, $NODE_MYPORT_1; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +connection node_2; +Starting server ... +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +COMMIT; +connection node_1; +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +COMMIT; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +COMMIT; +connection node_1a_galera_st_shutdown_slave; +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +ROLLBACK; +SELECT COUNT(*) = 35 FROM t1; +COUNT(*) = 35 +1 +SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; +COUNT(*) = 0 +1 +COMMIT; +SET AUTOCOMMIT=ON; +connection node_1; +SELECT COUNT(*) = 35 FROM t1; +COUNT(*) = 35 +1 +SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; +COUNT(*) = 0 +1 +DROP TABLE t1; +COMMIT; +SET AUTOCOMMIT=ON; +Performing State Transfer on a server that starts from a clean var directory +This is accomplished by shutting down node #2 and removing its var directory before restarting it +connection node_1; +CREATE TABLE t1 (f1 CHAR(255)) ENGINE=InnoDB; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +COMMIT; +connection node_2; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +COMMIT; +Shutting down server ... +connection node_1; +Cleaning var directory ... +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +COMMIT; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +connect node_1a_galera_st_clean_slave, 127.0.0.1, root, , test, $NODE_MYPORT_1; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +connection node_2; +Starting server ... +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +COMMIT; +connection node_1; +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +COMMIT; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +COMMIT; +connection node_1a_galera_st_clean_slave; +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +ROLLBACK; +SELECT COUNT(*) = 35 FROM t1; +COUNT(*) = 35 +1 +SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; +COUNT(*) = 0 +1 +COMMIT; +SET AUTOCOMMIT=ON; +connection node_1; +SELECT COUNT(*) = 35 FROM t1; +COUNT(*) = 35 +1 +SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; +COUNT(*) = 0 +1 +DROP TABLE t1; +COMMIT; +SET AUTOCOMMIT=ON; +Performing State Transfer on a server that has been killed and restarted +connection node_1; +CREATE TABLE t1 (f1 CHAR(255)) ENGINE=InnoDB; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +INSERT INTO t1 VALUES ('node1_committed_before'); +COMMIT; +connection node_2; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +INSERT INTO t1 VALUES ('node2_committed_before'); +COMMIT; +Killing server ... +connection node_1; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +INSERT INTO t1 VALUES ('node1_committed_during'); +COMMIT; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +connect node_1a_galera_st_kill_slave, 127.0.0.1, root, , test, $NODE_MYPORT_1; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +connection node_2; +Performing --wsrep-recover ... +Starting server ... +Using --wsrep-start-position when starting mysqld ... +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +INSERT INTO t1 VALUES ('node2_committed_after'); +COMMIT; +connection node_1; +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +INSERT INTO t1 VALUES ('node1_to_be_committed_after'); +COMMIT; +SET AUTOCOMMIT=OFF; +START TRANSACTION; +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +INSERT INTO t1 VALUES ('node1_committed_after'); +COMMIT; +connection node_1a_galera_st_kill_slave; +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); +ROLLBACK; +SELECT COUNT(*) = 35 FROM t1; +COUNT(*) = 35 +1 +SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; +COUNT(*) = 0 +1 +COMMIT; +SET AUTOCOMMIT=ON; +connection node_1; +SELECT COUNT(*) = 35 FROM t1; +COUNT(*) = 35 +1 +SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; +COUNT(*) = 0 +1 +DROP TABLE t1; +COMMIT; +SET AUTOCOMMIT=ON; +disconnect node_2; +disconnect node_1; diff --git a/mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.cnf b/mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.cnf new file mode 100644 index 00000000000..c52e1d474a6 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.cnf @@ -0,0 +1,17 @@ +!include ../galera_2nodes.cnf + +[mysqld] +wsrep_sst_method=mariabackup +wsrep_sst_auth="root:" +wsrep_debug=ON + +[mysqld.1] +wsrep_provider_options='base_port=@mysqld.1.#galera_port;gcache.size=1;pc.ignore_sb=true' + +[mysqld.2] +wsrep_provider_options='base_port=@mysqld.2.#galera_port;gcache.size=1;pc.ignore_sb=true' + +[sst] +transferfmt=@ENV.MTR_GALERA_TFMT +sst-log-archive=1 +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/tmp/logarchive diff --git a/mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.test b/mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.test new file mode 100644 index 00000000000..060617aee49 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_sst_mariabackup_logarchive.test @@ -0,0 +1,63 @@ +--source include/big_test.inc +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/have_mariabackup.inc + +# Save original auto_increment_offset values. +--let $node_1=node_1 +--let $node_2=node_2 +--source include/auto_increment_offset_save.inc + +--connection node_2 + +--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 = 'Synced' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_state_comment'; +--source include/wait_condition.inc + +--connection node_1 + +--let $wait_condition = SELECT VARIABLE_VALUE = 'Synced' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_state_comment'; +--source include/wait_condition.inc + +--remove_files_wildcard $MYSQLTEST_VARDIR/tmp/logarchive * + +--source suite/galera/include/galera_st_shutdown_slave.inc +--source suite/galera/include/galera_st_clean_slave.inc + +--source suite/galera/include/galera_st_kill_slave.inc +--source suite/galera/include/galera_st_kill_slave_ddl.inc + +# Restore original auto_increment_offset values. +--source include/auto_increment_offset_restore.inc + +--let sst_test_true_count=7 +if (`select version() like '%debug%'`) +{ + --let sst_test_true_count=10 +} + +--source include/galera_end.inc + +--list_files_write_file $MYSQLTEST_VARDIR/tmp/logarchive_list $MYSQLTEST_VARDIR/tmp/logarchive mariabackup.*.log.*.gz + +--perl + use strict; + use warnings; + my $file= $ENV{'MYSQLTEST_VARDIR'}.'/tmp/logarchive_list'; + my $count= 0; + open(FILE, "$file") or die("Error $? opening $file: $!\n"); + while () { + my $line = $_; + $count++; + } + close(FILE) or die("Error $? closing $file: $!"); + if ($count != $ENV{'sst_test_true_count'}) { + die("Wrong log archives counter: $count"); + } +EOF + +--remove_file $MYSQLTEST_VARDIR/tmp/logarchive_list +--remove_files_wildcard $MYSQLTEST_VARDIR/tmp/logarchive * +--rmdir $MYSQLTEST_VARDIR/tmp/logarchive diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 067a777fb9c..51de0f1ce2e 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -535,7 +535,14 @@ read_cnf() ssystag=$(parse_cnf mysqld_safe syslog-tag "${SST_SYSLOG_TAG:-}") ssystag="$ssystag-" sstlogarchive=$(parse_cnf sst sst-log-archive 1) - sstlogarchivedir=$(parse_cnf sst sst-log-archive-dir '/tmp/sst_log_archive') + sstlogarchivedir="" + if [ $sstlogarchive -ne 0 ]; then + sstlogarchivedir=$(parse_cnf sst sst-log-archive-dir \ + '/tmp/sst_log_archive') + if [ -n "$sstlogarchivedir" ]; then + sstlogarchivedir=$(trim_dir "$sstlogarchivedir") + fi + fi if [ $speciald -eq 0 ]; then wsrep_log_error \ @@ -879,7 +886,15 @@ else if [ -n "$sstlogarchivedir" ]; then if [ ! -d "$sstlogarchivedir" ]; then - mkdir -p "$sstlogarchivedir" + if ! mkdir -p "$sstlogarchivedir"; then + sstlogarchivedir="" + wsrep_log_warning \ + "Unable to create '$sstlogarchivedir' directory" + fi + elif [ ! -w "$sstlogarchivedir" ]; then + sstlogarchivedir="" + wsrep_log_warning \ + "The '$sstlogarchivedir' directory is not writtable" fi fi @@ -891,8 +906,8 @@ else newfile="$INNOAPPLYLOG.$ARCHIVETIMESTAMP" fi wsrep_log_info "Moving '$INNOAPPLYLOG' to '$newfile'" - mv "$INNOAPPLYLOG" "$newfile" - gzip "$newfile" + mv "$INNOAPPLYLOG" "$newfile" && gzip "$newfile" || \ + wsrep_log_warning "Failed to archive log file ('$newfile')" fi if [ -e "$INNOMOVELOG" ]; then @@ -903,8 +918,8 @@ else newfile="$INNOMOVELOG.$ARCHIVETIMESTAMP" fi wsrep_log_info "Moving '$INNOMOVELOG' to '$newfile'" - mv "$INNOMOVELOG" "$newfile" - gzip "$newfile" + mv "$INNOMOVELOG" "$newfile" && gzip "$newfile" || + wsrep_log_warning "Failed to archive log file ('$newfile')" fi if [ -e "$INNOBACKUPLOG" ]; then @@ -915,8 +930,8 @@ else newfile="$INNOBACKUPLOG.$ARCHIVETIMESTAMP" fi wsrep_log_info "Moving '$INNOBACKUPLOG' to '$newfile'" - mv "$INNOBACKUPLOG" "$newfile" - gzip "$newfile" + mv "$INNOBACKUPLOG" "$newfile" && gzip "$newfile" || + wsrep_log_warning "Failed to archive log file ('$newfile')" fi fi INNOAPPLY="> '$INNOAPPLYLOG' 2>&1" From 5a8766a98059b93798aa34d6824c6e130727d552 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Thu, 7 Apr 2022 15:40:34 +0300 Subject: [PATCH 04/37] Better comments in Item_in_subselect::inject_in_to_exists_cond() --- sql/item_subselect.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 92ba085af5b..e01c92b7a4f 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2757,6 +2757,8 @@ bool Item_in_subselect::inject_in_to_exists_cond(JOIN *join_arg) } where_item= and_items(thd, join_arg->conds, where_item); + + /* This is the fix_fields() call mentioned in the comment above */ if (!where_item->fixed && where_item->fix_fields(thd, 0)) DBUG_RETURN(true); // TIMOUR TODO: call optimize_cond() for the new where clause @@ -2767,7 +2769,10 @@ bool Item_in_subselect::inject_in_to_exists_cond(JOIN *join_arg) /* Attach back the list of multiple equalities to the new top-level AND. */ if (and_args && join_arg->cond_equal) { - /* The argument list of the top-level AND may change after fix fields. */ + /* + The fix_fields() call above may have changed the argument list, so + fetch it again: + */ and_args= ((Item_cond*) join_arg->conds)->argument_list(); ((Item_cond_and *) (join_arg->conds))->m_cond_equal= *join_arg->cond_equal; From b2ecb622a6d11df4f670041fbd7f48fe4077808a Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Wed, 6 Apr 2022 19:41:50 +0700 Subject: [PATCH 05/37] Remove a garbage file from mysql-test --- mysql-test/main/show_explain.cc | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 mysql-test/main/show_explain.cc diff --git a/mysql-test/main/show_explain.cc b/mysql-test/main/show_explain.cc deleted file mode 100644 index e69de29bb2d..00000000000 From b725a917572c53cd43ecb2cd9221ab828f7a9447 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 7 Apr 2022 17:49:59 +0200 Subject: [PATCH 06/37] MDEV-28253 Mysqldump - INVISIBLE column error --- mysql-test/main/show.result | 12 ++++++++++++ mysql-test/main/show.test | 11 +++++++++++ mysql-test/main/show_check.result | 4 ++-- mysql-test/suite/funcs_1/r/is_columns.result | 6 +++--- mysql-test/suite/funcs_1/r/is_columns_is.result | 4 ++-- .../suite/funcs_1/r/is_columns_is_embedded.result | 4 ++-- sql/sql_show.cc | 2 +- tests/mysql_client_test.c | 2 +- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/mysql-test/main/show.result b/mysql-test/main/show.result index 4a9e2738346..e453ee90c7e 100644 --- a/mysql-test/main/show.result +++ b/mysql-test/main/show.result @@ -53,3 +53,15 @@ drop table t1; # # End of 10.2 tests # +# +# MDEV-28253 Mysqldump - INVISIBLE column error +# +create table t1 (a int, b datetime invisible on update now() without system versioning) with system versioning; +desc t1; +Field Type Null Key Default Extra +a int(11) YES NULL +b datetime YES NULL on update current_timestamp(), INVISIBLE, WITHOUT SYSTEM VERSIONING +drop table t1; +# +# End of 10.3 tests +# diff --git a/mysql-test/main/show.test b/mysql-test/main/show.test index 9b0b58349d5..37c30000e59 100644 --- a/mysql-test/main/show.test +++ b/mysql-test/main/show.test @@ -45,3 +45,14 @@ drop table t1; --echo # --echo # End of 10.2 tests --echo # + +--echo # +--echo # MDEV-28253 Mysqldump - INVISIBLE column error +--echo # +create table t1 (a int, b datetime invisible on update now() without system versioning) with system versioning; +desc t1; +drop table t1; + +--echo # +--echo # End of 10.3 tests +--echo # diff --git a/mysql-test/main/show_check.result b/mysql-test/main/show_check.result index ed9e191f06d..81b1566cb4c 100644 --- a/mysql-test/main/show_check.result +++ b/mysql-test/main/show_check.result @@ -983,7 +983,7 @@ def information_schema COLUMNS COLUMNS CHARACTER_SET_NAME CHARACTER_SET_NAME 253 def information_schema COLUMNS COLUMNS COLLATION_NAME COLLATION_NAME 253 96 0 Y 4096 0 33 def information_schema COLUMNS COLUMNS COLUMN_TYPE COLUMN_TYPE 252 589815 7 N 4113 0 33 def information_schema COLUMNS COLUMNS COLUMN_KEY COLUMN_KEY 253 9 3 N 4097 0 33 -def information_schema COLUMNS COLUMNS EXTRA EXTRA 253 90 0 N 4097 0 33 +def information_schema COLUMNS COLUMNS EXTRA EXTRA 253 240 0 N 4097 0 33 def information_schema COLUMNS COLUMNS PRIVILEGES PRIVILEGES 253 240 31 N 4097 0 33 def information_schema COLUMNS COLUMNS COLUMN_COMMENT COLUMN_COMMENT 253 3072 0 N 4097 0 33 TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT @@ -1002,7 +1002,7 @@ def information_schema COLUMNS COLUMNS COLUMN_TYPE Type 252 589815 7 N 4113 0 33 def information_schema COLUMNS COLUMNS IS_NULLABLE Null 253 9 2 N 4097 0 33 def information_schema COLUMNS COLUMNS COLUMN_KEY Key 253 9 3 N 4097 0 33 def information_schema COLUMNS COLUMNS COLUMN_DEFAULT Default 252 589788 0 Y 4112 0 33 -def information_schema COLUMNS COLUMNS EXTRA Extra 253 90 0 N 4097 0 33 +def information_schema COLUMNS COLUMNS EXTRA Extra 253 240 0 N 4097 0 33 Field Type Null Key Default Extra c int(11) NO PRI NULL ---------------------------------------------------------------- diff --git a/mysql-test/suite/funcs_1/r/is_columns.result b/mysql-test/suite/funcs_1/r/is_columns.result index 13042dd11bc..35106e7ded5 100644 --- a/mysql-test/suite/funcs_1/r/is_columns.result +++ b/mysql-test/suite/funcs_1/r/is_columns.result @@ -45,7 +45,7 @@ CHARACTER_SET_NAME varchar(32) YES NULL COLLATION_NAME varchar(32) YES NULL COLUMN_TYPE longtext NO NULL COLUMN_KEY varchar(3) NO NULL -EXTRA varchar(30) NO NULL +EXTRA varchar(80) NO NULL PRIVILEGES varchar(80) NO NULL COLUMN_COMMENT varchar(1024) NO NULL IS_GENERATED varchar(6) NO NULL @@ -70,7 +70,7 @@ COLUMNS CREATE TEMPORARY TABLE `COLUMNS` ( `COLLATION_NAME` varchar(32), `COLUMN_TYPE` longtext NOT NULL, `COLUMN_KEY` varchar(3) NOT NULL, - `EXTRA` varchar(30) NOT NULL, + `EXTRA` varchar(80) NOT NULL, `PRIVILEGES` varchar(80) NOT NULL, `COLUMN_COMMENT` varchar(1024) NOT NULL, `IS_GENERATED` varchar(6) NOT NULL, @@ -95,7 +95,7 @@ CHARACTER_SET_NAME varchar(32) YES NULL COLLATION_NAME varchar(32) YES NULL COLUMN_TYPE longtext NO NULL COLUMN_KEY varchar(3) NO NULL -EXTRA varchar(30) NO NULL +EXTRA varchar(80) NO NULL PRIVILEGES varchar(80) NO NULL COLUMN_COMMENT varchar(1024) NO NULL IS_GENERATED varchar(6) NO NULL diff --git a/mysql-test/suite/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result index 53bb56742b0..b7c094eec56 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is.result @@ -73,7 +73,7 @@ def information_schema COLUMNS COLUMN_NAME 4 NULL NO varchar 64 192 NULL NULL NU def information_schema COLUMNS COLUMN_TYPE 16 NULL NO longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext select NEVER NULL def information_schema COLUMNS DATA_TYPE 8 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select NEVER NULL def information_schema COLUMNS DATETIME_PRECISION 13 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select NEVER NULL -def information_schema COLUMNS EXTRA 18 NULL NO varchar 30 90 NULL NULL NULL utf8 utf8_general_ci varchar(30) select NEVER NULL +def information_schema COLUMNS EXTRA 18 NULL NO varchar 80 240 NULL NULL NULL utf8 utf8_general_ci varchar(80) select NEVER NULL def information_schema COLUMNS GENERATION_EXPRESSION 22 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext select NEVER NULL def information_schema COLUMNS IS_GENERATED 21 NULL NO varchar 6 18 NULL NULL NULL utf8 utf8_general_ci varchar(6) select NEVER NULL def information_schema COLUMNS IS_NULLABLE 7 NULL NO varchar 3 9 NULL NULL NULL utf8 utf8_general_ci varchar(3) select NEVER NULL @@ -619,7 +619,7 @@ NULL information_schema COLUMNS DATETIME_PRECISION bigint NULL NULL NULL NULL bi 3.0000 information_schema COLUMNS COLLATION_NAME varchar 32 96 utf8 utf8_general_ci varchar(32) 1.0000 information_schema COLUMNS COLUMN_TYPE longtext 4294967295 4294967295 utf8 utf8_general_ci longtext 3.0000 information_schema COLUMNS COLUMN_KEY varchar 3 9 utf8 utf8_general_ci varchar(3) -3.0000 information_schema COLUMNS EXTRA varchar 30 90 utf8 utf8_general_ci varchar(30) +3.0000 information_schema COLUMNS EXTRA varchar 80 240 utf8 utf8_general_ci varchar(80) 3.0000 information_schema COLUMNS PRIVILEGES varchar 80 240 utf8 utf8_general_ci varchar(80) 3.0000 information_schema COLUMNS COLUMN_COMMENT varchar 1024 3072 utf8 utf8_general_ci varchar(1024) 3.0000 information_schema COLUMNS IS_GENERATED varchar 6 18 utf8 utf8_general_ci varchar(6) diff --git a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result index c0bd2ac09c1..0855cdf58d6 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result @@ -73,7 +73,7 @@ def information_schema COLUMNS COLUMN_NAME 4 NULL NO varchar 64 192 NULL NULL NU def information_schema COLUMNS COLUMN_TYPE 16 NULL NO longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext NEVER NULL def information_schema COLUMNS DATA_TYPE 8 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) NEVER NULL def information_schema COLUMNS DATETIME_PRECISION 13 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned NEVER NULL -def information_schema COLUMNS EXTRA 18 NULL NO varchar 30 90 NULL NULL NULL utf8 utf8_general_ci varchar(30) NEVER NULL +def information_schema COLUMNS EXTRA 18 NULL NO varchar 80 240 NULL NULL NULL utf8 utf8_general_ci varchar(80) NEVER NULL def information_schema COLUMNS GENERATION_EXPRESSION 22 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext NEVER NULL def information_schema COLUMNS IS_GENERATED 21 NULL NO varchar 6 18 NULL NULL NULL utf8 utf8_general_ci varchar(6) NEVER NULL def information_schema COLUMNS IS_NULLABLE 7 NULL NO varchar 3 9 NULL NULL NULL utf8 utf8_general_ci varchar(3) NEVER NULL @@ -619,7 +619,7 @@ NULL information_schema COLUMNS DATETIME_PRECISION bigint NULL NULL NULL NULL bi 3.0000 information_schema COLUMNS COLLATION_NAME varchar 32 96 utf8 utf8_general_ci varchar(32) 1.0000 information_schema COLUMNS COLUMN_TYPE longtext 4294967295 4294967295 utf8 utf8_general_ci longtext 3.0000 information_schema COLUMNS COLUMN_KEY varchar 3 9 utf8 utf8_general_ci varchar(3) -3.0000 information_schema COLUMNS EXTRA varchar 30 90 utf8 utf8_general_ci varchar(30) +3.0000 information_schema COLUMNS EXTRA varchar 80 240 utf8 utf8_general_ci varchar(80) 3.0000 information_schema COLUMNS PRIVILEGES varchar 80 240 utf8 utf8_general_ci varchar(80) 3.0000 information_schema COLUMNS COLUMN_COMMENT varchar 1024 3072 utf8 utf8_general_ci varchar(1024) 3.0000 information_schema COLUMNS IS_GENERATED varchar 6 18 utf8 utf8_general_ci varchar(6) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 2a3dbceb4cb..c0d7d7e95f6 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -9238,7 +9238,7 @@ ST_FIELD_INFO columns_fields_info[]= OPEN_FRM_ONLY}, {"COLUMN_TYPE", 65535, MYSQL_TYPE_STRING, 0, 0, "Type", OPEN_FRM_ONLY}, {"COLUMN_KEY", 3, MYSQL_TYPE_STRING, 0, 0, "Key", OPEN_FRM_ONLY}, - {"EXTRA", 30, MYSQL_TYPE_STRING, 0, 0, "Extra", OPEN_FRM_ONLY}, + {"EXTRA", 80, MYSQL_TYPE_STRING, 0, 0, "Extra", OPEN_FRM_ONLY}, {"PRIVILEGES", 80, MYSQL_TYPE_STRING, 0, 0, "Privileges", OPEN_FRM_ONLY}, {"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Comment", OPEN_FRM_ONLY}, diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index dc741b8ec41..326544d58de 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -7557,7 +7557,7 @@ static void test_explain_bug() verify_prepare_field(result, 5, "Extra", "EXTRA", mysql_get_server_version(mysql) <= 50000 ? MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, - 0, 0, "information_schema", 30, 0); + 0, 0, "information_schema", 80, 0); mysql_free_result(result); mysql_stmt_close(stmt); From 4194f7b6054d9cf888d657f08c88dc27031def7b Mon Sep 17 00:00:00 2001 From: Nayuta Yanagisawa Date: Wed, 16 Feb 2022 17:56:49 +0900 Subject: [PATCH 07/37] MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list The original query "SELECT IF(COUNT(a.`id`)>=0,'Y','N') FROM t" is transformed to "SELECT COUNT(a.`id`), IF(ref >= 0, 'Y', 'N') FROM t", where ref is Item_ref to "COUNT(a.`id`)", by split_sum_func(). Spider walks the item list twice, invoking spider_db_print_item_type(). The first invocation is in spider_create_group_by_handler() with str == NULL. The second one is in spider_group_by_handler::init_scan() with str != NULL. spider_db_print_item_type() prints nothing at the first invocation, and it prints item at the second invocation. However, at the second invocation, the above mentioned ref to "COUNT(a.`id`)" points to a field in a temporary table where the result will be stored. Thus, to look behind the item_ref, Spider need to generate the query earlier. A possible fix would be to generate a query to send in spider_create_group_by_handler(). However, the fix requires a considerable amount of changes of the Spider's GROUP BY handler. I'd like to avoid that. So, I fix the problem by not to use the GROUP BY handler when a query contains Item_ref whose table_name, name, and alias_name_used are not set. --- .../spider/bugfix/r/mdev_25116.result | 33 +++++++++++++++++ .../mysql-test/spider/bugfix/t/mdev_25116.cnf | 3 ++ .../spider/bugfix/t/mdev_25116.test | 37 +++++++++++++++++++ storage/spider/spd_db_conn.cc | 3 +- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result new file mode 100644 index 00000000000..cd2ca4b1635 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result @@ -0,0 +1,33 @@ +# +# MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (id INT); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +id INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +connection master_1; +SELECT IF(COUNT(id > 0),'Y','N') FROM tbl_a; +IF(COUNT(id > 0),'Y','N') +N +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf new file mode 100644 index 00000000000..05dfd8a0bce --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test new file mode 100644 index 00000000000..70c2bcc51b7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test @@ -0,0 +1,37 @@ +--echo # +--echo # MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +CREATE TABLE tbl_a (id INT); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + id INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +--connection master_1 +SELECT IF(COUNT(id > 0),'Y','N') FROM tbl_a; + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index c488dfcb806..2569574561e 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -9298,8 +9298,7 @@ int spider_db_open_item_ref( } DBUG_RETURN(0); } - DBUG_RETURN(spider_db_print_item_type(*(item_ref->ref), NULL, spider, str, - alias, alias_length, dbton_id, use_fields, fields)); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); // MDEV-25116 } DBUG_RETURN(spider_db_open_item_ident((Item_ident *) item_ref, spider, str, alias, alias_length, dbton_id, use_fields, fields)); From 3814b04d6b0b87e20cdfa85933221d463ce71515 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 8 Apr 2022 10:23:24 +0400 Subject: [PATCH 08/37] MDEV-28062 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 on INSERT..SELECT Adding an MTR test only. This problem was earlier fixed by the patch for: MDEV-28078 Garbage on multiple equal ENUMs with tricky character sets --- mysql-test/main/ctype_utf32_innodb.result | 34 ++++++++++++++++++++++ mysql-test/main/ctype_utf32_innodb.test | 35 +++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 mysql-test/main/ctype_utf32_innodb.result create mode 100644 mysql-test/main/ctype_utf32_innodb.test diff --git a/mysql-test/main/ctype_utf32_innodb.result b/mysql-test/main/ctype_utf32_innodb.result new file mode 100644 index 00000000000..82b7348cabb --- /dev/null +++ b/mysql-test/main/ctype_utf32_innodb.result @@ -0,0 +1,34 @@ +# +# Start of 10.3 tests +# +# +# MDEV-28062 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 on INSERT..SELECT +# +SET sql_mode=''; +CREATE TABLE t1 ( +HOST CHAR DEFAULT '%', +USER CHAR DEFAULT '%', +ROLE CHAR DEFAULT '%', +ENABLED ENUM ('a','a') DEFAULT 'a', +HISTORY ENUM ('a','a') DEFAULT 'a' +) COLLATE=utf32_general_ci ENGINE=InnoDB; +Warnings: +Note 1291 Column 'ENABLED' has duplicated value 'a' in ENUM +Note 1291 Column 'HISTORY' has duplicated value 'a' in ENUM +INSERT INTO t1 SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 ( +HOST CHAR DEFAULT '%', +USER CHAR DEFAULT '%', +ROLE CHAR DEFAULT '%', +ENABLED ENUM ('a','a') DEFAULT 'a', +HISTORY ENUM ('a','a') DEFAULT 'a' +) COLLATE=utf32_general_ci ENGINE=MyISAM; +Warnings: +Note 1291 Column 'ENABLED' has duplicated value 'a' in ENUM +Note 1291 Column 'HISTORY' has duplicated value 'a' in ENUM +INSERT INTO t1 SELECT * FROM t1; +DROP TABLE t1; +# +# End of 10.3 tests +# diff --git a/mysql-test/main/ctype_utf32_innodb.test b/mysql-test/main/ctype_utf32_innodb.test new file mode 100644 index 00000000000..1663b5adafb --- /dev/null +++ b/mysql-test/main/ctype_utf32_innodb.test @@ -0,0 +1,35 @@ +--source include/have_innodb.inc + +--echo # +--echo # Start of 10.3 tests +--echo # + +--echo # +--echo # MDEV-28062 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 on INSERT..SELECT +--echo # + +SET sql_mode=''; + +CREATE TABLE t1 ( + HOST CHAR DEFAULT '%', + USER CHAR DEFAULT '%', + ROLE CHAR DEFAULT '%', + ENABLED ENUM ('a','a') DEFAULT 'a', + HISTORY ENUM ('a','a') DEFAULT 'a' +) COLLATE=utf32_general_ci ENGINE=InnoDB; +INSERT INTO t1 SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + HOST CHAR DEFAULT '%', + USER CHAR DEFAULT '%', + ROLE CHAR DEFAULT '%', + ENABLED ENUM ('a','a') DEFAULT 'a', + HISTORY ENUM ('a','a') DEFAULT 'a' +) COLLATE=utf32_general_ci ENGINE=MyISAM; +INSERT INTO t1 SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.3 tests +--echo # From 27b5d814e2c851569a0d75e4217da4a552b79f25 Mon Sep 17 00:00:00 2001 From: Nayuta Yanagisawa Date: Tue, 29 Mar 2022 23:41:40 +0900 Subject: [PATCH 09/37] MDEV-27065 Partitioning tables with custom data directories moves data back to default directory The partitioning engine does not support the table-level DATA/INDEX DIRECTORY specification. If one create a non-partitioned table with the DATA/INDEX DIRECTORY option and then performs ALTER TABLE ... PARTITION BY on it, the DATA/INDEX DIRECTORY specification of the old schema is ignored. The behavior might be a bit surprising for users because the value of a usual table option applies to all the partitions. Thus, we raise a warning on such ALTER TABLE ... PARTITION BY. --- .../suite/parts/inc/part_alter_values.inc | 37 +++++++++++++++++-- .../parts/r/partition_alter_innodb.result | 13 +++++++ .../parts/r/partition_alter_maria.result | 20 ++++++++++ .../parts/r/partition_alter_myisam.result | 20 ++++++++++ sql/ha_partition.cc | 22 ++++++++++- 5 files changed, 108 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/parts/inc/part_alter_values.inc b/mysql-test/suite/parts/inc/part_alter_values.inc index ac69169a9ca..2f16476c78b 100644 --- a/mysql-test/suite/parts/inc/part_alter_values.inc +++ b/mysql-test/suite/parts/inc/part_alter_values.inc @@ -36,12 +36,43 @@ ALTER TABLE t1 REORGANIZE PARTITION p1 INTO ); DROP TABLE t1; -# -# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION -# +--echo # +--echo # MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +--echo # --eval create table t1 (i int) engine=$engine partition by range(i) (partition p0 values less than (10)) lock table t1 write; --error ER_SAME_NAME_PARTITION alter table t1 add partition (partition p0 values less than (20)); alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; + +--echo # +--echo # MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +--echo # + +--mkdir $MYSQLTEST_VARDIR/tmp/mdev_27065 + +--disable_query_log +--eval CREATE TABLE t1 (id INT) ENGINE=$engine DATA DIRECTORY='$MYSQLTEST_VARDIR/tmp/mdev_27065' +--enable_query_log +ALTER TABLE t1 PARTITION BY RANGE(id)( + PARTITION p0 VALUES LESS THAN (1000), + PARTITION p1 VALUES LESS THAN MAXVALUE +); +DROP TABLE t1; + +# InnoDB doesn't support INDEX DIRECTORY. +if (`SELECT IF('$engine' != 'InnoDB', 1, 0)`) +{ + --disable_query_log + --eval CREATE TABLE t2 (id INT) ENGINE=$engine INDEX DIRECTORY='$MYSQLTEST_VARDIR/tmp/mdev_27065' + --enable_query_log + ALTER TABLE t2 PARTITION BY RANGE(id)( + PARTITION p0 VALUES LESS THAN (1000), + PARTITION p1 VALUES LESS THAN MAXVALUE + ); + DROP TABLE t2; +} + +--remove_files_wildcard $MYSQLTEST_VARDIR/tmp/mdev_27065 * +--rmdir $MYSQLTEST_VARDIR/tmp/mdev_27065 diff --git a/mysql-test/suite/parts/r/partition_alter_innodb.result b/mysql-test/suite/parts/r/partition_alter_innodb.result index f3921a1db26..ae3caaa4981 100644 --- a/mysql-test/suite/parts/r/partition_alter_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter_innodb.result @@ -42,9 +42,22 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; +# +# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +# create table t1 (i int) engine=InnoDB partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; +# +# MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +# +ALTER TABLE t1 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 table option of old schema is ignored +DROP TABLE t1; diff --git a/mysql-test/suite/parts/r/partition_alter_maria.result b/mysql-test/suite/parts/r/partition_alter_maria.result index 77f511d9b3b..358ffbdfbe7 100644 --- a/mysql-test/suite/parts/r/partition_alter_maria.result +++ b/mysql-test/suite/parts/r/partition_alter_maria.result @@ -69,9 +69,29 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; +# +# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +# create table t1 (i int) engine=Aria partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; +# +# MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +# +ALTER TABLE t1 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 table option of old schema is ignored +DROP TABLE t1; +ALTER TABLE t2 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 table option of old schema is ignored +DROP TABLE t2; diff --git a/mysql-test/suite/parts/r/partition_alter_myisam.result b/mysql-test/suite/parts/r/partition_alter_myisam.result index ce3e04d6c97..9d76881fdfa 100644 --- a/mysql-test/suite/parts/r/partition_alter_myisam.result +++ b/mysql-test/suite/parts/r/partition_alter_myisam.result @@ -42,12 +42,32 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; +# +# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +# create table t1 (i int) engine=MyISAM partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; +# +# MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +# +ALTER TABLE t1 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 table option of old schema is ignored +DROP TABLE t1; +ALTER TABLE t2 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 table option of old schema is ignored +DROP TABLE t2; create table t1 ( c1 int, c2 int, c3 varchar(100)) delay_key_write=1 partition by key(c1) ( partition p01 data directory = 'MYSQL_TMP_DIR' diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 4345f9eb9ca..3f9da331334 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -678,6 +678,7 @@ int ha_partition::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info) { int error; + THD *thd= ha_thd(); char name_buff[FN_REFLEN + 1], name_lc_buff[FN_REFLEN]; char *name_buffer_ptr; const char *path; @@ -695,8 +696,27 @@ int ha_partition::create(const char *name, TABLE *table_arg, my_error(ER_PARTITION_NO_TEMPORARY, MYF(0)); DBUG_RETURN(TRUE); } + /* + The following block should be removed once the table-level data directory + specification is supported by the partitioning engine (MDEV-28108). + */ + if (thd_sql_command(thd) == SQLCOM_ALTER_TABLE && create_info) + { + if (create_info->data_file_name) + { + push_warning_printf( + thd, Sql_condition::WARN_LEVEL_WARN, WARN_OPTION_IGNORED, + " table option of old schema is ignored"); + } + if (create_info->index_file_name) + { + push_warning_printf( + thd, Sql_condition::WARN_LEVEL_WARN, WARN_OPTION_IGNORED, + " table option of old schema is ignored"); + } + } - if (get_from_handler_file(name, ha_thd()->mem_root, false)) + if (get_from_handler_file(name, thd->mem_root, false)) DBUG_RETURN(TRUE); DBUG_ASSERT(m_file_buffer); DBUG_PRINT("enter", ("name: (%s)", name)); From d623b5a1dd9196fdeb60d933a51f48967c9d4196 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 8 Apr 2022 00:06:53 +0200 Subject: [PATCH 10/37] MDEV-22282 When using mysqldump to backup a view that contains derived tables, the database name is prepended to each table in the view derived tables have db = "", table_name = "*", those aren't real names to be compared with. --- mysql-test/main/cte_nonrecursive.result | 14 +++++++------- mysql-test/main/cte_recursive.result | 4 ++-- mysql-test/main/intersect.result | 2 +- mysql-test/main/lock_view.result | 2 +- mysql-test/main/view.result | 4 ++-- sql/sql_show.cc | 3 ++- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/mysql-test/main/cte_nonrecursive.result b/mysql-test/main/cte_nonrecursive.result index c9bf9e874fd..ef821d29527 100644 --- a/mysql-test/main/cte_nonrecursive.result +++ b/mysql-test/main/cte_nonrecursive.result @@ -571,7 +571,7 @@ with t as (select a from t1 where b >= 'c') select * from t2,t where t2.c=t.a; show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with t as (select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` >= 'c')select `test`.`t2`.`c` AS `c`,`t`.`a` AS `a` from (`test`.`t2` join `t`) where `test`.`t2`.`c` = `t`.`a` latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with t as (select `t1`.`a` AS `a` from `t1` where `t1`.`b` >= 'c')select `t2`.`c` AS `c`,`t`.`a` AS `a` from (`t2` join `t`) where `t2`.`c` = `t`.`a` latin1 latin1_swedish_ci select * from v1; c a 4 4 @@ -588,7 +588,7 @@ with t as (select a, count(*) from t1 where b >= 'c' group by a) select * from t2,t where t2.c=t.a; show create view v2; View Create View character_set_client collation_connection -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS with t as (select `test`.`t1`.`a` AS `a`,count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` >= 'c' group by `test`.`t1`.`a`)select `test`.`t2`.`c` AS `c`,`t`.`a` AS `a`,`t`.`count(*)` AS `count(*)` from (`test`.`t2` join `t`) where `test`.`t2`.`c` = `t`.`a` latin1 latin1_swedish_ci +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS with t as (select `t1`.`a` AS `a`,count(0) AS `count(*)` from `t1` where `t1`.`b` >= 'c' group by `t1`.`a`)select `t2`.`c` AS `c`,`t`.`a` AS `a`,`t`.`count(*)` AS `count(*)` from (`t2` join `t`) where `t2`.`c` = `t`.`a` latin1 latin1_swedish_ci select * from v2; c a count(*) 4 4 2 @@ -606,7 +606,7 @@ with t(c) as (select a from t1 where b >= 'c') select * from t r1 where r1.c=4; show create view v3; View Create View character_set_client collation_connection -v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS with t(c) as (select `test`.`t1`.`a` AS `c` from `test`.`t1` where `test`.`t1`.`b` >= 'c')select `r1`.`c` AS `c` from `t` `r1` where `r1`.`c` = 4 latin1 latin1_swedish_ci +v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS with t(c) as (select `t1`.`a` AS `c` from `t1` where `t1`.`b` >= 'c')select `r1`.`c` AS `c` from `t` `r1` where `r1`.`c` = 4 latin1 latin1_swedish_ci select * from v3; c 4 @@ -618,7 +618,7 @@ with t(c) as (select a from t1 where b >= 'c') select * from t r1, t r2 where r1.c=r2.c and r2.c=4; show create view v4; View Create View character_set_client collation_connection -v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS with t(c) as (select `test`.`t1`.`a` AS `c` from `test`.`t1` where `test`.`t1`.`b` >= 'c')select `r1`.`c` AS `c`,`r2`.`c` AS `d` from (`t` `r1` join `t` `r2`) where `r1`.`c` = `r2`.`c` and `r2`.`c` = 4 latin1 latin1_swedish_ci +v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS with t(c) as (select `t1`.`a` AS `c` from `t1` where `t1`.`b` >= 'c')select `r1`.`c` AS `c`,`r2`.`c` AS `d` from (`t` `r1` join `t` `r2`) where `r1`.`c` = `r2`.`c` and `r2`.`c` = 4 latin1 latin1_swedish_ci select * from v4; c d 4 4 @@ -1021,10 +1021,10 @@ select a from t1; show table status; show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with t as (select `s`.`a` AS `a` from (select `test`.`t1`.`a` AS `a` from `test`.`t1`) `s`), r as (select `t`.`a` AS `a` from (`test`.`t2` join `t`) where `test`.`t2`.`b` = `t`.`a`)select `r`.`a` AS `a` from `r` latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with t as (select `s`.`a` AS `a` from (select `t1`.`a` AS `a` from `t1`) `s`), r as (select `t`.`a` AS `a` from (`t2` join `t`) where `t2`.`b` = `t`.`a`)select `r`.`a` AS `a` from `r` latin1 latin1_swedish_ci show create view v2; View Create View character_set_client collation_connection -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS with t as (select `s`.`a` AS `a` from (select `test`.`t1`.`a` AS `a` from `test`.`t1`) `s`), r as (select `t`.`a` AS `a` from (`test`.`t2` join `t`) where `test`.`t2`.`b` = `t`.`a`)select `test`.`t1`.`a` AS `a` from `test`.`t1` latin1 latin1_swedish_ci +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS with t as (select `s`.`a` AS `a` from (select `t1`.`a` AS `a` from `t1`) `s`), r as (select `t`.`a` AS `a` from (`t2` join `t`) where `t2`.`b` = `t`.`a`)select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci select * from v1; a 2 @@ -1349,7 +1349,7 @@ r.r_regionkey in select r_regionkey from t where r_name <> "ASIA"); show create view v; View Create View character_set_client collation_connection -v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `n`.`n_nationkey` AS `n_nationkey`,`n`.`n_name` AS `n_name`,`n`.`n_regionkey` AS `n_regionkey`,`r`.`r_regionkey` AS `r_regionkey`,`r`.`r_name` AS `r_name` from (`test`.`nation` `n` join `test`.`region` `r`) where `n`.`n_regionkey` = `r`.`r_regionkey` and `r`.`r_regionkey` in (with t as (select `test`.`region`.`r_regionkey` AS `r_regionkey`,`test`.`region`.`r_name` AS `r_name` from `test`.`region` where `test`.`region`.`r_regionkey` <= 3)select `t`.`r_regionkey` from `t` where `t`.`r_name` <> 'ASIA') latin1 latin1_swedish_ci +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `n`.`n_nationkey` AS `n_nationkey`,`n`.`n_name` AS `n_name`,`n`.`n_regionkey` AS `n_regionkey`,`r`.`r_regionkey` AS `r_regionkey`,`r`.`r_name` AS `r_name` from (`nation` `n` join `region` `r`) where `n`.`n_regionkey` = `r`.`r_regionkey` and `r`.`r_regionkey` in (with t as (select `region`.`r_regionkey` AS `r_regionkey`,`region`.`r_name` AS `r_name` from `region` where `region`.`r_regionkey` <= 3)select `t`.`r_regionkey` from `t` where `t`.`r_name` <> 'ASIA') latin1 latin1_swedish_ci select * from v; n_nationkey n_name n_regionkey r_regionkey r_name 0 ALGERIA 0 0 AFRICA diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result index 86d5fa08b1f..993fad4f34d 100644 --- a/mysql-test/main/cte_recursive.result +++ b/mysql-test/main/cte_recursive.result @@ -818,7 +818,7 @@ where p.id = a.father or p.id = a.mother select * from ancestors; show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with recursive ancestors as (select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' and `test`.`folks`.`dob` = '2000-01-01' union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from (`test`.`folks` `p` join `ancestors` `a`) where `p`.`id` = `a`.`father` or `p`.`id` = `a`.`mother`)select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors` latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with recursive ancestors as (select `folks`.`id` AS `id`,`folks`.`name` AS `name`,`folks`.`dob` AS `dob`,`folks`.`father` AS `father`,`folks`.`mother` AS `mother` from `folks` where `folks`.`name` = 'Me' and `folks`.`dob` = '2000-01-01' union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from (`folks` `p` join `ancestors` `a`) where `p`.`id` = `a`.`father` or `p`.`id` = `a`.`mother`)select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors` latin1 latin1_swedish_ci select * from v1; id name dob father mother 100 Me 2000-01-01 20 30 @@ -849,7 +849,7 @@ where p.id = ma.mother select * from ancestors; show create view v2; View Create View character_set_client collation_connection -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS with recursive ancestors as (select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from (`test`.`folks` `p` join `ancestors` `fa`) where `p`.`id` = `fa`.`father` union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from (`test`.`folks` `p` join `ancestors` `ma`) where `p`.`id` = `ma`.`mother`)select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors` latin1 latin1_swedish_ci +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS with recursive ancestors as (select `folks`.`id` AS `id`,`folks`.`name` AS `name`,`folks`.`dob` AS `dob`,`folks`.`father` AS `father`,`folks`.`mother` AS `mother` from `folks` where `folks`.`name` = 'Me' union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from (`folks` `p` join `ancestors` `fa`) where `p`.`id` = `fa`.`father` union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from (`folks` `p` join `ancestors` `ma`) where `p`.`id` = `ma`.`mother`)select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors` latin1 latin1_swedish_ci select * from v2; id name dob father mother 100 Me 2000-01-01 20 30 diff --git a/mysql-test/main/intersect.result b/mysql-test/main/intersect.result index 62ab0b7e5de..827d1f4d909 100644 --- a/mysql-test/main/intersect.result +++ b/mysql-test/main/intersect.result @@ -724,7 +724,7 @@ a b drop procedure p1; show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (select 4 AS `4`,4 AS `4`) latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1`) union select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((select `t2`.`c` AS `c`,`t2`.`d` AS `d` from `t2`) intersect (select `t3`.`e` AS `e`,`t3`.`f` AS `f` from `t3`)) `__3` union (select 4 AS `4`,4 AS `4`) latin1 latin1_swedish_ci drop view v1; drop tables t1,t2,t3; # diff --git a/mysql-test/main/lock_view.result b/mysql-test/main/lock_view.result index 364c2cddf60..48c45dcf23d 100644 --- a/mysql-test/main/lock_view.result +++ b/mysql-test/main/lock_view.result @@ -256,7 +256,7 @@ SET character_set_client = @saved_cs_client; /*!50001 SET collation_connection = latin1_swedish_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`u1`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v1` AS select `dt`.`id` AS `id` from (select `test`.`t1`.`id` AS `id` from `test`.`t1`) `dt` */; +/*!50001 VIEW `v1` AS select `dt`.`id` AS `id` from (select `t1`.`id` AS `id` from `t1`) `dt` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; diff --git a/mysql-test/main/view.result b/mysql-test/main/view.result index 6483d76bba1..74b25cc94bf 100644 --- a/mysql-test/main/view.result +++ b/mysql-test/main/view.result @@ -6543,7 +6543,7 @@ INSERT INTO t3 VALUES (1),(8); CREATE VIEW v1 AS SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`i` AS `i`,`alias1`.`j` AS `j` from (`test`.`t1` left join (select `test`.`t2`.`j` AS `j` from (`test`.`t2` join `test`.`t3` on(`test`.`t3`.`k` = `test`.`t2`.`j`))) `alias1` on(`test`.`t1`.`i` = `alias1`.`j`)) latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i`,`alias1`.`j` AS `j` from (`t1` left join (select `t2`.`j` AS `j` from (`t2` join `t3` on(`t3`.`k` = `t2`.`j`))) `alias1` on(`t1`.`i` = `alias1`.`j`)) latin1 latin1_swedish_ci SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); i j 3 NULL @@ -6690,7 +6690,7 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `testalias`.`testcase` AS `testcase` from (select case when 1 in (select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`a` < 2) then 1 end AS `testcase`) `testalias` latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `testalias`.`testcase` AS `testcase` from (select case when 1 in (select `t1`.`a` from `t1` where `t1`.`a` < 2) then 1 end AS `testcase`) `testalias` latin1 latin1_swedish_ci SELECT * FROM v1; testcase 1 diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c0d7d7e95f6..6f607c2dfb0 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2660,7 +2660,8 @@ static int show_create_view(THD *thd, TABLE_LIST *table, String *buff) tbl; tbl= tbl->next_global) { - if (cmp(&table->view_db, tbl->view ? &tbl->view_db : &tbl->db)) + if (!tbl->is_derived() && + cmp(&table->view_db, tbl->view ? &tbl->view_db : &tbl->db)) { table->compact_view_format= FALSE; break; From 2ae92e89817b1eceed134fcf98e21f99ce26a22d Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Sat, 9 Apr 2022 23:01:26 +0400 Subject: [PATCH 11/37] MDEV-28267 ASAN heap-use-after-free in Item_sp::func_name_cstring This crash happens on a combination of multiple conditions: - There is a thead#1 running an "ANALYZE FORMAT=JSON" query for a "SELECT .. FROM INFORMATION_SCHEMA.COLUMNS WHERE .. " - The WHERE clause contains a stored function call, say f1(). - The WHERE clause is built in the way so that the function f1() is never actually called, e.g. WHERE .. AND (TRUE OR f1()=expr) - The database contains multiple VIEWs that have the function f1() call, e.g. in their