mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Fix for bug#49199: Optimizer handles incorrectly:
field='const1' AND field='const2' in some cases Building multiple equality predicates containing a constant which is compared as a datetime (with a field) we should take this fact into account and compare the constant with another possible constatns as datetimes as well. E.g. for the SELECT ... WHERE a='2001-01-01' AND a='2001-01-01 00:00:00' we should compare '2001-01-01' with '2001-01-01 00:00:00' as datetimes but not as strings. mysql-test/r/select.result: Fix for bug#49199: Optimizer handles incorrectly: field='const1' AND field='const2' in some cases - test result. mysql-test/t/select.test: Fix for bug#49199: Optimizer handles incorrectly: field='const1' AND field='const2' in some cases - test case. sql/item_cmpfunc.cc: Fix for bug#49199: Optimizer handles incorrectly: field='const1' AND field='const2' in some cases - adding a constant to Item_equal compare it as a datetime value with stored one if there's a date[time] field in a equality predicate. sql/item_cmpfunc.h: Fix for bug#49199: Optimizer handles incorrectly: field='const1' AND field='const2' in some cases - adding a constant to Item_equal compare it as a datetime value with stored one if there's a date[time] field in a equality predicate. sql/sql_select.cc: Fix for bug#49199: Optimizer handles incorrectly: field='const1' AND field='const2' in some cases - adding a constant to Item_equal compare it as a datetime value with stored one if there's a date[time] field in a equality predicate.
This commit is contained in:
@@ -4903,7 +4903,8 @@ Item *Item_bool_rowready_func2::negated_item()
|
||||
}
|
||||
|
||||
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
|
||||
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
|
||||
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0),
|
||||
compare_as_dates(FALSE)
|
||||
{
|
||||
const_item_cache= 0;
|
||||
fields.push_back(f1);
|
||||
@@ -4916,6 +4917,7 @@ Item_equal::Item_equal(Item *c, Item_field *f)
|
||||
const_item_cache= 0;
|
||||
fields.push_back(f);
|
||||
const_item= c;
|
||||
compare_as_dates= f->is_datetime();
|
||||
}
|
||||
|
||||
|
||||
@@ -4930,9 +4932,45 @@ Item_equal::Item_equal(Item_equal *item_equal)
|
||||
fields.push_back(item);
|
||||
}
|
||||
const_item= item_equal->const_item;
|
||||
compare_as_dates= item_equal->compare_as_dates;
|
||||
cond_false= item_equal->cond_false;
|
||||
}
|
||||
|
||||
|
||||
void Item_equal::compare_const(Item *c)
|
||||
{
|
||||
if (compare_as_dates)
|
||||
{
|
||||
cmp.set_datetime_cmp_func(&c, &const_item);
|
||||
cond_false= cmp.compare();
|
||||
}
|
||||
else
|
||||
{
|
||||
Item_func_eq *func= new Item_func_eq(c, const_item);
|
||||
func->set_cmp_func();
|
||||
func->quick_fix_field();
|
||||
cond_false= !func->val_int();
|
||||
}
|
||||
if (cond_false)
|
||||
const_item_cache= 1;
|
||||
}
|
||||
|
||||
|
||||
void Item_equal::add(Item *c, Item_field *f)
|
||||
{
|
||||
if (cond_false)
|
||||
return;
|
||||
if (!const_item)
|
||||
{
|
||||
DBUG_ASSERT(f);
|
||||
const_item= c;
|
||||
compare_as_dates= f->is_datetime();
|
||||
return;
|
||||
}
|
||||
compare_const(c);
|
||||
}
|
||||
|
||||
|
||||
void Item_equal::add(Item *c)
|
||||
{
|
||||
if (cond_false)
|
||||
@@ -4942,11 +4980,7 @@ void Item_equal::add(Item *c)
|
||||
const_item= c;
|
||||
return;
|
||||
}
|
||||
Item_func_eq *func= new Item_func_eq(c, const_item);
|
||||
func->set_cmp_func();
|
||||
func->quick_fix_field();
|
||||
if ((cond_false= !func->val_int()))
|
||||
const_item_cache= 1;
|
||||
compare_const(c);
|
||||
}
|
||||
|
||||
void Item_equal::add(Item_field *f)
|
||||
|
Reference in New Issue
Block a user