Commit d513a4ce authored by Rex's avatar Rex

MDEV-19520 Extend condition normalization to include 'NOT a'

Having Item_func_not items in item trees breaks assumptions during the
optimization phase about transformation possibilities in fix_fields().
Remove Item_func_not by extending normalization during parsing.

Reviewed by Oleksandr Byelkin (sanja@mariadb.com)
parent d9dd673f
......@@ -4969,4 +4969,16 @@ SELECT a,b FROM t1 GROUP BY a,b HAVING a = (b IS NULL);
a b
0 11
DROP TABLE t1;
#
# MDEV-19520 Extend condition normalization to include 'NOT a'
# having Item_func_not in item tree breaks assumptions during the
# optimization phase about transformation possibilities in fix_fields().
# Remove Item_func_not by extending normalization during parsing.
#
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,16 @@ SELECT a,b FROM t1 GROUP BY a,b HAVING a = (b IS NULL);
DROP TABLE t1;
--echo #
--echo # MDEV-19520 Extend condition normalization to include 'NOT a'
--echo # having Item_func_not in item tree breaks assumptions during the
--echo # optimization phase about transformation possibilities in fix_fields().
--echo # Remove Item_func_not by extending normalization during parsing.
--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
......@@ -9234,6 +9234,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
......@@ -9249,6 +9250,21 @@ 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)
{
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