diff options
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 714eb8be7ee..bc0990d50b2 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -888,10 +888,13 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, enum_field_types f_type= item->cmp_type() == TIME_RESULT ? item->field_type() : warn_item->field_type(); - if (item->result_type() == INT_RESULT && item->cmp_type() == TIME_RESULT) + if (item->result_type() == INT_RESULT && + item->cmp_type() == TIME_RESULT && + item->type() == Item::CACHE_ITEM) { /* it's our Item_cache_temporal, as created below */ - value= item->val_int(); + DBUG_ASSERT(is_temporal_type(((Item_cache *) item)->field_type())); + value= ((Item_cache_temporal*) item)->val_temporal_packed(); } else { @@ -5706,8 +5709,8 @@ Item *Item_bool_rowready_func2::negated_item() */ Item_equal::Item_equal(Item *f1, Item *f2, bool with_const_item) - : Item_bool_func(), eval_item(0), cond_false(0), context_field(NULL), - link_equal_fields(FALSE) + : Item_bool_func(), eval_item(0), cond_false(0), cond_true(0), + context_field(NULL), link_equal_fields(FALSE) { const_item_cache= 0; with_const= with_const_item; @@ -5732,8 +5735,8 @@ Item_equal::Item_equal(Item *f1, Item *f2, bool with_const_item) */ Item_equal::Item_equal(Item_equal *item_equal) - : Item_bool_func(), eval_item(0), cond_false(0), context_field(NULL), - link_equal_fields(FALSE) + : Item_bool_func(), eval_item(0), cond_false(0), cond_true(0), + context_field(NULL), link_equal_fields(FALSE) { const_item_cache= 0; List_iterator_fast<Item> li(item_equal->equal_items); @@ -5800,13 +5803,9 @@ void Item_equal::add_const(Item *c, Item *f) func->quick_fix_field(); cond_false= !func->val_int(); } - /* - TODO: also support the case where Item_equal becomes singular with - this->is_cond_true()=1. When I attempted to mark the item as constant, - the optimizer attempted to remove it, however it is still referenced from - COND_EQUAL and I got a crash. - */ - if (cond_false) + if (with_const && equal_items.elements == 1) + cond_true= TRUE; + if (cond_false || cond_true) const_item_cache= 1; } @@ -6010,8 +6009,7 @@ void Item_equal::merge_into_list(List<Item_equal> *list, void Item_equal::sort(Item_field_cmpfunc compare, void *arg) { - if (equal_items.elements > 1) - bubble_sort<Item>(&equal_items, compare, arg); + bubble_sort<Item>(&equal_items, compare, arg); } @@ -6139,13 +6137,7 @@ bool Item_equal::fix_fields(THD *thd, Item **ref) void Item_equal::update_used_tables() { not_null_tables_cache= used_tables_cache= 0; - /* - TODO: also support the case where Item_equal becomes singular with - this->is_cond_true()=1. When I attempted to mark the item as constant, - the optimizer attempted to remove it, however it is still referenced from - COND_EQUAL and I got a crash. - */ - if ((const_item_cache= cond_false)) + if ((const_item_cache= cond_false || cond_true)) return; Item_equal_fields_iterator it(*this); Item *item; @@ -6194,7 +6186,7 @@ longlong Item_equal::val_int() { if (cond_false) return 0; - if (is_cond_true()) + if (cond_true) return 1; Item *item= get_const(); Item_equal_fields_iterator it(*this); @@ -6220,11 +6212,6 @@ longlong Item_equal::val_int() void Item_equal::fix_length_and_dec() { Item *item= get_first(NO_PARTICULAR_TAB, NULL); - if (!item) - { - DBUG_ASSERT(is_cond_true()); // it should be the only constant - item= equal_items.head(); - } eval_item= cmp_item::get_comparator(item->cmp_type(), item, item->collation.collation); } |