Commit a0c722d8 authored by Varun Gupta's avatar Varun Gupta

MDEV-15321:different results when using value of optimizer_use_condition_selectivity=4 and =1

To disallow equality propagation for DATETIME with non-zero YYYYMMDD part we were setting null_value to true.
This caused issues when we were calculating selectivity for a condition as this returned IMPOSSIBLE WHERE.

The issue is resolved by not setting null_value to true for DATETIME with non-zero YYYYMMDD.
parent 0a534348
......@@ -1215,5 +1215,36 @@ MAX(a) MAX(COALESCE(a))
10:20:30 10:20:30
DROP TABLE t1;
#
# MDEV-15321: different results when using value of optimizer_use_condition_selectivity=4 and =1
#
SET @save_old_mode=@@old_mode;
SET @@old_mode=zero_date_time_cast;
CREATE TABLE t1 (a TIME);
INSERT INTO t1 VALUES ('0000-00-00 10:20:30'),('0000-00-00 10:20:31');
INSERT INTO t1 VALUES ('0000-00-01 10:20:30'),('0000-00-01 10:20:31');
INSERT INTO t1 VALUES ('31 10:20:30'),('32 10:20:30'),('33 10:20:30'),('34 10:20:30');
SET @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
SET @@optimizer_use_condition_selectivity=1;
SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
a
34:20:30
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '0000-00-01 10:20:30') and (length(`test`.`t1`.`a`) = 8))
SET @@optimizer_use_condition_selectivity=4;
SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
a
34:20:30
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '0000-00-01 10:20:30') and (length(`test`.`t1`.`a`) = 8))
drop table t1;
SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @@old_mode= @save_old_mode;
#
# End of 10.1 tests
#
......@@ -723,6 +723,29 @@ INSERT INTO t1 VALUES ('10:10:10'),('10:20:30');
SELECT MAX(a), MAX(COALESCE(a)) FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-15321: different results when using value of optimizer_use_condition_selectivity=4 and =1
--echo #
SET @save_old_mode=@@old_mode;
SET @@old_mode=zero_date_time_cast;
CREATE TABLE t1 (a TIME);
INSERT INTO t1 VALUES ('0000-00-00 10:20:30'),('0000-00-00 10:20:31');
INSERT INTO t1 VALUES ('0000-00-01 10:20:30'),('0000-00-01 10:20:31');
INSERT INTO t1 VALUES ('31 10:20:30'),('32 10:20:30'),('33 10:20:30'),('34 10:20:30');
SET @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
SET @@optimizer_use_condition_selectivity=1;
SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
SET @@optimizer_use_condition_selectivity=4;
SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='0000-00-01 10:20:30' AND LENGTH(a)=8;
drop table t1;
SET @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @@old_mode= @save_old_mode;
--echo #
--echo # End of 10.1 tests
--echo #
......@@ -166,19 +166,21 @@ bool Item::get_time_with_conversion(THD *thd, MYSQL_TIME *ltime,
- truncate the YYYYMMDD part
- add (MM*33+DD)*24 to hours
- add (MM*31+DD)*24 to hours
Let's return NULL here, to disallow equal field propagation.
Let's return TRUE here, to disallow equal field propagation.
Note, If we start to use this method in more pieces of the code other
than eqial field propagation, we should probably return
NULL only if some flag in fuzzydate is set.
than equal field propagation, we should probably return
TRUE only if some flag in fuzzydate is set.
*/
return (null_value= true);
return true;
}
if (datetime_to_time_with_warn(thd, ltime, &ltime2, TIME_SECOND_PART_DIGITS))
{
/*
Time difference between CURRENT_DATE and ltime
did not fit into the supported TIME range
If the time difference between CURRENT_DATE and ltime
did not fit into the supported TIME range, then we set the
difference to the maximum possible value in the supported TIME range
*/
DBUG_ASSERT(0);
return (null_value= true);
}
*ltime= ltime2;
......
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