Commit 50c64e29 authored by Rex's avatar Rex

MDEV-19520 pushdown_from_having_into_where() not calling fix_fields() correctly

fix_fields() called in pushdown_from_having_into_where() assuming that the
item is immutable.
normalize_cond() extended to include (not f)=>(f == 0) to avoid the
issue where NOT(field) was being transformed to (field == 0) during
this fix_fields call.

s
parent a586b6db
......@@ -4969,4 +4969,14 @@ SELECT a,b FROM t1 GROUP BY a,b HAVING a = (b IS NULL);
a b
0 11
DROP TABLE t1;
#
# MDEV-19520 pushdown_from_having_into_where() not calling fix_fields()
# correctly
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1);
SELECT a FROM t1 GROUP BY a HAVING NOT a;
a
0
DROP TABLE t1;
End of 10.4 tests
......@@ -1485,4 +1485,14 @@ SELECT a,b FROM t1 GROUP BY a,b HAVING a = (b IS NULL);
DROP TABLE t1;
--echo #
--echo # MDEV-19520 pushdown_from_having_into_where() not calling fix_fields()
--echo # correctly
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1);
SELECT a FROM t1 GROUP BY a HAVING NOT a;
DROP TABLE t1;
--echo End of 10.4 tests
......@@ -9111,6 +9111,7 @@ push_new_name_resolution_context(THD *thd,
/**
Fix condition which contains only field (f turns to f <> 0 )
or only contains the function NOT field (not f turns to f == 0)
@param cond The condition to fix
......@@ -9126,6 +9127,22 @@ Item *normalize_cond(THD *thd, Item *cond)
{
cond= new (thd->mem_root) Item_func_ne(thd, cond, new (thd->mem_root) Item_int(thd, 0));
}
else
{
if (type == Item::FUNC_ITEM)
{
Item_func *func_item= (Item_func *)cond;
if (func_item->functype() == Item_func::NOT_FUNC &&
func_item->argument_count() == 1)
{
Item *arg= func_item->arguments()[0];
if (arg->type() == Item::FIELD_ITEM ||
arg->type() == Item::REF_ITEM)
cond= new (thd->mem_root) Item_func_eq(thd, arg,
new (thd->mem_root) Item_int(thd, 0));
}
}
}
}
return cond;
}
......
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