Commit 1f1e3ce8 authored by Alexander Barkov's avatar Alexander Barkov

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.
parent a5a433e2
...@@ -1198,5 +1198,86 @@ Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2 ...@@ -1198,5 +1198,86 @@ Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; 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 # End of 10.1 tests
# #
...@@ -1246,5 +1246,71 @@ drop table t1; ...@@ -1246,5 +1246,71 @@ drop table t1;
SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @@old_mode= @save_old_mode; 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 # End of 10.1 tests
# #
...@@ -747,6 +747,49 @@ DROP VIEW v1; ...@@ -747,6 +747,49 @@ DROP VIEW v1;
DROP TABLE t1; 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 #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -746,6 +746,40 @@ drop table t1; ...@@ -746,6 +746,40 @@ drop table t1;
SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @@old_mode= @save_old_mode; 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 #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -145,6 +145,19 @@ bool Item::get_date_with_conversion(MYSQL_TIME *ltime, ulonglong fuzzydate) ...@@ -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(&ltime, TIME_FUZZY_DATES | TIME_INVALID_DATES))
return 0;
if (ltime.time_type != MYSQL_TIMESTAMP_TIME)
return pack_time(&ltime);
if ((null_value= time_to_datetime_with_warn(current_thd, &ltime, &tmp, 0)))
return 0;
return pack_time(&tmp);
}
/** /**
Get date/time/datetime. Get date/time/datetime.
If DATETIME or DATE result is returned, it's converted to TIME. 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) ...@@ -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) 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)); 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) ...@@ -7313,7 +7327,7 @@ bool Item_ref::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
longlong Item_ref::val_datetime_packed() longlong Item_ref::val_datetime_packed()
{ {
DBUG_ASSERT(fixed); DBUG_ASSERT(fixed);
longlong tmp= (*ref)->val_datetime_packed(); longlong tmp= (*ref)->val_datetime_packed_result();
null_value= (*ref)->null_value; null_value= (*ref)->null_value;
return tmp; return tmp;
} }
...@@ -7322,7 +7336,7 @@ longlong Item_ref::val_datetime_packed() ...@@ -7322,7 +7336,7 @@ longlong Item_ref::val_datetime_packed()
longlong Item_ref::val_time_packed() longlong Item_ref::val_time_packed()
{ {
DBUG_ASSERT(fixed); DBUG_ASSERT(fixed);
longlong tmp= (*ref)->val_time_packed(); longlong tmp= (*ref)->val_time_packed_result();
null_value= (*ref)->null_value; null_value= (*ref)->null_value;
return tmp; return tmp;
} }
......
...@@ -1302,6 +1302,13 @@ class Item: public Value_source, ...@@ -1302,6 +1302,13 @@ class Item: public Value_source,
uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES | TIME_TIME_ONLY; uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES | TIME_TIME_ONLY;
return get_date(&ltime, fuzzydate) ? 0 : pack_time(&ltime); return get_date(&ltime, fuzzydate) ? 0 : pack_time(&ltime);
} }
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(&ltime, fuzzydate) ? 0 : pack_time(&ltime);
}
// Get a temporal value in packed DATE/DATETIME or TIME format // Get a temporal value in packed DATE/DATETIME or TIME format
longlong val_temporal_packed(enum_field_types f_type) longlong val_temporal_packed(enum_field_types f_type)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment