diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-12-19 14:03:54 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-12-19 14:03:54 +0400 |
commit | 1f1e3ce8a18ab548f9641ea10295372abbd147ad (patch) | |
tree | 4988f087b0688195015141f24aa4f6a0d571504f | |
parent | a5a433e256d29f00b6b51babcf0aac49e95c7e82 (diff) | |
download | mariadb-git-1f1e3ce8a18ab548f9641ea10295372abbd147ad.tar.gz |
MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41
Item_ref::val_(datetime|time)_packed() erroneously called
(*ref)->val_(datetime|time)_packed().
- Fixing to call (*ref)->val_(datetime|time)_packed_result().
- Backporting Item::val_(datetime|time)_packed_result() from 10.3.
- Fixing Item_field::get_date_result() to handle null_value in the same
way how Item_field::get_date() does.
-rw-r--r-- | mysql-test/r/type_datetime.result | 81 | ||||
-rw-r--r-- | mysql-test/r/type_time.result | 66 | ||||
-rw-r--r-- | mysql-test/t/type_datetime.test | 43 | ||||
-rw-r--r-- | mysql-test/t/type_time.test | 34 | ||||
-rw-r--r-- | sql/item.cc | 24 | ||||
-rw-r--r-- | sql/item.h | 7 |
6 files changed, 250 insertions, 5 deletions
diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 591df19a9c6..3468ff67b53 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -1198,5 +1198,86 @@ Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2 DROP VIEW v1; DROP TABLE t1; # +# MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +# +CREATE TABLE t1 +( +id INT NOT NULL PRIMARY KEY, +id2 INT, +k TINYINT, +j INT, +t DATETIME, +KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'2019-12-13 10:09:59'), +(54,54,1,0,'2019-12-13 16:28:41'), +(55,54,1,0,'2019-12-13 16:29:10'), +(56,54,1,0,'2019-12-13 16:29:43'), +(57,54,1,0,'2019-12-13 16:30:16'), +(58,54,1,0,'2019-12-13 16:30:49'), +(59,54,1,0,'2019-12-13 16:31:23'), +(60,54,1,0,'2019-12-13 16:31:55'), +(61,54,1,0,'2019-12-13 16:32:28'), +(62,54,1,0,'2019-12-13 16:33:01'), +(63,54,1,0,'2019-12-13 16:33:34'), +(64,54,1,0,'2019-12-13 16:34:07'), +(65,54,1,0,'2019-12-13 16:34:40'), +(66,54,1,0,'2019-12-13 16:35:13'), +(67,54,1,0,'2019-12-13 16:35:46'), +(68,54,1,0,'2019-12-13 16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=max(t); +t +2019-12-13 10:09:59 +2019-12-13 16:28:41 +2019-12-13 16:29:10 +2019-12-13 16:29:43 +2019-12-13 16:30:16 +2019-12-13 16:30:49 +2019-12-13 16:31:23 +2019-12-13 16:31:55 +2019-12-13 16:32:28 +2019-12-13 16:33:01 +2019-12-13 16:33:34 +2019-12-13 16:34:07 +2019-12-13 16:34:40 +2019-12-13 16:35:13 +2019-12-13 16:35:46 +2019-12-13 16:36:19 +SELECT t FROM t1 WHERE id2=54 and j=0 and k=1 GROUP BY t HAVING t=max(t); +t +2019-12-13 10:09:59 +2019-12-13 16:28:41 +2019-12-13 16:29:10 +2019-12-13 16:29:43 +2019-12-13 16:30:16 +2019-12-13 16:30:49 +2019-12-13 16:31:23 +2019-12-13 16:31:55 +2019-12-13 16:32:28 +2019-12-13 16:33:01 +2019-12-13 16:33:34 +2019-12-13 16:34:07 +2019-12-13 16:34:40 +2019-12-13 16:35:13 +2019-12-13 16:35:46 +2019-12-13 16:36:19 +DROP TABLE t1; +CREATE TABLE t1 (pk INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1); +SELECT pk<DATE'2001-01-01' FROM t1 GROUP BY pk; +pk<DATE'2001-01-01' +1 +Warnings: +Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1 +SELECT pk<DATE'2001-01-01' FROM v1 GROUP BY pk; +pk<DATE'2001-01-01' +1 +Warnings: +Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1 +DROP VIEW v1; +DROP TABLE t1; +# # End of 10.1 tests # diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index fc287e86fbd..9719f544fbb 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -1246,5 +1246,71 @@ drop table t1; SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@old_mode= @save_old_mode; # +# MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +# +CREATE OR REPLACE TABLE t1 +( +id INT NOT NULL PRIMARY KEY, +id2 INT, +k TINYINT, +j INT, +t TIME, +KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'10:09:59'), +(54,54,1,0,'16:28:41'), +(55,54,1,0,'16:29:10'), +(56,54,1,0,'16:29:43'), +(57,54,1,0,'16:30:16'), +(58,54,1,0,'16:30:49'), +(59,54,1,0,'16:31:23'), +(60,54,1,0,'16:31:55'), +(61,54,1,0,'16:32:28'), +(62,54,1,0,'16:33:01'), +(63,54,1,0,'16:33:34'), +(64,54,1,0,'16:34:07'), +(65,54,1,0,'16:34:40'), +(66,54,1,0,'16:35:13'), +(67,54,1,0,'16:35:46'), +(68,54,1,0,'16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=MAX(t); +t +10:09:59 +16:28:41 +16:29:10 +16:29:43 +16:30:16 +16:30:49 +16:31:23 +16:31:55 +16:32:28 +16:33:01 +16:33:34 +16:34:07 +16:34:40 +16:35:13 +16:35:46 +16:36:19 +SELECT t FROM t1 WHERE id2=54 AND j=0 AND k=1 GROUP BY t HAVING t=MAX(t); +t +10:09:59 +16:28:41 +16:29:10 +16:29:43 +16:30:16 +16:30:49 +16:31:23 +16:31:55 +16:32:28 +16:33:01 +16:33:34 +16:34:07 +16:34:40 +16:35:13 +16:35:46 +16:36:19 +DROP TABLE t1; +# # End of 10.1 tests # diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index 6df3ab60764..447a5d4b192 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -748,5 +748,48 @@ DROP TABLE t1; --echo # +--echo # MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +--echo # + +CREATE TABLE t1 +( + id INT NOT NULL PRIMARY KEY, + id2 INT, + k TINYINT, + j INT, + t DATETIME, + KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'2019-12-13 10:09:59'), +(54,54,1,0,'2019-12-13 16:28:41'), +(55,54,1,0,'2019-12-13 16:29:10'), +(56,54,1,0,'2019-12-13 16:29:43'), +(57,54,1,0,'2019-12-13 16:30:16'), +(58,54,1,0,'2019-12-13 16:30:49'), +(59,54,1,0,'2019-12-13 16:31:23'), +(60,54,1,0,'2019-12-13 16:31:55'), +(61,54,1,0,'2019-12-13 16:32:28'), +(62,54,1,0,'2019-12-13 16:33:01'), +(63,54,1,0,'2019-12-13 16:33:34'), +(64,54,1,0,'2019-12-13 16:34:07'), +(65,54,1,0,'2019-12-13 16:34:40'), +(66,54,1,0,'2019-12-13 16:35:13'), +(67,54,1,0,'2019-12-13 16:35:46'), +(68,54,1,0,'2019-12-13 16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=max(t); +SELECT t FROM t1 WHERE id2=54 and j=0 and k=1 GROUP BY t HAVING t=max(t); +DROP TABLE t1; + +CREATE TABLE t1 (pk INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1); +SELECT pk<DATE'2001-01-01' FROM t1 GROUP BY pk; +SELECT pk<DATE'2001-01-01' FROM v1 GROUP BY pk; +DROP VIEW v1; +DROP TABLE t1; + + +--echo # --echo # End of 10.1 tests --echo # diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index 10b75f27546..49128234795 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -747,5 +747,39 @@ SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selecti set @@old_mode= @save_old_mode; --echo # +--echo # MDEV-21319 COUNT(*) returns 1, actual SELECT returns no result in 10.3.21, but 1 result in 10.1.41 +--echo # + +CREATE OR REPLACE TABLE t1 +( + id INT NOT NULL PRIMARY KEY, + id2 INT, + k TINYINT, + j INT, + t TIME, + KEY k1 (id2,k,j,t) +); +INSERT INTO t1 VALUES +(53,54,1,0,'10:09:59'), +(54,54,1,0,'16:28:41'), +(55,54,1,0,'16:29:10'), +(56,54,1,0,'16:29:43'), +(57,54,1,0,'16:30:16'), +(58,54,1,0,'16:30:49'), +(59,54,1,0,'16:31:23'), +(60,54,1,0,'16:31:55'), +(61,54,1,0,'16:32:28'), +(62,54,1,0,'16:33:01'), +(63,54,1,0,'16:33:34'), +(64,54,1,0,'16:34:07'), +(65,54,1,0,'16:34:40'), +(66,54,1,0,'16:35:13'), +(67,54,1,0,'16:35:46'), +(68,54,1,0,'16:36:19'); +SELECT t FROM t1 GROUP BY t HAVING t=MAX(t); +SELECT t FROM t1 WHERE id2=54 AND j=0 AND k=1 GROUP BY t HAVING t=MAX(t); +DROP TABLE t1; + +--echo # --echo # End of 10.1 tests --echo # diff --git a/sql/item.cc b/sql/item.cc index 86bd4670714..17eb570ad80 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -145,6 +145,19 @@ bool Item::get_date_with_conversion(MYSQL_TIME *ltime, ulonglong fuzzydate) } +longlong Item::val_datetime_packed_result() +{ + MYSQL_TIME ltime, tmp; + if (get_date_result(<ime, TIME_FUZZY_DATES | TIME_INVALID_DATES)) + return 0; + if (ltime.time_type != MYSQL_TIMESTAMP_TIME) + return pack_time(<ime); + if ((null_value= time_to_datetime_with_warn(current_thd, <ime, &tmp, 0))) + return 0; + return pack_time(&tmp); +} + + /** Get date/time/datetime. If DATETIME or DATE result is returned, it's converted to TIME. @@ -2594,12 +2607,13 @@ bool Item_field::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) bool Item_field::get_date_result(MYSQL_TIME *ltime, ulonglong fuzzydate) { - if (result_field->is_null() || result_field->get_date(ltime,fuzzydate)) + if ((null_value= result_field->is_null()) || + result_field->get_date(ltime, fuzzydate)) { bzero((char*) ltime,sizeof(*ltime)); - return (null_value= 1); + return true; } - return (null_value= 0); + return false; } @@ -7313,7 +7327,7 @@ bool Item_ref::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) longlong Item_ref::val_datetime_packed() { DBUG_ASSERT(fixed); - longlong tmp= (*ref)->val_datetime_packed(); + longlong tmp= (*ref)->val_datetime_packed_result(); null_value= (*ref)->null_value; return tmp; } @@ -7322,7 +7336,7 @@ longlong Item_ref::val_datetime_packed() longlong Item_ref::val_time_packed() { DBUG_ASSERT(fixed); - longlong tmp= (*ref)->val_time_packed(); + longlong tmp= (*ref)->val_time_packed_result(); null_value= (*ref)->null_value; return tmp; } diff --git a/sql/item.h b/sql/item.h index fb11064f122..bea09620ef8 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1302,6 +1302,13 @@ public: uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES | TIME_TIME_ONLY; return get_date(<ime, fuzzydate) ? 0 : pack_time(<ime); } + longlong val_datetime_packed_result(); + longlong val_time_packed_result() + { + MYSQL_TIME ltime; + uint fuzzydate= TIME_TIME_ONLY | TIME_INVALID_DATES | TIME_FUZZY_DATES; + return get_date_result(<ime, fuzzydate) ? 0 : pack_time(<ime); + } // Get a temporal value in packed DATE/DATETIME or TIME format longlong val_temporal_packed(enum_field_types f_type) { |