Commit 78b580b7 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-5132.

Objects of the classes Item_func_isnull and Item_func_isnotnull
must have the flag sargable set to TRUE.
Set the value of the flag sargable only in constructors of the 
classes inherited from Item_int_func.
parent 092a2388
......@@ -373,3 +373,12 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT * FROM t1 WHERE NOT (concat( dt, '1' ) IS NOT NULL);
dt
DROP TABLE t1;
#
# Bug mdev-5132: crash when exeicuting a join query
# with IS NULL and IS NOT NULL in where
#
CREATE TABLE t1 (a DATE, b INT, c INT, KEY(a), KEY(b), KEY(c)) ENGINE=MyISAM;
CREATE TABLE t2 (d DATE) ENGINE=MyISAM;
SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL;
a b c d
DROP TABLE t1,t2;
......@@ -283,3 +283,15 @@ SELECT * FROM t1 WHERE NOT (concat( dt, '1' ) IS NOT NULL);
SELECT * FROM t1 WHERE NOT (concat( dt, '1' ) IS NOT NULL);
DROP TABLE t1;
--echo #
--echo # Bug mdev-5132: crash when exeicuting a join query
--echo # with IS NULL and IS NOT NULL in where
--echo #
CREATE TABLE t1 (a DATE, b INT, c INT, KEY(a), KEY(b), KEY(c)) ENGINE=MyISAM;
CREATE TABLE t2 (d DATE) ENGINE=MyISAM;
SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL;
DROP TABLE t1,t2;
......@@ -539,8 +539,6 @@ void Item_bool_func2::fix_length_and_dec()
to the collation of A.
*/
sargable= true;
DTCollation coll;
if (args[0]->result_type() == STRING_RESULT &&
args[1]->result_type() == STRING_RESULT &&
......@@ -2185,7 +2183,6 @@ void Item_func_between::fix_length_and_dec()
THD *thd= current_thd;
max_length= 1;
compare_as_dates= 0;
sargable= true;
/*
As some compare functions are generated after sql_yacc,
......@@ -3865,7 +3862,6 @@ void Item_func_in::fix_length_and_dec()
uint found_types= 0;
uint type_cnt= 0, i;
Item_result cmp_type= STRING_RESULT;
sargable= true;
left_result_type= args[0]->cmp_type();
if (!(found_types= collect_cmp_types(args, arg_count, true)))
return;
......@@ -5492,6 +5488,7 @@ Item_equal::Item_equal(Item *f1, Item *f2, bool with_const_item)
equal_items.push_back(f2);
compare_as_dates= with_const_item && f2->cmp_type() == TIME_RESULT;
upper_levels= NULL;
sargable= TRUE;
}
......@@ -5521,6 +5518,7 @@ Item_equal::Item_equal(Item_equal *item_equal)
compare_as_dates= item_equal->compare_as_dates;
cond_false= item_equal->cond_false;
upper_levels= item_equal->upper_levels;
sargable= TRUE;
}
......@@ -5944,7 +5942,6 @@ void Item_equal::fix_length_and_dec()
Item *item= get_first(NO_PARTICULAR_TAB, NULL);
eval_item= cmp_item::get_comparator(item->cmp_type(), item,
item->collation.collation);
sargable= true;
}
......
......@@ -118,7 +118,7 @@ public:
Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
Item_bool_func(THD *thd, Item_bool_func *item) :Item_int_func(thd, item) {}
bool is_bool_func() { return 1; }
void fix_length_and_dec() { decimals=0; max_length=1; sargable= true;}
void fix_length_and_dec() { decimals=0; max_length=1; }
uint decimal_precision() const { return 1; }
};
......@@ -364,7 +364,8 @@ protected:
public:
Item_bool_func2(Item *a,Item *b)
:Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1), abort_on_null(FALSE) {}
:Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1),
abort_on_null(FALSE) { sargable= TRUE; }
void fix_length_and_dec();
void set_cmp_func()
{
......@@ -668,7 +669,7 @@ public:
/* TRUE <=> arguments will be compared as dates. */
Item *compare_as_dates;
Item_func_between(Item *a, Item *b, Item *c)
:Item_func_opt_neg(a, b, c), compare_as_dates(FALSE) {}
:Item_func_opt_neg(a, b, c), compare_as_dates(FALSE) { sargable= TRUE; }
longlong val_int();
optimize_type select_optimize() const { return OPTIMIZE_KEY; }
enum Functype functype() const { return BETWEEN; }
......@@ -1284,6 +1285,7 @@ public:
{
bzero(&cmp_items, sizeof(cmp_items));
allowed_arg_cols= 0; // Fetch this value from first argument
sargable= TRUE;
}
longlong val_int();
bool fix_fields(THD *, Item **);
......@@ -1349,7 +1351,7 @@ public:
class Item_func_isnull :public Item_bool_func
{
public:
Item_func_isnull(Item *a) :Item_bool_func(a) {}
Item_func_isnull(Item *a) :Item_bool_func(a) { sargable= TRUE; }
longlong val_int();
enum Functype functype() const { return ISNULL_FUNC; }
void fix_length_and_dec()
......@@ -1410,7 +1412,8 @@ class Item_func_isnotnull :public Item_bool_func
{
bool abort_on_null;
public:
Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0)
{ sargable= TRUE; }
longlong val_int();
enum Functype functype() const { return ISNOTNULL_FUNC; }
void fix_length_and_dec()
......@@ -1717,7 +1720,7 @@ public:
inline Item_equal()
: Item_bool_func(), with_const(FALSE), eval_item(0), cond_false(0),
context_field(NULL)
{ const_item_cache=0 ;}
{ const_item_cache=0; sargable= TRUE; }
Item_equal(Item *f1, Item *f2, bool with_const_item);
Item_equal(Item_equal *item_equal);
/* Currently the const item is always the first in the list of equal items */
......
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