Skip to content

Commit c7443a0

Browse files
committed
MDEV-25969: Condition pushdown into derived table doesn't work if select list uses SP
Post-merge fix in 10.4: add a testcase for pushdown into IN subquery
1 parent eebe209 commit c7443a0

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

mysql-test/main/derived_cond_pushdown.result

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10814,9 +10814,64 @@ EXPLAIN
1081410814
}
1081510815
}
1081610816
}
10817+
# Extra test for 10.4+: Check that this works for pushdown into IN
10818+
# subqueries:
10819+
create table t4 (a int, b int, c decimal);
10820+
insert into t4 select a,a,a from t1;
10821+
# The subquery must be materialized and must have
10822+
# "attached_condition": "t1.a + 1 > 10",
10823+
# "having_condition": "`f1(a)` > 1 and `sum(b)` > 123",
10824+
explain format=json
10825+
select *
10826+
from t4
10827+
where
10828+
(a,b,c) in (select a, f1(a), sum(b) from t1 group by a, f1(a))
10829+
and
10830+
(a+1) > 10 AND b > 1 and c>123;
10831+
EXPLAIN
10832+
{
10833+
"query_block": {
10834+
"select_id": 1,
10835+
"table": {
10836+
"table_name": "t4",
10837+
"access_type": "ALL",
10838+
"rows": 3,
10839+
"filtered": 100,
10840+
"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"
10841+
},
10842+
"table": {
10843+
"table_name": "<subquery2>",
10844+
"access_type": "eq_ref",
10845+
"possible_keys": ["distinct_key"],
10846+
"key": "distinct_key",
10847+
"key_length": "23",
10848+
"used_key_parts": ["a", "f1(a)", "sum(b)"],
10849+
"ref": ["test.t4.a", "test.t4.b", "test.t4.c"],
10850+
"rows": 1,
10851+
"filtered": 100,
10852+
"attached_condition": "t4.c = `<subquery2>`.`sum(b)`",
10853+
"materialized": {
10854+
"unique": 1,
10855+
"query_block": {
10856+
"select_id": 2,
10857+
"having_condition": "`f1(a)` > 1 and `sum(b)` > 123",
10858+
"temporary_table": {
10859+
"table": {
10860+
"table_name": "t1",
10861+
"access_type": "ALL",
10862+
"rows": 3,
10863+
"filtered": 100,
10864+
"attached_condition": "t1.a + 1 > 10"
10865+
}
10866+
}
10867+
}
10868+
}
10869+
}
10870+
}
10871+
}
1081710872
drop view v2;
1081810873
drop function f1;
10819-
drop table t1;
10874+
drop table t1, t4;
1082010875
# End of 10.2 tests
1082110876
#
1082210877
# MDEV-14579: pushdown conditions into materialized views/derived tables

mysql-test/main/derived_cond_pushdown.test

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,9 +2305,26 @@ select a, f1(a), sum(b) from t1 group by a, f1(a);
23052305
explain format=json
23062306
select * from v2 where (s+1) > 10 AND a > 1 and a2>123;
23072307

2308+
--echo # Extra test for 10.4+: Check that this works for pushdown into IN
2309+
--echo # subqueries:
2310+
2311+
create table t4 (a int, b int, c decimal);
2312+
insert into t4 select a,a,a from t1;
2313+
2314+
--echo # The subquery must be materialized and must have
2315+
--echo # "attached_condition": "t1.a + 1 > 10",
2316+
--echo # "having_condition": "`f1(a)` > 1 and `sum(b)` > 123",
2317+
explain format=json
2318+
select *
2319+
from t4
2320+
where
2321+
(a,b,c) in (select a, f1(a), sum(b) from t1 group by a, f1(a))
2322+
and
2323+
(a+1) > 10 AND b > 1 and c>123;
2324+
23082325
drop view v2;
23092326
drop function f1;
2310-
drop table t1;
2327+
drop table t1, t4;
23112328
--echo # End of 10.2 tests
23122329

23132330
--echo #

0 commit comments

Comments
 (0)