From 7b33a6a1ea80dc628e6614368449e6b2bcb267f2 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 13 Mar 2019 09:31:35 +0400 Subject: [PATCH] MDEV-18876 Assertion `is_valid_time_slow()' failed in Time::valid_MYSQL_TIME_to_valid_value --- mysql-test/include/type_hrtime.inc | 6 ++++++ mysql-test/main/type_time.result | 24 +++++++++++++++++++++++- mysql-test/main/type_time.test | 17 +++++++++++++++++ mysql-test/main/type_time_hires.result | 7 +++++++ sql/item.cc | 14 ++++++++++++++ sql/item.h | 7 +------ 6 files changed, 68 insertions(+), 7 deletions(-) diff --git a/mysql-test/include/type_hrtime.inc b/mysql-test/include/type_hrtime.inc index 55fd3d665fe..d666dc63bba 100644 --- a/mysql-test/include/type_hrtime.inc +++ b/mysql-test/include/type_hrtime.inc @@ -55,6 +55,12 @@ select * from t1; delete from t1 where a < 20110101; select * from t1; +if ($type == time) +{ +delete from t1 where a is not null; +select * from t1; +} + # # create ... select # diff --git a/mysql-test/main/type_time.result b/mysql-test/main/type_time.result index a448c5fb702..673bed990a1 100644 --- a/mysql-test/main/type_time.result +++ b/mysql-test/main/type_time.result @@ -188,7 +188,7 @@ create table t1(f1 time); insert into t1 values ('23:38:57'); select f1, f1 = '2010-10-11 23:38:57' from t1; f1 f1 = '2010-10-11 23:38:57' -23:38:57 0 +23:38:57 1 drop table t1; # # MDEV-4634 Crash in CONVERT_TZ @@ -2186,5 +2186,27 @@ Warnings: Warning 1264 Out of range value for column 't' at row 1 DROP TABLE t1; # +# MDEV-18876 Assertion `is_valid_time_slow()' failed in Time::valid_MYSQL_TIME_to_valid_value +# +CREATE TABLE t1 (f INT); +INSERT INTO t1 VALUES (1),(2); +SELECT DISTINCT f FROM t1 ORDER BY 1 && ( '1972-11-06 16:58:58' BETWEEN CONVERT( 0, TIME ) AND '20:31:05' ); +f +1 +2 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a VARCHAR(32)); +INSERT INTO t1 VALUES ('1972-11-06 16:58:58'); +SELECT * FROM t1 WHERE a < TIME'20:31:05'; +a +1972-11-06 16:58:58 +SELECT a < TIME'20:31:05' FROM t1; +a < TIME'20:31:05' +1 +DROP TABLE t1; +SELECT '1972-11-06 16:58:58' < TIME'20:31:05'; +'1972-11-06 16:58:58' < TIME'20:31:05' +1 +# # End of 10.4 tests # diff --git a/mysql-test/main/type_time.test b/mysql-test/main/type_time.test index 7eb75b95af2..08e43041c76 100644 --- a/mysql-test/main/type_time.test +++ b/mysql-test/main/type_time.test @@ -1430,6 +1430,23 @@ INSERT INTO t1 VALUES (3e19); DROP TABLE t1; +--echo # +--echo # MDEV-18876 Assertion `is_valid_time_slow()' failed in Time::valid_MYSQL_TIME_to_valid_value +--echo # + +CREATE TABLE t1 (f INT); +INSERT INTO t1 VALUES (1),(2); +SELECT DISTINCT f FROM t1 ORDER BY 1 && ( '1972-11-06 16:58:58' BETWEEN CONVERT( 0, TIME ) AND '20:31:05' ); +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a VARCHAR(32)); +INSERT INTO t1 VALUES ('1972-11-06 16:58:58'); +SELECT * FROM t1 WHERE a < TIME'20:31:05'; +SELECT a < TIME'20:31:05' FROM t1; +DROP TABLE t1; + +SELECT '1972-11-06 16:58:58' < TIME'20:31:05'; + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/type_time_hires.result b/mysql-test/main/type_time_hires.result index 47185116bea..ca19e9ed5bf 100644 --- a/mysql-test/main/type_time_hires.result +++ b/mysql-test/main/type_time_hires.result @@ -67,8 +67,10 @@ a 01:02:03.4567 select extract(microsecond from a + interval 100 microsecond) from t1 where a>'2010-11-12 01:02:03.456'; extract(microsecond from a + interval 100 microsecond) +456800 select a from t1 where a>'2010-11-12 01:02:03.456' group by a; a +01:02:03.4567 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -115,6 +117,11 @@ NULL delete from t1 where a < 20110101; select * from t1; a +01:02:13.3332 +NULL +delete from t1 where a is not null; +select * from t1; +a NULL create table t2 select * from t1; create table t3 like t1; diff --git a/sql/item.cc b/sql/item.cc index 6589f1e5683..826fd742a07 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -129,6 +129,20 @@ longlong Item::val_datetime_packed_result(THD *thd) } +longlong Item::val_time_packed_result(THD *thd) +{ + MYSQL_TIME ltime; + if (get_date_result(thd, <ime, Time::Options_cmp(thd))) + return 0; + if (ltime.time_type == MYSQL_TIMESTAMP_TIME) + return pack_time(<ime); + int warn= 0; + Time tmp(&warn, <ime, 0); + DBUG_ASSERT(tmp.is_valid_time()); + return tmp.to_packed(); +} + + /* For the items which don't have its own fast val_str_ascii() implementation we provide a generic slower version, diff --git a/sql/item.h b/sql/item.h index 0ffbd2f8bc4..19b81decbc7 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1708,12 +1708,7 @@ public: return Time(thd, this, Time::Options_cmp(thd)).to_packed(); } longlong val_datetime_packed_result(THD *thd); - longlong val_time_packed_result(THD *thd) - { - MYSQL_TIME ltime; - return get_date_result(thd, <ime, Time::Options_cmp(thd)) ? 0 : - pack_time(<ime); - } + longlong val_time_packed_result(THD *thd); virtual bool get_date_result(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { return get_date(thd, ltime,fuzzydate); }