summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-03-17 11:41:25 +0100
committerSergei Golubchik <sergii@pisem.net>2013-03-17 11:41:25 +0100
commit19fd5dcb159414ea54329b0d3fec6c6d0dc5c0d7 (patch)
tree53422be325dfde77ac5b01cdc5929bbd701d6638
parentf17af00893f22f494b3cc63cb29e71a9d50b5151 (diff)
downloadmariadb-git-19fd5dcb159414ea54329b0d3fec6c6d0dc5c0d7.tar.gz
MDEV-4284 Assertion `cmp_items[(uint)cmp_type]' fails in sql/item_cmpfunc.cc
Flip the switch and create Item_cache based on the argument's cmp_type, not argument's result_type(). Fix subselect_engine to calculate cmp_type correctly sql/item_subselect.h: mdev:4284
-rw-r--r--mysql-test/r/cache_temporal_4265.result1
-rw-r--r--mysql-test/r/func_date_add.result6
-rw-r--r--mysql-test/t/func_date_add.test12
-rw-r--r--sql/item.cc2
-rw-r--r--sql/item_subselect.cc10
-rw-r--r--sql/item_subselect.h5
6 files changed, 31 insertions, 5 deletions
diff --git a/mysql-test/r/cache_temporal_4265.result b/mysql-test/r/cache_temporal_4265.result
index b8f13e465de..1b4b3c2c4aa 100644
--- a/mysql-test/r/cache_temporal_4265.result
+++ b/mysql-test/r/cache_temporal_4265.result
@@ -7,5 +7,4 @@ a
2002-03-04
Warnings:
Note 1003 2000-01-01
-Note 1003 2000-01-06
drop table t1;
diff --git a/mysql-test/r/func_date_add.result b/mysql-test/r/func_date_add.result
index a7f2383848d..e8fbba786a4 100644
--- a/mysql-test/r/func_date_add.result
+++ b/mysql-test/r/func_date_add.result
@@ -96,3 +96,9 @@ b + interval a day
2002-02-04
drop table t1;
End of 5.0 tests
+create table t1 (a varchar(10));
+insert t1 values ('2000-12-03'),('2008-05-03');
+select * from t1 where case a when adddate( '2012-12-12', 7 ) then true end;
+a
+drop table t1;
+End of 5.5 tests
diff --git a/mysql-test/t/func_date_add.test b/mysql-test/t/func_date_add.test
index fc5a5cb2823..5f27978347c 100644
--- a/mysql-test/t/func_date_add.test
+++ b/mysql-test/t/func_date_add.test
@@ -88,3 +88,15 @@ select b + interval a day from t1;
drop table t1;
--echo End of 5.0 tests
+
+#
+# MDEV-4284 Assertion `cmp_items[(uint)cmp_type]' fails in sql/item_cmpfunc.cc
+#
+
+create table t1 (a varchar(10));
+insert t1 values ('2000-12-03'),('2008-05-03');
+select * from t1 where case a when adddate( '2012-12-12', 7 ) then true end;
+drop table t1;
+
+--echo End of 5.5 tests
+
diff --git a/sql/item.cc b/sql/item.cc
index 2c435eb6a9f..15f1645b151 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -8643,7 +8643,7 @@ int stored_field_cmp_to_item(THD *thd, Field *field, Item *item)
Item_cache* Item_cache::get_cache(const Item *item)
{
- return get_cache(item, item->result_type());
+ return get_cache(item, item->cmp_type());
}
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 152b50da616..9042e92f1da 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1087,6 +1087,11 @@ enum Item_result Item_singlerow_subselect::result_type() const
return engine->type();
}
+enum Item_result Item_singlerow_subselect::cmp_type() const
+{
+ return engine->cmptype();
+}
+
/*
Don't rely on the result type to calculate field type.
Ask the engine instead.
@@ -3044,12 +3049,13 @@ void subselect_engine::set_row(List<Item> &item_list, Item_cache **row)
{
Item *sel_item;
List_iterator_fast<Item> li(item_list);
- res_type= STRING_RESULT;
+ cmp_type= res_type= STRING_RESULT;
res_field_type= MYSQL_TYPE_VAR_STRING;
for (uint i= 0; (sel_item= li++); i++)
{
item->max_length= sel_item->max_length;
res_type= sel_item->result_type();
+ cmp_type= sel_item->cmp_type();
res_field_type= sel_item->field_type();
item->decimals= sel_item->decimals;
item->unsigned_flag= sel_item->unsigned_flag;
@@ -3060,7 +3066,7 @@ void subselect_engine::set_row(List<Item> &item_list, Item_cache **row)
//psergey-backport-timours: row[i]->store(sel_item);
}
if (item_list.elements > 1)
- res_type= ROW_RESULT;
+ cmp_type= res_type= ROW_RESULT;
}
void subselect_single_select_engine::fix_length_and_dec(Item_cache **row)
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 1da129380e7..25852b55d98 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -286,6 +286,7 @@ public:
bool val_bool();
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
enum Item_result result_type() const;
+ enum Item_result cmp_type() const;
enum_field_types field_type() const;
void fix_length_and_dec();
@@ -698,6 +699,7 @@ protected:
THD *thd; /* pointer to current THD */
Item_subselect *item; /* item, that use this engine */
enum Item_result res_type; /* type of results */
+ enum Item_result cmp_type; /* how to compare the results */
enum_field_types res_field_type; /* column type of the results */
bool maybe_null; /* may be null (first item in select) */
public:
@@ -712,7 +714,7 @@ public:
{
result= res;
item= si;
- res_type= STRING_RESULT;
+ cmp_type= res_type= STRING_RESULT;
res_field_type= MYSQL_TYPE_VAR_STRING;
maybe_null= 0;
set_thd(thd_arg);
@@ -752,6 +754,7 @@ public:
virtual uint cols()= 0; /* return number of columns in select */
virtual uint8 uncacheable()= 0; /* query is uncacheable */
enum Item_result type() { return res_type; }
+ enum Item_result cmptype() { return cmp_type; }
enum_field_types field_type() { return res_field_type; }
virtual void exclude()= 0;
virtual bool may_be_null() { return maybe_null; };