Skip to content

Commit

Permalink
MDEV-25969: Condition pushdown into derived table doesn't work if sel…
Browse files Browse the repository at this point in the history
…ect list uses SP

Post-merge fix in 10.4: add a testcase for pushdown into IN subquery
  • Loading branch information
spetrunia committed Jun 30, 2021
1 parent eebe209 commit c7443a0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
57 changes: 56 additions & 1 deletion mysql-test/main/derived_cond_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -10814,9 +10814,64 @@ EXPLAIN
}
}
}
# Extra test for 10.4+: Check that this works for pushdown into IN
# subqueries:
create table t4 (a int, b int, c decimal);
insert into t4 select a,a,a from t1;
# The subquery must be materialized and must have
# "attached_condition": "t1.a + 1 > 10",
# "having_condition": "`f1(a)` > 1 and `sum(b)` > 123",
explain format=json
select *
from t4
where
(a,b,c) in (select a, f1(a), sum(b) from t1 group by a, f1(a))
and
(a+1) > 10 AND b > 1 and c>123;
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t4",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "t4.a + 1 > 10 and t4.b > 1 and t4.c > 123 and t4.a is not null and t4.b is not null and t4.c is not null"
},
"table": {
"table_name": "<subquery2>",
"access_type": "eq_ref",
"possible_keys": ["distinct_key"],
"key": "distinct_key",
"key_length": "23",
"used_key_parts": ["a", "f1(a)", "sum(b)"],
"ref": ["test.t4.a", "test.t4.b", "test.t4.c"],
"rows": 1,
"filtered": 100,
"attached_condition": "t4.c = `<subquery2>`.`sum(b)`",
"materialized": {
"unique": 1,
"query_block": {
"select_id": 2,
"having_condition": "`f1(a)` > 1 and `sum(b)` > 123",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "t1.a + 1 > 10"
}
}
}
}
}
}
}
drop view v2;
drop function f1;
drop table t1;
drop table t1, t4;
# End of 10.2 tests
#
# MDEV-14579: pushdown conditions into materialized views/derived tables
Expand Down
19 changes: 18 additions & 1 deletion mysql-test/main/derived_cond_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -2305,9 +2305,26 @@ select a, f1(a), sum(b) from t1 group by a, f1(a);
explain format=json
select * from v2 where (s+1) > 10 AND a > 1 and a2>123;

--echo # Extra test for 10.4+: Check that this works for pushdown into IN
--echo # subqueries:

create table t4 (a int, b int, c decimal);
insert into t4 select a,a,a from t1;

--echo # The subquery must be materialized and must have
--echo # "attached_condition": "t1.a + 1 > 10",
--echo # "having_condition": "`f1(a)` > 1 and `sum(b)` > 123",
explain format=json
select *
from t4
where
(a,b,c) in (select a, f1(a), sum(b) from t1 group by a, f1(a))
and
(a+1) > 10 AND b > 1 and c>123;

drop view v2;
drop function f1;
drop table t1;
drop table t1, t4;
--echo # End of 10.2 tests

--echo #
Expand Down

0 comments on commit c7443a0

Please sign in to comment.