Commit 6cc2e7ea authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8795 Equal expression propagation does not work for temporal literals

parent 9b577edd
...@@ -748,5 +748,16 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` ...@@ -748,5 +748,16 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`
DROP TABLE t1; DROP TABLE t1;
SET timestamp=DEFAULT; SET timestamp=DEFAULT;
# #
# MDEV-8795 Equal expression propagation does not work for temporal literals
#
CREATE TABLE t1 (a DATE);
INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=DATE'2001-01-01' AND COALESCE(a)>=DATE'2001-01-01';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (coalesce(`test`.`t1`.`a`) = DATE'2001-01-01')
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -1085,5 +1085,16 @@ Warnings: ...@@ -1085,5 +1085,16 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (40 + rand()))) Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (40 + rand())))
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-8795 Equal expression propagation does not work for temporal literals
#
CREATE TABLE t1 (a DATETIME);
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-02 00:00:00');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=TIMESTAMP'2001-01-01 00:00:00' AND COALESCE(a)>=TIMESTAMP'2001-01-01 00:00:00';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (coalesce(`test`.`t1`.`a`) = TIMESTAMP'2001-01-01 00:00:00')
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -958,5 +958,16 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` ...@@ -958,5 +958,16 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`
DROP TABLE t1; DROP TABLE t1;
SET timestamp=DEFAULT; SET timestamp=DEFAULT;
# #
# MDEV-8795 Equal expression propagation does not work for temporal literals
#
CREATE TABLE t1 (a TIME);
INSERT INTO t1 VALUES ('00:00:01'),('00:00:02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=TIME'00:00:01' AND COALESCE(a)>=TIME'00:00:01';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (coalesce(`test`.`t1`.`a`) = TIME'00:00:01')
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -531,6 +531,15 @@ DROP TABLE t1; ...@@ -531,6 +531,15 @@ DROP TABLE t1;
SET timestamp=DEFAULT; SET timestamp=DEFAULT;
--echo #
--echo # MDEV-8795 Equal expression propagation does not work for temporal literals
--echo #
CREATE TABLE t1 (a DATE);
INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=DATE'2001-01-01' AND COALESCE(a)>=DATE'2001-01-01';
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -655,6 +655,14 @@ SET sql_mode=DEFAULT; ...@@ -655,6 +655,14 @@ SET sql_mode=DEFAULT;
--let $TYPE= DATETIME --let $TYPE= DATETIME
--source include/equal_fields_propagation_datetime.inc --source include/equal_fields_propagation_datetime.inc
--echo #
--echo # MDEV-8795 Equal expression propagation does not work for temporal literals
--echo #
CREATE TABLE t1 (a DATETIME);
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-02 00:00:00');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=TIMESTAMP'2001-01-01 00:00:00' AND COALESCE(a)>=TIMESTAMP'2001-01-01 00:00:00';
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -576,6 +576,14 @@ DROP TABLE t1; ...@@ -576,6 +576,14 @@ DROP TABLE t1;
SET timestamp=DEFAULT; SET timestamp=DEFAULT;
--echo #
--echo # MDEV-8795 Equal expression propagation does not work for temporal literals
--echo #
CREATE TABLE t1 (a TIME);
INSERT INTO t1 VALUES ('00:00:01'),('00:00:02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(a)=TIME'00:00:01' AND COALESCE(a)>=TIME'00:00:01';
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -6430,6 +6430,12 @@ void Item_date_literal::print(String *str, enum_query_type query_type) ...@@ -6430,6 +6430,12 @@ void Item_date_literal::print(String *str, enum_query_type query_type)
} }
Item *Item_date_literal::clone_item(THD *thd)
{
return new (thd->mem_root) Item_date_literal(thd, &cached_time);
}
bool Item_date_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) bool Item_date_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{ {
DBUG_ASSERT(fixed); DBUG_ASSERT(fixed);
...@@ -6450,6 +6456,12 @@ void Item_datetime_literal::print(String *str, enum_query_type query_type) ...@@ -6450,6 +6456,12 @@ void Item_datetime_literal::print(String *str, enum_query_type query_type)
} }
Item *Item_datetime_literal::clone_item(THD *thd)
{
return new (thd->mem_root) Item_datetime_literal(thd, &cached_time, decimals);
}
bool Item_datetime_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) bool Item_datetime_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{ {
DBUG_ASSERT(fixed); DBUG_ASSERT(fixed);
...@@ -6470,6 +6482,12 @@ void Item_time_literal::print(String *str, enum_query_type query_type) ...@@ -6470,6 +6482,12 @@ void Item_time_literal::print(String *str, enum_query_type query_type)
} }
Item *Item_time_literal::clone_item(THD *thd)
{
return new (thd->mem_root) Item_time_literal(thd, &cached_time, decimals);
}
bool Item_time_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) bool Item_time_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{ {
DBUG_ASSERT(fixed); DBUG_ASSERT(fixed);
......
...@@ -3348,6 +3348,7 @@ public: ...@@ -3348,6 +3348,7 @@ public:
} }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; } enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type);
Item *clone_item(THD *thd);
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
}; };
...@@ -3366,6 +3367,7 @@ public: ...@@ -3366,6 +3367,7 @@ public:
} }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; } enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type);
Item *clone_item(THD *thd);
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
}; };
...@@ -3386,6 +3388,7 @@ public: ...@@ -3386,6 +3388,7 @@ public:
} }
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type);
Item *clone_item(THD *thd);
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
}; };
......
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