[Commits] 740fc2a: Fixed mdev-15765 BETWEEN not working in certain cases

IgorBabaev igor at mariadb.com
Wed Apr 11 04:07:29 EEST 2018


revision-id: 740fc2ae084f8f81990de557d696aefbc507752d (mariadb-10.2.14-34-g740fc2a)
parent(s): 45e6d0aebf023acb50671f82b87e6de5d1e78f5e
author: Igor Babaev
committer: Igor Babaev
timestamp: 2018-04-10 18:07:29 -0700
message:

Fixed mdev-15765 BETWEEN not working in certain cases

The implementations of the convert_to_basic_const_item() virtual
function for the Item_cache classes should call cache_value() when
value_cached == NULL.

---
 mysql-test/r/derived_cond_pushdown.result | 15 +++++++++++++++
 mysql-test/t/derived_cond_pushdown.test   | 13 +++++++++++++
 sql/item.cc                               | 10 ++++++++++
 3 files changed, 38 insertions(+)

diff --git a/mysql-test/r/derived_cond_pushdown.result b/mysql-test/r/derived_cond_pushdown.result
index e30bd4c..8e74e09 100644
--- a/mysql-test/r/derived_cond_pushdown.result
+++ b/mysql-test/r/derived_cond_pushdown.result
@@ -9030,3 +9030,18 @@ EXPLAIN
   }
 }
 DROP TABLE t1,t2;
+#
+# MDEV-15765: pushing condition with temporal constants
+#             into constant tables
+#
+select * from (select  date('2018-01-01') as d
+union all
+select  date('2018-01-01') as d) as t
+where t.d between date ('2017-01-01') and date ('2019-01-01');
+d
+2018-01-01
+2018-01-01
+select * from (select  date('2018-01-01') as d) as t
+where t.d between date ('2017-01-01') and date ('2019-01-01');
+d
+2018-01-01
diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test
index b1555fd..0b87738 100644
--- a/mysql-test/t/derived_cond_pushdown.test
+++ b/mysql-test/t/derived_cond_pushdown.test
@@ -1633,3 +1633,16 @@ EVAL EXPLAIN $query;
 EVAL EXPLAIN FORMAT=JSON $query;
 
 DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-15765: pushing condition with temporal constants
+--echo #             into constant tables
+--echo #
+
+select * from (select  date('2018-01-01') as d
+               union all
+               select  date('2018-01-01') as d) as t
+  where t.d between date ('2017-01-01') and date ('2019-01-01');
+
+select * from (select  date('2018-01-01') as d) as t
+  where t.d between date ('2017-01-01') and date ('2019-01-01');
diff --git a/sql/item.cc b/sql/item.cc
index 007b4f4..0350b43 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -9687,6 +9687,8 @@ Item *Item_cache_int::convert_to_basic_const_item(THD *thd)
 {
   Item *new_item;
   DBUG_ASSERT(value_cached || example != 0);
+  if (!value_cached)
+    cache_value();
   new_item= null_value ?
             (Item*) new (thd->mem_root) Item_null(thd) :
 	    (Item*) new (thd->mem_root) Item_int(thd, val_int(), max_length);
@@ -9862,6 +9864,8 @@ Item *Item_cache_temporal::convert_to_basic_const_item(THD *thd)
 {
   Item *new_item;
   DBUG_ASSERT(value_cached || example != 0);
+  if (!value_cached)
+    cache_value();
   if (null_value)
     new_item= (Item*) new (thd->mem_root) Item_null(thd);
   else
@@ -9936,6 +9940,8 @@ Item *Item_cache_real::convert_to_basic_const_item(THD *thd)
 {
   Item *new_item;
   DBUG_ASSERT(value_cached || example != 0);
+  if (!value_cached)
+    cache_value();
   new_item= null_value ?
             (Item*) new (thd->mem_root) Item_null(thd) :
 	    (Item*) new (thd->mem_root) Item_float(thd, val_real(),
@@ -9999,6 +10005,8 @@ Item *Item_cache_decimal::convert_to_basic_const_item(THD *thd)
 {
   Item *new_item;
   DBUG_ASSERT(value_cached || example != 0);
+  if (!value_cached)
+    cache_value();
   if (null_value)
     new_item= (Item*) new (thd->mem_root) Item_null(thd);
   else
@@ -10094,6 +10102,8 @@ Item *Item_cache_str::convert_to_basic_const_item(THD *thd)
 {
   Item *new_item;
   DBUG_ASSERT(value_cached || example != 0);
+  if (!value_cached)
+    cache_value();
   if (null_value)
     new_item= (Item*) new (thd->mem_root) Item_null(thd);
   else


More information about the commits mailing list