Skip to content

Commit 2faefe5

Browse files
committed
MDEV-18383: Missing rows with pushdown condition defined with IF-function
using Item_cond This bug is similar to the bug MDEV-16765. It appears because of the wrong pushdown into HAVING clause while this pushdown shouldn't be made at all. This happens because function that checks if Item_cond can be pushed always returns that it can be pushed. To fix it new method Item_cond::excl_dep_on_table() was added.
1 parent 57dd892 commit 2faefe5

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

mysql-test/r/derived_cond_pushdown.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10480,4 +10480,25 @@ EXPLAIN
1048010480
}
1048110481
DROP VIEW v1,v2;
1048210482
DROP TABLE t1;
10483+
#
10484+
# MDEV-18383: pushdown condition with the IF structure
10485+
# defined with Item_cond item
10486+
#
10487+
CREATE TABLE t1(a INT, b INT);
10488+
CREATE TABLE t2(c INT, d INT);
10489+
INSERT INTO t1 VALUES (1,2),(3,4),(5,6);
10490+
INSERT INTO t2 VALUES (1,3),(3,7),(5,1);
10491+
SELECT *
10492+
FROM t1,
10493+
(
10494+
SELECT MAX(d) AS max_d,c
10495+
FROM t2
10496+
GROUP BY c
10497+
) AS tab
10498+
WHERE t1.a=tab.c AND
10499+
IF(2,t1.a=1 OR t1.b>5,1=1);
10500+
a b max_d c
10501+
1 2 3 1
10502+
5 6 1 5
10503+
DROP TABLE t1,t2;
1048310504
# End of 10.2 tests

mysql-test/t/derived_cond_pushdown.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,4 +2102,26 @@ eval EXPLAIN FORMAT=JSON $q2;
21022102
DROP VIEW v1,v2;
21032103
DROP TABLE t1;
21042104

2105+
--echo #
2106+
--echo # MDEV-18383: pushdown condition with the IF structure
2107+
--echo # defined with Item_cond item
2108+
--echo #
2109+
2110+
CREATE TABLE t1(a INT, b INT);
2111+
CREATE TABLE t2(c INT, d INT);
2112+
INSERT INTO t1 VALUES (1,2),(3,4),(5,6);
2113+
INSERT INTO t2 VALUES (1,3),(3,7),(5,1);
2114+
2115+
SELECT *
2116+
FROM t1,
2117+
(
2118+
SELECT MAX(d) AS max_d,c
2119+
FROM t2
2120+
GROUP BY c
2121+
) AS tab
2122+
WHERE t1.a=tab.c AND
2123+
IF(2,t1.a=1 OR t1.b>5,1=1);
2124+
2125+
DROP TABLE t1,t2;
2126+
21052127
--echo # End of 10.2 tests

sql/item_cmpfunc.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,6 +4994,23 @@ Item *Item_cond::build_clone(THD *thd, MEM_ROOT *mem_root)
49944994
}
49954995

49964996

4997+
bool Item_cond::excl_dep_on_table(table_map tab_map)
4998+
{
4999+
if (used_tables() & OUTER_REF_TABLE_BIT)
5000+
return false;
5001+
if (!(used_tables() & ~tab_map))
5002+
return true;
5003+
List_iterator_fast<Item> li(list);
5004+
Item *item;
5005+
while ((item= li++))
5006+
{
5007+
if (!item->excl_dep_on_table(tab_map))
5008+
return false;
5009+
}
5010+
return true;
5011+
}
5012+
5013+
49975014
bool Item_cond::excl_dep_on_grouping_fields(st_select_lex *sel)
49985015
{
49995016
List_iterator_fast<Item> li(list);

sql/item_cmpfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,7 @@ class Item_cond :public Item_bool_func
22292229
Item_transformer transformer, uchar *arg_t);
22302230
bool eval_not_null_tables(void *opt_arg);
22312231
Item *build_clone(THD *thd, MEM_ROOT *mem_root);
2232+
bool excl_dep_on_table(table_map tab_map);
22322233
bool excl_dep_on_grouping_fields(st_select_lex *sel);
22332234
};
22342235

0 commit comments

Comments
 (0)