From e34877ab63d127f6f8e536c82f5d65505e406a5e Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 1 Jul 2021 16:14:09 +0530 Subject: MDEV-25971 Instant ADD COLUMN fails to issue truncation warnings A table rebuild that would truncate the default value of a DATE column is expected to issue data truncation warnings. But, these warnings are not being issued if the ADD COLUMN is being executed with ALGORITHM=INSTANT. InnoDB sets the warning of the field while assigning the default value of the field during check_if_supported_inplace_alter(). --- mysql-test/suite/innodb/r/innodb-alter.result | 17 +++++++++-------- mysql-test/suite/innodb/r/instant_alter.result | 24 ++++++++++++++++++------ mysql-test/suite/innodb/t/innodb-alter.test | 7 ++----- sql/sql_table.cc | 9 ++++++--- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-alter.result b/mysql-test/suite/innodb/r/innodb-alter.result index cce8a060b0e..749e242fce8 100644 --- a/mysql-test/suite/innodb/r/innodb-alter.result +++ b/mysql-test/suite/innodb/r/innodb-alter.result @@ -1049,13 +1049,12 @@ a 10 DROP TABLE t1; CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB; -SET @save_allowed = @@GLOBAL.innodb_instant_alter_column_allowed; -SET GLOBAL innodb_instant_alter_column_allowed=never; -iNSERT INTO t1 VALUES (10); -ALTER TABLE t1 ADD b DATE NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0); -affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 -SET GLOBAL innodb_instant_alter_column_allowed=@save_allowed; +INSERT INTO t1 VALUES (10); +ALTER TABLE t1 ADD b DATE NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0), algorithm=copy; +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'b' at row 1 SELECT * FROM t1; a b 10 2001-01-01 @@ -1064,7 +1063,9 @@ CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB; iNSERT INTO t1 VALUES (10); ALTER TABLE t1 ADD b TIME NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'b' at row 1 SELECT * FROM t1; a b 10 10:20:30 diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index 1a818531756..5d76d648345 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -308,10 +308,14 @@ id c2 c3 c4 c5 c6 affected rows: 3 ALTER TABLE t3 ADD COLUMN c7 TIME NOT NULL DEFAULT current_timestamp(); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'c7' at row 1 ALTER TABLE t3 ADD COLUMN c8 DATE NOT NULL DEFAULT current_timestamp(); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'c8' at row 1 SELECT id, c2, ST_AsText(c3) c3, c4, c5, c6, c7, c8 FROM t3; id c2 c3 c4 c5 c6 c7 c8 1 1 POLYGON((1 1,2 2,3 3,1 1)) 1970-01-01 03:00:42 1970-01-01 03:00:42 NULL 03:00:42 1970-01-01 @@ -788,10 +792,14 @@ id c2 c3 c4 c5 c6 affected rows: 3 ALTER TABLE t3 ADD COLUMN c7 TIME NOT NULL DEFAULT current_timestamp(); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'c7' at row 1 ALTER TABLE t3 ADD COLUMN c8 DATE NOT NULL DEFAULT current_timestamp(); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'c8' at row 1 SELECT id, c2, ST_AsText(c3) c3, c4, c5, c6, c7, c8 FROM t3; id c2 c3 c4 c5 c6 c7 c8 1 1 POLYGON((1 1,2 2,3 3,1 1)) 1970-01-01 03:00:42 1970-01-01 03:00:42 NULL 03:00:42 1970-01-01 @@ -1268,10 +1276,14 @@ id c2 c3 c4 c5 c6 affected rows: 3 ALTER TABLE t3 ADD COLUMN c7 TIME NOT NULL DEFAULT current_timestamp(); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'c7' at row 1 ALTER TABLE t3 ADD COLUMN c8 DATE NOT NULL DEFAULT current_timestamp(); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1265 Data truncated for column 'c8' at row 1 SELECT id, c2, ST_AsText(c3) c3, c4, c5, c6, c7, c8 FROM t3; id c2 c3 c4 c5 c6 c7 c8 1 1 POLYGON((1 1,2 2,3 3,1 1)) 1970-01-01 03:00:42 1970-01-01 03:00:42 NULL 03:00:42 1970-01-01 diff --git a/mysql-test/suite/innodb/t/innodb-alter.test b/mysql-test/suite/innodb/t/innodb-alter.test index e0ee5a04ac4..d1adc4c91c0 100644 --- a/mysql-test/suite/innodb/t/innodb-alter.test +++ b/mysql-test/suite/innodb/t/innodb-alter.test @@ -652,13 +652,10 @@ DROP TABLE t1; # DATETIME-to-DATE truncation is OK CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB; -SET @save_allowed = @@GLOBAL.innodb_instant_alter_column_allowed; -SET GLOBAL innodb_instant_alter_column_allowed=never; -iNSERT INTO t1 VALUES (10); +INSERT INTO t1 VALUES (10); --enable_info -ALTER TABLE t1 ADD b DATE NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0); +ALTER TABLE t1 ADD b DATE NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0), algorithm=copy; --disable_info -SET GLOBAL innodb_instant_alter_column_allowed=@save_allowed; SELECT * FROM t1; DROP TABLE t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c70639d71db..9aae74a613d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10015,9 +10015,12 @@ do_continue:; if (alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_NONE) ha_alter_info.online= true; // Ask storage engine whether to use copy or in-place - ha_alter_info.inplace_supported= - table->file->check_if_supported_inplace_alter(altered_table, - &ha_alter_info); + { + Check_level_instant_set check_level_save(thd, CHECK_FIELD_WARN); + ha_alter_info.inplace_supported= + table->file->check_if_supported_inplace_alter(altered_table, + &ha_alter_info); + } if (alter_info->supports_algorithm(thd, &ha_alter_info) || alter_info->supports_lock(thd, &ha_alter_info)) -- cgit v1.2.1