Commit 18366c93 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

NOT elimination moved in parsing (suggested by Monty)

parent 34dc3a86
......@@ -2030,15 +2030,6 @@ void Item_cond::neg_arguments(THD *thd)
{
if (!(new_item= new Item_func_not(item)))
return; // Fatal OEM error
/*
We can use 0 as tables list because Item_func_not do not use it
on fix_fields and its arguments are already fixed.
We do not check results of fix_fields, because there are not way
to return error in this functions interface, thd->net.report_error
will be checked on upper level call.
*/
new_item->fix_fields(thd, 0, &new_item);
}
VOID(li.replace(new_item));
}
......@@ -2734,18 +2725,6 @@ Item *Item_func_not::neg_transformer(THD *thd) /* NOT(x) -> x */
Item *Item_bool_rowready_func2::neg_transformer(THD *thd)
{
Item *item= negated_item();
if (item)
{
/*
We can use 0 as tables list because Item_func* family do not use it
on fix_fields and its arguments are already fixed.
We do not check results of fix_fields, because there are not way
to return error in this functions interface, thd->net.report_error
will be checked on upper level call.
*/
item->fix_fields(thd, 0, &item);
}
return item;
}
......@@ -2754,9 +2733,6 @@ Item *Item_bool_rowready_func2::neg_transformer(THD *thd)
Item *Item_func_isnull::neg_transformer(THD *thd)
{
Item *item= new Item_func_isnotnull(args[0]);
// see comment before fix_fields in Item_bool_rowready_func2::neg_transformer
if (item)
item->fix_fields(thd, 0, &item);
return item;
}
......@@ -2765,9 +2741,6 @@ Item *Item_func_isnull::neg_transformer(THD *thd)
Item *Item_func_isnotnull::neg_transformer(THD *thd)
{
Item *item= new Item_func_isnull(args[0]);
// see comment before fix_fields in Item_bool_rowready_func2::neg_transformer
if (item)
item->fix_fields(thd, 0, &item);
return item;
}
......@@ -2777,9 +2750,6 @@ Item *Item_cond_and::neg_transformer(THD *thd) /* NOT(a AND b AND ...) -> */
{
neg_arguments(thd);
Item *item= new Item_cond_or(list);
// see comment before fix_fields in Item_bool_rowready_func2::neg_transformer
if (item)
item->fix_fields(thd, 0, &item);
return item;
}
......@@ -2789,9 +2759,6 @@ Item *Item_cond_or::neg_transformer(THD *thd) /* NOT(a OR b OR ...) -> */
{
neg_arguments(thd);
Item *item= new Item_cond_and(list);
// see comment before fix_fields in Item_bool_rowready_func2::neg_transformer
if (item)
item->fix_fields(thd, 0, &item);
return item;
}
......
......@@ -274,7 +274,7 @@ public:
enum Functype rev_functype() const { return EQUAL_FUNC; }
cond_result eq_cmp_result() const { return COND_TRUE; }
const char *func_name() const { return "<=>"; }
Item* neg_transformer(THD *thd) { return 0; }
Item *neg_transformer(THD *thd) { return 0; }
};
......
......@@ -4401,19 +4401,6 @@ optimize_cond(THD *thd, COND *conds, Item::cond_result *cond_value)
if (conds)
{
DBUG_EXECUTE("where", print_where(conds, "original"););
/* Eliminate NOT operators; in case of PS/SP do it once */
if (thd->current_arena->is_first_stmt_execute())
{
Item_arena *arena= thd->current_arena, backup;
thd->set_n_backup_item_arena(arena, &backup);
conds= eliminate_not_funcs(thd, conds);
select->prep_where= conds->copy_andor_structure(thd);
thd->restore_backup_item_arena(arena, &backup);
}
else
conds= eliminate_not_funcs(thd, conds);
DBUG_EXECUTE("where", print_where(conds, "after negation elimination"););
/* change field = field to field = const for each found field = const */
propagate_cond_constants((I_List<COND_CMP> *) 0, conds, conds);
/*
......
......@@ -2755,8 +2755,16 @@ simple_expr:
| '+' expr %prec NEG { $$= $2; }
| '-' expr %prec NEG { $$= new Item_func_neg($2); }
| '~' expr %prec NEG { $$= new Item_func_bit_neg($2); }
| NOT expr %prec NEG { $$= new Item_func_not($2); }
| '!' expr %prec NEG { $$= new Item_func_not($2); }
| NOT expr %prec NEG
{
if (($$= $2->neg_transformer(YYTHD)) == 0)
$$= new Item_func_not($2);
}
| '!' expr %prec NEG
{
if (($$= $2->neg_transformer(YYTHD)) == 0)
$$= new Item_func_not($2);
}
| '(' expr ')' { $$= $2; }
| '(' expr ',' expr_list ')'
{
......
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