From 786940d7e03630d28d82bca4388c937c0d48594a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 26 Sep 2018 20:14:47 +0400 Subject: [PATCH] MDEV-17219 Assertion `!t->fraction_remainder(decimals())' failed in Field_time::store_TIME_with_warning --- mysql-test/main/type_time.result | 12 ++++++++++++ mysql-test/main/type_time.test | 11 +++++++++++ sql/field.cc | 3 ++- sql/sql_type.h | 9 +++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/type_time.result b/mysql-test/main/type_time.result index 6d26ee1fdaa..f16c958d9c1 100644 --- a/mysql-test/main/type_time.result +++ b/mysql-test/main/type_time.result @@ -2076,5 +2076,17 @@ d1 t1 d1 UPDATE (t1 JOIN t2 ON (t2.d1 = t1.t1)) SET t1.d1 = '2018-07-07' WHERE (t1.d1 > 70 ); DROP TABLE t1,t2; # +# MDEV-17219 Assertion `!t->fraction_remainder(decimals())' failed in Field_time::store_TIME_with_warning +# +SET optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (it TIME NOT NULL); +INSERT INTO t1 VALUES ('07:25:13'),('05:15:55'),('09:58:01'),('04:23:57'),('19:37:28'),('01:38:05'),('20:50:52'); +SELECT 1 FROM t1 WHERE it < -7487797330456870912; +1 +Warnings: +Warning 1292 Truncated incorrect time value: '-7487797330456870912' +DROP TABLE t1; +SET optimizer_use_condition_selectivity=DEFAULT; +# # End of 10.4 tests # diff --git a/mysql-test/main/type_time.test b/mysql-test/main/type_time.test index 6a3f6984583..b2e4c4ae7ae 100644 --- a/mysql-test/main/type_time.test +++ b/mysql-test/main/type_time.test @@ -1351,6 +1351,17 @@ SELECT * FROM (t1 JOIN t2 ON (t2.d1 = t1.t1)) WHERE (t1.d1 > 70 ); UPDATE (t1 JOIN t2 ON (t2.d1 = t1.t1)) SET t1.d1 = '2018-07-07' WHERE (t1.d1 > 70 ); DROP TABLE t1,t2; +--echo # +--echo # MDEV-17219 Assertion `!t->fraction_remainder(decimals())' failed in Field_time::store_TIME_with_warning +--echo # +SET optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (it TIME NOT NULL); +INSERT INTO t1 VALUES ('07:25:13'),('05:15:55'),('09:58:01'),('04:23:57'),('19:37:28'),('01:38:05'),('20:50:52'); +SELECT 1 FROM t1 WHERE it < -7487797330456870912; +DROP TABLE t1; +SET optimizer_use_condition_selectivity=DEFAULT; + + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/field.cc b/sql/field.cc index 878c23862a8..eb2dc2c8bd6 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5735,7 +5735,8 @@ int Field_time::store(longlong nr, bool unsigned_val) { ErrConvInteger str(nr, unsigned_val); int was_cut; - Time tm(&was_cut, nr, unsigned_val); + // Need fractional digit truncation if nr overflows to '838:59:59.999999' + Time tm(&was_cut, nr, unsigned_val, decimals()); return store_TIME_with_warning(&tm, &str, was_cut); } diff --git a/sql/sql_type.h b/sql/sql_type.h index c577da33be8..21704bf9ef0 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -800,6 +800,15 @@ public: { trunc(dec); } + Time(int *warn, longlong nr, bool unsigned_val, uint dec) + :Time(warn, nr, unsigned_val) + { + /* + Decimal digit truncation is needed here in case if nr was out + of the supported TIME range, so "this" was set to '838:59:59.999999'. + */ + trunc(dec); + } Time(int *warn, const my_decimal *d, uint dec) :Temporal(Time(warn, d)) {