Skip to content

Commit edfebc2

Browse files
committed
Fix filter source variable not found bug in left join to semi join optimizer
1 parent 8dd2b4c commit edfebc2

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

presto-main-base/src/main/java/com/facebook/presto/sql/planner/iterative/rule/LeftJoinNullFilterToSemiJoin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public Result apply(FilterNode filterNode, Captures captures, Context context)
150150
|| (semiJoinFilteringSource instanceof ProjectNode &&
151151
((ProjectNode) semiJoinFilteringSource).getSource() instanceof AggregationNode &&
152152
AggregationNode.isDistinct((AggregationNode) ((ProjectNode) semiJoinFilteringSource).getSource())))) {
153-
AggregationNode.GroupingSetDescriptor groupingSetDescriptor = new AggregationNode.GroupingSetDescriptor(ImmutableList.of(semiJoinFilteringSource.getOutputVariables().get(0)), 1, ImmutableSet.of());
153+
AggregationNode.GroupingSetDescriptor groupingSetDescriptor = new AggregationNode.GroupingSetDescriptor(ImmutableList.of(rightKey), 1, ImmutableSet.of());
154154
semiJoinFilteringSource = new AggregationNode(
155155
semiJoinFilteringSource.getSourceLocation(),
156156
context.getIdAllocator().getNextId(),

presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7447,6 +7447,10 @@ public void testLeftJoinNullFilterToSemiJoin()
74477447
assertQuery(enableOptimization, sql, "values 3, 3");
74487448
assertNotEquals(computeActual("EXPLAIN(TYPE DISTRIBUTED) " + sql).getOnlyValue().toString().indexOf("Aggregate"), -1);
74497449

7450+
// filter in right child of join
7451+
sql = "with t1 as (select * from (values (1, 2), (2, 3), (1, 0)) t(k1, k2)), t2 as (select * from (values (1, 2), (2, 3)) t(k1, k2)) select t1.k1, t1.k2 from t1 left join t2 on t1.k2=t2.k2 and t2.k1 > 1 where t2.k2 is null";
7452+
assertQuery(enableOptimization, sql, "values (1, 2), (1, 0)");
7453+
74507454
// null in left side
74517455
sql = "with t1 as (select * from (values 1, 1, 2, 2, 3, 3, null) t(k)), t2 as (select * from (values 1, 1, 2, 2) t(k)) select t1.* from t1 left join t2 on t1.k=t2.k where t2.k is null";
74527456
assertQuery(enableOptimization, sql, "values 3, 3, null");

0 commit comments

Comments
 (0)