From 6d29c8527b4215cb516f709013cc6dfc6475da7d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 12 Oct 2018 11:44:19 -0700 Subject: [PATCH 1/7] MDEV-17354 Server crashes in add_key_field / .. / Item_func_null_predicate::add_key_fields upon INSERT .. SELECT The function Item *Item_direct_view_ref::derived_field_transformer_for_where() erroneously did not strip off ref wrappers from references to materialized derived tables / views. As a result the expressions that contained some references of the type Item_direct_view_ref to columns of a materialized derived table / view V were pushed into V incorrectly. This could cause crashes for some INSERT ... SELECT statements. --- mysql-test/r/derived_cond_pushdown.result | 146 ++++++++++++++++++++++ mysql-test/t/derived_cond_pushdown.test | 33 +++++ sql/item.cc | 2 +- 3 files changed, 180 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/derived_cond_pushdown.result b/mysql-test/r/derived_cond_pushdown.result index 9ef3488e06d..9d9d1e7613c 100644 --- a/mysql-test/r/derived_cond_pushdown.result +++ b/mysql-test/r/derived_cond_pushdown.result @@ -10241,3 +10241,149 @@ a b c 1 2 2 3 2 2 DROP TABLE t1; +# +# MDEV-17354: INSERT SELECT with condition pushdown into derived +# +CREATE TABLE t1 (f INT NOT NULL); +INSERT INTO t1 VALUES (3), (7), (3); +CREATE ALGORITHM= TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq; +INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL; +EXPLAIN INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 144 Using where +2 DERIVED ALL NULL NULL NULL NULL 12 +2 DERIVED t1 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) +3 DERIVED t1 ALL NULL NULL NULL NULL 12 +EXPLAIN FORMAT=JSON INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 144, + "filtered": 100, + "attached_condition": "t.f is not null", + "materialized": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "materialized": { + "query_block": { + "select_id": 3, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 12, + "filtered": 100 + } + } + } + }, + "block-nl-join": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t1.f is not null" + }, + "buffer_type": "flat", + "buffer_size": "256Kb", + "join_type": "BNL" + } + } + } + } + } +} +SELECT * FROM t1; +f +3 +7 +3 +3 +3 +3 +7 +7 +7 +3 +3 +3 +DELETE FROM t1; +INSERT INTO t1 VALUES (3), (7), (3); +INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t +WHERE f IS NOT NULL; +EXPLAIN FORMAT=JSON INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t +WHERE f IS NOT NULL; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 16, + "filtered": 100, + "attached_condition": "t.f is not null", + "materialized": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 8, + "filtered": 100, + "attached_condition": "t1.f is not null" + }, + "table": { + "table_name": "", + "access_type": "ref", + "possible_keys": ["key0"], + "key": "key0", + "key_length": "4", + "used_key_parts": ["f"], + "ref": ["test.t1.f"], + "rows": 2, + "filtered": 100, + "materialized": { + "query_block": { + "select_id": 3, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 8, + "filtered": 100, + "attached_condition": "t1.f is not null" + } + } + } + } + } + } + } + } +} +SELECT * FROM t1; +f +3 +7 +3 +3 +3 +7 +3 +3 +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test index 23109662c6d..476a3d795b9 100644 --- a/mysql-test/t/derived_cond_pushdown.test +++ b/mysql-test/t/derived_cond_pushdown.test @@ -2042,3 +2042,36 @@ SELECT * FROM WHERE ((a,b) IN ((1,2),(3,2))); DROP TABLE t1; + +--echo # +--echo # MDEV-17354: INSERT SELECT with condition pushdown into derived +--echo # + +CREATE TABLE t1 (f INT NOT NULL); +INSERT INTO t1 VALUES (3), (7), (3); + +CREATE ALGORITHM= TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq; + +let $q1= +INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL; + +eval $q1; +eval EXPLAIN $q1; +eval EXPLAIN FORMAT=JSON $q1; +SELECT * FROM t1; + +DELETE FROM t1; +INSERT INTO t1 VALUES (3), (7), (3); + +let $q2= +INSERT INTO t1 +SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t + WHERE f IS NOT NULL; + +eval $q2; +eval EXPLAIN FORMAT=JSON $q2; +SELECT * FROM t1; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/item.cc b/sql/item.cc index 35de01b1186..2adec33491b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7214,7 +7214,7 @@ Item *Item_direct_view_ref::derived_field_transformer_for_where(THD *thd, DBUG_ASSERT (producing_item != NULL); return producing_item->build_clone(thd, thd->mem_root); } - return this; + return (*ref); } static From b715a0fe451425a2cc1c0be587a68c1512b4725a Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Sat, 13 Oct 2018 19:14:31 +0300 Subject: [PATCH 2/7] Disabled storage_engine test for RocksDB due to unstable execution plan The failure caused by MDEV-16387 --- storage/rocksdb/mysql-test/storage_engine/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/rocksdb/mysql-test/storage_engine/disabled.def b/storage/rocksdb/mysql-test/storage_engine/disabled.def index 930e1d82b87..7ed4fac6645 100644 --- a/storage/rocksdb/mysql-test/storage_engine/disabled.def +++ b/storage/rocksdb/mysql-test/storage_engine/disabled.def @@ -18,6 +18,7 @@ show_engine : SHOW ENGINE produces different number of lines depending show_table_status : MDEV-13152 - Indeterministic row number in SHOW TABLE STATUS on RocksDB table tbl_opt_data_dir : Not supported tbl_opt_index_dir : Not supported +type_binary_indexes : MDEV-16387 - Wrong execution plan type_spatial : Not supported type_spatial_indexes : Not supported update_low_prio : Not supported From af6077b5358198384eb873ce26f88e7a7ecfe106 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Sun, 14 Oct 2018 10:44:00 -0700 Subject: [PATCH 3/7] MDEV-16990:server crashes in base_list_iterator::next When we have a query which has implicit_grouping then we are sure that we would end up with only one row so there is no point to do DISTINCT computation --- mysql-test/r/win.result | 12 ++++++++++++ mysql-test/t/win.test | 10 ++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index e4b2d223a02..aef9b613433 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3314,3 +3314,15 @@ COUNT(DISTINCT t2.a2) rank() OVER (ORDER BY t2.b1) 1 2 1 3 DROP TABLE t1,t2; +# +# MDEV-16990: server crashes in base_list_iterator::next +# +CREATE TABLE t1(i int); +insert into t1 values (1),(2); +SELECT DISTINCT row_number() OVER (), MAX(1) FROM t1; +row_number() OVER () MAX(1) +1 1 +SELECT DISTINCT BIT_AND(0) OVER (), MAX(1) FROM t1; +BIT_AND(0) OVER () MAX(1) +0 1 +drop table t1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index f47237ee59e..1617e85caf4 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2082,3 +2082,13 @@ SELECT COUNT(DISTINCT t2.a2), rank() OVER (ORDER BY t2.b1) FROM t2 ,t1 GROUP BY t2.b1 ORDER BY t1.a1; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-16990: server crashes in base_list_iterator::next +--echo # + +CREATE TABLE t1(i int); +insert into t1 values (1),(2); +SELECT DISTINCT row_number() OVER (), MAX(1) FROM t1; +SELECT DISTINCT BIT_AND(0) OVER (), MAX(1) FROM t1; +drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6f98bab32d3..a9adbd168a6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2731,7 +2731,7 @@ bool JOIN::make_aggr_tables_info() remove_duplicates() assumes there is a preceding computation step (and in the degenerate join, there's none) */ - if (top_join_tab_count) + if (top_join_tab_count && tables_list) curr_tab->distinct= true; having= NULL; From 2d4075e1d9dba3dd8503d65fdb145a6dcc056c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 16 Oct 2018 10:42:30 +0300 Subject: [PATCH 4/7] MDEV-17466 Virtual column value not available during purge row_build_index_entry_low(): Assert that when the value of a virtual column is not available, this can only happen when the index creation was completed but not committed yet. This change is not fixing any bug, making a debug assertion stricter, so that bugs can be caught in the future. Ultimately, we should change the InnoDB undo log format so that all actual secondary index keys are stored there, also for virtual or spatial indexes. In that way, purge and rollback would be more straightforward. --- storage/innobase/row/row0row.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/innobase/row/row0row.cc b/storage/innobase/row/row0row.cc index ad4991fb4e9..3f4308d4bed 100644 --- a/storage/innobase/row/row0row.cc +++ b/storage/innobase/row/row0row.cc @@ -127,6 +127,8 @@ row_build_index_entry_low( ut_ad(dfield_is_null(dfield2) || dfield_get_len(dfield2) == 0 || dfield2->data); + ut_ad(dfield2->type.mtype != DATA_MISSING + || !index->is_committed()); } else { dfield2 = dtuple_get_nth_field(row, col_no); ut_ad(dfield_get_type(dfield2)->mtype == DATA_MISSING From 2308b9afec559cd8c5717007a7ad6821c374370d Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Wed, 3 Oct 2018 21:45:05 +0300 Subject: [PATCH 5/7] MDEV-17098 DATE -> DATETIME replication conversion not working, even in ALL_NON_LOSSY mode Opened up MYSQL_TYPE _DATETIME{,2} <-> _NEWDATE conversions for replication. --- mysql-test/extra/rpl_tests/check_type.inc | 8 ++ .../extra/rpl_tests/type_conversions.test | 91 +++++++++++++++++++ .../binlog_encryption/rpl_typeconv.result | 44 +++++++++ mysql-test/suite/rpl/r/rpl_typeconv.result | 44 +++++++++ sql/rpl_utility.cc | 34 ++++++- 5 files changed, 219 insertions(+), 2 deletions(-) diff --git a/mysql-test/extra/rpl_tests/check_type.inc b/mysql-test/extra/rpl_tests/check_type.inc index 97300753d38..baba7a21e86 100644 --- a/mysql-test/extra/rpl_tests/check_type.inc +++ b/mysql-test/extra/rpl_tests/check_type.inc @@ -24,11 +24,19 @@ connection master; disable_warnings; DROP TABLE IF EXISTS t1; enable_warnings; +if ($source_temp_format) +{ + --eval SET @@global.mysql56_temporal_format= $source_temp_format +} eval CREATE TABLE t1( pk INT NOT NULL PRIMARY KEY, a $source_type ) ENGINE=$engine_type; sync_slave_with_master; +if ($target_temp_format) +{ + --eval SET @@global.mysql56_temporal_format= $source_temp_format +} eval ALTER TABLE t1 MODIFY a $target_type; connection master; diff --git a/mysql-test/extra/rpl_tests/type_conversions.test b/mysql-test/extra/rpl_tests/type_conversions.test index b013d471f01..511d59e3633 100644 --- a/mysql-test/extra/rpl_tests/type_conversions.test +++ b/mysql-test/extra/rpl_tests/type_conversions.test @@ -1007,5 +1007,96 @@ source extra/rpl_tests/check_type.inc; --echo # End of MDEV-15833 +--echo # +--echo # MDEV-17098 DATE <-> DATETIME +--echo # + +# NON-LOSSY +let $source_temp_format= 1; # irrelevant with DATE though +let $source_type= DATE; +let $target_temp_format= 1; # to produce MYSQL_TYPE_DATETIME2 +let $target_type= DATETIME(6); +let $source_value= '2018-10-11'; +let $target_value= '2018-10-11 00:00:00.000000'; +let $can_convert = $if_is_non_lossy; +source extra/rpl_tests/check_type.inc; + +let $source_temp_format= 1; +let $source_type= DATE; +let $target_temp_format= 0; # to produce "old" MYSQL_TYPE_DATETIME +let $target_type= DATETIME(6); +let $source_value= '2018-10-11'; +let $target_value= '2018-10-11 00:00:00.000000'; +let $can_convert = $if_is_non_lossy; +source extra/rpl_tests/check_type.inc; + +let $source_temp_format= 0; +let $source_type= DATE; +let $target_temp_format= 1; +let $target_type= DATETIME(6); +let $source_value= '2018-10-11'; +let $target_value= '2018-10-11 00:00:00.000000'; +let $can_convert = $if_is_non_lossy; +source extra/rpl_tests/check_type.inc; + +# zero-precision test version +let $source_temp_format= 1; +let $source_type= DATE; +let $target_temp_format= 1; +let $target_type= DATETIME(0); +let $source_value= '2018-10-11'; +let $target_value= '2018-10-11 00:00:00'; +let $can_convert = $if_is_non_lossy; +source extra/rpl_tests/check_type.inc; + +# LOSSY +let $source_temp_format= 1; +let $source_type= DATETIME(6); +let $target_temp_format= 1; +let $target_type= DATE; +let $source_value= '2018-10-11 00:00:00.000001'; +let $target_value= '2018-10-11'; +let $can_convert = $if_is_lossy; +source extra/rpl_tests/check_type.inc; + +let $source_temp_format= 1; +let $source_type= DATETIME(6); +let $target_temp_format= 0; +let $target_type= DATE; +let $source_value= '2018-10-11 00:00:00.000001'; +let $target_value= '2018-10-11'; +let $can_convert = $if_is_lossy; +source extra/rpl_tests/check_type.inc; + +# zero-precision test version +let $source_temp_format= 1; +let $source_type= DATETIME(0); +let $target_temp_format= 1; +let $target_type= DATE; +let $source_value= '2018-10-11 00:00:00'; +let $target_value= '2018-10-11'; +let $can_convert = $if_is_lossy; +source extra/rpl_tests/check_type.inc; + +# TODO: fix MDEV-17394 Row-based replication DATETIME(m) to +# DATETIME(s) does not work or incorrect +# +# +# let $source_temp_format= 0; +# let $source_type= DATETIME(6); +# let $target_temp_format= 1; +# let $target_type= DATE; +# ... +# let $source_temp_format= 0; +# let $source_type= DATETIME(6); +# let $target_temp_format= 0; +# let $target_type= DATE; +# ... + +let $source_temp_format=; +let $target_temp_format=; +--echo # End of MDEV-17098 + + --source include/rpl_reset.inc enable_query_log; diff --git a/mysql-test/suite/binlog_encryption/rpl_typeconv.result b/mysql-test/suite/binlog_encryption/rpl_typeconv.result index e9ffdd2b7b1..e65dede28e0 100644 --- a/mysql-test/suite/binlog_encryption/rpl_typeconv.result +++ b/mysql-test/suite/binlog_encryption/rpl_typeconv.result @@ -43,6 +43,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS=''; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; @@ -51,6 +55,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; @@ -59,6 +67,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; @@ -67,6 +79,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; **** Result of conversions **** @@ -208,6 +224,13 @@ LONGBLOB TINYBLOB LONGBLOB BLOB LONGBLOB MEDIUMBLOB LONGBLOB VARBINARY(65500 +DATE DATETIME(6) +DATE DATETIME(6) +DATE DATETIME(6) +DATE DATETIME(0) +DATETIME(6) DATE +DATETIME(6) DATE +DATETIME(0) DATE TINYBLOB TINYBLOB ALL_NON_LOSSY TINYBLOB BLOB ALL_NON_LOSSY TINYBLOB MEDIUMBLOB ALL_NON_LOSSY @@ -345,6 +368,13 @@ LONGBLOB TINYBLOB ALL_NON_LOSSY LONGBLOB BLOB ALL_NON_LOSSY LONGBLOB MEDIUMBLOB ALL_NON_LOSSY LONGBLOB VARBINARY(65500 ALL_NON_LOSSY +DATE DATETIME(6) ALL_NON_LOSSY +DATE DATETIME(6) ALL_NON_LOSSY +DATE DATETIME(6) ALL_NON_LOSSY +DATE DATETIME(0) ALL_NON_LOSSY +DATETIME(6) DATE ALL_NON_LOSSY +DATETIME(6) DATE ALL_NON_LOSSY +DATETIME(0) DATE ALL_NON_LOSSY TINYBLOB TINYBLOB ALL_LOSSY TINYBLOB BLOB ALL_LOSSY TINYBLOB MEDIUMBLOB ALL_LOSSY @@ -482,6 +512,13 @@ LONGBLOB TINYBLOB ALL_LOSSY LONGBLOB BLOB ALL_LOSSY LONGBLOB MEDIUMBLOB ALL_LOSSY LONGBLOB VARBINARY(65500 ALL_LOSSY +DATE DATETIME(6) ALL_LOSSY +DATE DATETIME(6) ALL_LOSSY +DATE DATETIME(6) ALL_LOSSY +DATE DATETIME(0) ALL_LOSSY +DATETIME(6) DATE ALL_LOSSY +DATETIME(6) DATE ALL_LOSSY +DATETIME(0) DATE ALL_LOSSY TINYBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY TINYBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY TINYBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY @@ -619,6 +656,13 @@ LONGBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY LONGBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY LONGBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY LONGBLOB VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(0) ALL_LOSSY,ALL_NON_LOSSY +DATETIME(6) DATE ALL_LOSSY,ALL_NON_LOSSY +DATETIME(6) DATE ALL_LOSSY,ALL_NON_LOSSY +DATETIME(0) DATE ALL_LOSSY,ALL_NON_LOSSY DROP TABLE type_conversions; call mtr.add_suppression("Slave SQL.*Column 1 of table .test.t1. cannot be converted from type.* error.* 1677"); connection master; diff --git a/mysql-test/suite/rpl/r/rpl_typeconv.result b/mysql-test/suite/rpl/r/rpl_typeconv.result index e9ffdd2b7b1..e65dede28e0 100644 --- a/mysql-test/suite/rpl/r/rpl_typeconv.result +++ b/mysql-test/suite/rpl/r/rpl_typeconv.result @@ -43,6 +43,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS=''; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; @@ -51,6 +55,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; @@ -59,6 +67,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; @@ -67,6 +79,10 @@ SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; # MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values # # End of MDEV-15833 +# +# MDEV-17098 DATE <-> DATETIME +# +# End of MDEV-17098 include/rpl_reset.inc connection slave; **** Result of conversions **** @@ -208,6 +224,13 @@ LONGBLOB TINYBLOB LONGBLOB BLOB LONGBLOB MEDIUMBLOB LONGBLOB VARBINARY(65500 +DATE DATETIME(6) +DATE DATETIME(6) +DATE DATETIME(6) +DATE DATETIME(0) +DATETIME(6) DATE +DATETIME(6) DATE +DATETIME(0) DATE TINYBLOB TINYBLOB ALL_NON_LOSSY TINYBLOB BLOB ALL_NON_LOSSY TINYBLOB MEDIUMBLOB ALL_NON_LOSSY @@ -345,6 +368,13 @@ LONGBLOB TINYBLOB ALL_NON_LOSSY LONGBLOB BLOB ALL_NON_LOSSY LONGBLOB MEDIUMBLOB ALL_NON_LOSSY LONGBLOB VARBINARY(65500 ALL_NON_LOSSY +DATE DATETIME(6) ALL_NON_LOSSY +DATE DATETIME(6) ALL_NON_LOSSY +DATE DATETIME(6) ALL_NON_LOSSY +DATE DATETIME(0) ALL_NON_LOSSY +DATETIME(6) DATE ALL_NON_LOSSY +DATETIME(6) DATE ALL_NON_LOSSY +DATETIME(0) DATE ALL_NON_LOSSY TINYBLOB TINYBLOB ALL_LOSSY TINYBLOB BLOB ALL_LOSSY TINYBLOB MEDIUMBLOB ALL_LOSSY @@ -482,6 +512,13 @@ LONGBLOB TINYBLOB ALL_LOSSY LONGBLOB BLOB ALL_LOSSY LONGBLOB MEDIUMBLOB ALL_LOSSY LONGBLOB VARBINARY(65500 ALL_LOSSY +DATE DATETIME(6) ALL_LOSSY +DATE DATETIME(6) ALL_LOSSY +DATE DATETIME(6) ALL_LOSSY +DATE DATETIME(0) ALL_LOSSY +DATETIME(6) DATE ALL_LOSSY +DATETIME(6) DATE ALL_LOSSY +DATETIME(0) DATE ALL_LOSSY TINYBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY TINYBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY TINYBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY @@ -619,6 +656,13 @@ LONGBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY LONGBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY LONGBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY LONGBLOB VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY +DATE DATETIME(0) ALL_LOSSY,ALL_NON_LOSSY +DATETIME(6) DATE ALL_LOSSY,ALL_NON_LOSSY +DATETIME(6) DATE ALL_LOSSY,ALL_NON_LOSSY +DATETIME(0) DATE ALL_LOSSY,ALL_NON_LOSSY DROP TABLE type_conversions; call mtr.add_suppression("Slave SQL.*Column 1 of table .test.t1. cannot be converted from type.* error.* 1677"); connection master; diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index bdf5b7dea80..9554daeedbd 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -765,14 +765,44 @@ can_convert_field_to(Field *field, case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_YEAR: - case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_NULL: case MYSQL_TYPE_ENUM: case MYSQL_TYPE_SET: case MYSQL_TYPE_TIMESTAMP2: - case MYSQL_TYPE_DATETIME2: case MYSQL_TYPE_TIME2: DBUG_RETURN(false); + case MYSQL_TYPE_NEWDATE: + { + if (field->real_type() == MYSQL_TYPE_DATETIME2 || + field->real_type() == MYSQL_TYPE_DATETIME) + { + *order_var= -1; + DBUG_RETURN(is_conversion_ok(*order_var, rli)); + } + else + { + DBUG_RETURN(false); + } + } + break; + + //case MYSQL_TYPE_DATETIME: TODO: fix MDEV-17394 and uncomment. + // + //The "old" type does not specify the fraction part size which is required + //for correct conversion. + case MYSQL_TYPE_DATETIME2: + { + if (field->real_type() == MYSQL_TYPE_NEWDATE) + { + *order_var= 1; + DBUG_RETURN(is_conversion_ok(*order_var, rli)); + } + else + { + DBUG_RETURN(false); + } + } + break; } DBUG_RETURN(false); // To keep GCC happy } From dc3f55947e1e849d73bede588d24839e58cb6547 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 17 Oct 2018 03:26:30 -0700 Subject: [PATCH 6/7] MDEV-17107 Assertion `table_list->table' failed in find_field_in_table_ref Added only test case because the bug was fixed by the patch for mdev-16992. --- mysql-test/r/cte_nonrecursive.result | 18 ++++++++++++++++++ mysql-test/t/cte_nonrecursive.test | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result index 2b9455d10f2..fc654588072 100644 --- a/mysql-test/r/cte_nonrecursive.result +++ b/mysql-test/r/cte_nonrecursive.result @@ -1641,3 +1641,21 @@ a b drop procedure p1; drop procedure p2; drop table t1; +# +# MDEV-17107: PS for CREATE OR REPLACE VIEW defined by SELECT with CTEs +# +create table t1(a int); +insert into t1 values (3), (1), (2); +create table t2 (b int); +insert into t2 values (2), (10); +prepare stmt from +"create or replace view v1 as + with t as (select s.a from (select t1.a from t1) s), + r as(select t.a from t2, t where t2.b=t.a) + select a from r;"; +execute stmt; +select * from v1; +a +2 +drop view v1; +drop table t1,t2; diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test index 648fc89975c..920c27a70f9 100644 --- a/mysql-test/t/cte_nonrecursive.test +++ b/mysql-test/t/cte_nonrecursive.test @@ -1147,3 +1147,24 @@ select * from t1; drop procedure p1; drop procedure p2; drop table t1; + +--echo # +--echo # MDEV-17107: PS for CREATE OR REPLACE VIEW defined by SELECT with CTEs +--echo # + +create table t1(a int); +insert into t1 values (3), (1), (2); +create table t2 (b int); +insert into t2 values (2), (10); + +prepare stmt from +"create or replace view v1 as + with t as (select s.a from (select t1.a from t1) s), + r as(select t.a from t2, t where t2.b=t.a) + select a from r;"; + +execute stmt; +select * from v1; + +drop view v1; +drop table t1,t2; From 853a0a4368ec5268aac2e53e862ce4ad975ffd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 17 Oct 2018 09:54:18 +0300 Subject: [PATCH 7/7] MDEV-13564: Set innodb_safe_truncate=ON by default The setting innodb_safe_truncate=ON reduces compatibility with older versions of MariaDB and backup tools in two ways. First, we will be writing TRX_UNDO_RENAME_TABLE records, which older versions do not know about. These records could be misinterpreted if a DDL transaction was recovered and would be rolled back. Such rollback is only possible if the server was killed while an incomplete DDL transaction was persisted. On transaction completion, the insert_undo log pages would only be repurposed for new undo log allocations, and their contents would not matter. So, older versions will not have a problem with innodb_safe_truncate=ON if the server was shut down cleanly. Second, to prevent such recovery failure, innodb_safe_truncate=ON will cause a modification of the redo log format identifier, which will prevent older versions from starting up after a crash. MariaDB Server versions older than 10.2.13 will refuse to start up altogether, even after clean shutdown. A server restart with innodb_safe_truncate=OFF will restore compatibility with older server and backup versions. --- mysql-test/suite/innodb/t/truncate_debug.opt | 1 + mysql-test/suite/innodb/t/truncate_inject.opt | 1 + mysql-test/suite/innodb/t/truncate_purge_debug.opt | 1 + mysql-test/suite/innodb/t/truncate_restart.opt | 1 + mysql-test/suite/innodb_zip/t/wl6501_1.opt | 1 + mysql-test/suite/innodb_zip/t/wl6501_crash_3.opt | 1 + mysql-test/suite/innodb_zip/t/wl6501_crash_4.opt | 1 + mysql-test/suite/innodb_zip/t/wl6501_crash_5.opt | 1 + mysql-test/suite/innodb_zip/t/wl6501_scale_1.opt | 1 + mysql-test/suite/sys_vars/r/sysvars_innodb.result | 6 +++--- storage/innobase/handler/ha_innodb.cc | 4 ++-- 11 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 mysql-test/suite/innodb/t/truncate_debug.opt create mode 100644 mysql-test/suite/innodb/t/truncate_inject.opt create mode 100644 mysql-test/suite/innodb/t/truncate_restart.opt create mode 100644 mysql-test/suite/innodb_zip/t/wl6501_1.opt create mode 100644 mysql-test/suite/innodb_zip/t/wl6501_crash_3.opt create mode 100644 mysql-test/suite/innodb_zip/t/wl6501_crash_4.opt create mode 100644 mysql-test/suite/innodb_zip/t/wl6501_crash_5.opt create mode 100644 mysql-test/suite/innodb_zip/t/wl6501_scale_1.opt diff --git a/mysql-test/suite/innodb/t/truncate_debug.opt b/mysql-test/suite/innodb/t/truncate_debug.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb/t/truncate_debug.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb/t/truncate_inject.opt b/mysql-test/suite/innodb/t/truncate_inject.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb/t/truncate_inject.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb/t/truncate_purge_debug.opt b/mysql-test/suite/innodb/t/truncate_purge_debug.opt index 8bed7e46166..4cb238c6e53 100644 --- a/mysql-test/suite/innodb/t/truncate_purge_debug.opt +++ b/mysql-test/suite/innodb/t/truncate_purge_debug.opt @@ -1,3 +1,4 @@ --innodb-purge-threads=1 --innodb-purge-batch-size=1 --innodb-stats-persistent=OFF +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb/t/truncate_restart.opt b/mysql-test/suite/innodb/t/truncate_restart.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb/t/truncate_restart.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb_zip/t/wl6501_1.opt b/mysql-test/suite/innodb_zip/t/wl6501_1.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb_zip/t/wl6501_1.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb_zip/t/wl6501_crash_3.opt b/mysql-test/suite/innodb_zip/t/wl6501_crash_3.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb_zip/t/wl6501_crash_3.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb_zip/t/wl6501_crash_4.opt b/mysql-test/suite/innodb_zip/t/wl6501_crash_4.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb_zip/t/wl6501_crash_4.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb_zip/t/wl6501_crash_5.opt b/mysql-test/suite/innodb_zip/t/wl6501_crash_5.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb_zip/t/wl6501_crash_5.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/innodb_zip/t/wl6501_scale_1.opt b/mysql-test/suite/innodb_zip/t/wl6501_scale_1.opt new file mode 100644 index 00000000000..658bd901f47 --- /dev/null +++ b/mysql-test/suite/innodb_zip/t/wl6501_scale_1.opt @@ -0,0 +1 @@ +--innodb-safe-truncate=0 diff --git a/mysql-test/suite/sys_vars/r/sysvars_innodb.result b/mysql-test/suite/sys_vars/r/sysvars_innodb.result index a2b82df3dbc..995f21dccf4 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_innodb.result +++ b/mysql-test/suite/sys_vars/r/sysvars_innodb.result @@ -2402,12 +2402,12 @@ READ_ONLY NO COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME INNODB_SAFE_TRUNCATE SESSION_VALUE NULL -GLOBAL_VALUE OFF +GLOBAL_VALUE ON GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE OFF +DEFAULT_VALUE ON VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BOOLEAN -VARIABLE_COMMENT Use backup-safe TRUNCATE TABLE and crash-safe RENAME (incompatible with older MariaDB 10.2; OFF by default) +VARIABLE_COMMENT Use backup-safe TRUNCATE TABLE and crash-safe RENAME (incompatible with older MariaDB 10.2; ON by default) NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index e7ec8488d45..84253d88983 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -20696,8 +20696,8 @@ static MYSQL_SYSVAR_BOOL(read_only, srv_read_only_mode, static MYSQL_SYSVAR_BOOL(safe_truncate, srv_safe_truncate, PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, - "Use backup-safe TRUNCATE TABLE and crash-safe RENAME (incompatible with older MariaDB 10.2; OFF by default)", - NULL, NULL, FALSE); + "Use backup-safe TRUNCATE TABLE and crash-safe RENAME (incompatible with older MariaDB 10.2; ON by default)", + NULL, NULL, TRUE); static MYSQL_SYSVAR_BOOL(cmp_per_index_enabled, srv_cmp_per_index_enabled, PLUGIN_VAR_OPCMDARG,