From 780d77109be6431bc51a7935144dbf605f9cfc87 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 29 Mar 2019 12:26:42 +0400 Subject: [PATCH] MDEV-17969 Assertion `name' failed in THD::push_warning_truncated_value_for_field --- mysql-test/main/type_temporal_innodb.result | 12 ++++++++++++ mysql-test/main/type_temporal_innodb.test | 15 +++++++++++++++ mysql-test/main/type_timestamp.result | 9 +++++++++ mysql-test/main/type_timestamp.test | 13 +++++++++++++ sql/field.cc | 15 ++++++++++++--- 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/type_temporal_innodb.result b/mysql-test/main/type_temporal_innodb.result index f8d8bc018bd..55b398b3b02 100644 --- a/mysql-test/main/type_temporal_innodb.result +++ b/mysql-test/main/type_temporal_innodb.result @@ -160,3 +160,15 @@ SELECT * FROM t1 WHERE LEAST( UTC_TIME(), d ); d 2012-12-21 DROP TABLE t1; +# +# MDEV-17969 Assertion `name' failed in THD::push_warning_truncated_value_for_field +# +CREATE TABLE t1 (c1 DATE , c2 TIMESTAMP) ENGINE=InnoDB; +INSERT INTO t1 VALUES ('2006-07-17','0000-00-00 00:00:00'); +CREATE TABLE t2 (pk INT, a1 TIME) Engine=InnoDB; +INSERT INTO t2 VALUES (6,'00:00:00'); +SET SESSION sql_mode= 'strict_all_tables,no_zero_date'; +CREATE TABLE tbl SELECT * FROM t1 WHERE t1.c1 = (SELECT c2 FROM t2 WHERE pk = 6); +ERROR 22007: Truncated incorrect datetime value: '0000-00-00 00:00:00' +DROP TABLE t1,t2; +SET sql_mode=DEFAULT; diff --git a/mysql-test/main/type_temporal_innodb.test b/mysql-test/main/type_temporal_innodb.test index 81f2f586c51..3debb798018 100644 --- a/mysql-test/main/type_temporal_innodb.test +++ b/mysql-test/main/type_temporal_innodb.test @@ -66,3 +66,18 @@ CREATE TABLE t1 (d DATE) ENGINE=InnoDB; INSERT INTO t1 VALUES ('2012-12-21'); SELECT * FROM t1 WHERE LEAST( UTC_TIME(), d ); DROP TABLE t1; + +--echo # +--echo # MDEV-17969 Assertion `name' failed in THD::push_warning_truncated_value_for_field +--echo # + +CREATE TABLE t1 (c1 DATE , c2 TIMESTAMP) ENGINE=InnoDB; +INSERT INTO t1 VALUES ('2006-07-17','0000-00-00 00:00:00'); +CREATE TABLE t2 (pk INT, a1 TIME) Engine=InnoDB; +INSERT INTO t2 VALUES (6,'00:00:00'); +SET SESSION sql_mode= 'strict_all_tables,no_zero_date'; +--error ER_TRUNCATED_WRONG_VALUE +CREATE TABLE tbl SELECT * FROM t1 WHERE t1.c1 = (SELECT c2 FROM t2 WHERE pk = 6); +# ^^^ there is no column c2 in table t2 +DROP TABLE t1,t2; +SET sql_mode=DEFAULT; diff --git a/mysql-test/main/type_timestamp.result b/mysql-test/main/type_timestamp.result index eda01d67ec7..019bfb6289f 100644 --- a/mysql-test/main/type_timestamp.result +++ b/mysql-test/main/type_timestamp.result @@ -1185,5 +1185,14 @@ c IN (GREATEST(a,b)) 0 DROP TABLE t1; # +# MDEV-17969 Assertion `name' failed in THD::push_warning_truncated_value_for_field +# +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('2018-01-01'),('2019-01-01'); +SET SESSION SQL_MODE= 'STRICT_ALL_TABLES,NO_ZERO_DATE'; +CREATE TABLE t2 SELECT 1 AS f FROM t1 GROUP BY FROM_DAYS(d); +ERROR 22007: Truncated incorrect date value: '0000-00-00' +DROP TABLE t1; +# # End of 10.4 tests # diff --git a/mysql-test/main/type_timestamp.test b/mysql-test/main/type_timestamp.test index 0ddc3047d2c..b76dd1b0c89 100644 --- a/mysql-test/main/type_timestamp.test +++ b/mysql-test/main/type_timestamp.test @@ -773,6 +773,19 @@ INSERT INTO t1 VALUES (0,0,0); SELECT c IN (GREATEST(a,b)) FROM t1; DROP TABLE t1; + +--echo # +--echo # MDEV-17969 Assertion `name' failed in THD::push_warning_truncated_value_for_field +--echo # + +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('2018-01-01'),('2019-01-01'); +SET SESSION SQL_MODE= 'STRICT_ALL_TABLES,NO_ZERO_DATE'; +--error ER_TRUNCATED_WRONG_VALUE +CREATE TABLE t2 SELECT 1 AS f FROM t1 GROUP BY FROM_DAYS(d); +DROP TABLE t1; + + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/field.cc b/sql/field.cc index 2fb763ddf0b..54063d7fcb5 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11010,9 +11010,18 @@ void Field::set_datetime_warning(Sql_condition::enum_warning_level level, { THD *thd= get_thd(); if (thd->really_abort_on_warning() && level >= Sql_condition::WARN_LEVEL_WARN) - thd->push_warning_truncated_value_for_field(level, typestr, - str->ptr(), table->s, - field_name.str); + { + /* + field_str.name can be NULL when field is not in the select list: + SET SESSION SQL_MODE= 'STRICT_ALL_TABLES,NO_ZERO_DATE'; + CREATE OR REPLACE TABLE t2 SELECT 1 AS f FROM t1 GROUP BY FROM_DAYS(d); + Can't call push_warning_truncated_value_for_field() directly here, + as it expect a non-NULL name. + */ + thd->push_warning_wrong_or_truncated_value(level, false, typestr, + str->ptr(), table->s, + field_name.str); + } else set_warning(level, code, cuted_increment); }