Skip to content

Commit 03d2c55

Browse files
committed
Always output left side join key for inner join
1 parent f419d2f commit 03d2c55

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

presto-main-base/src/main/java/com/facebook/presto/sql/planner/optimizations/UnaliasSymbolReferences.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,18 +591,26 @@ public PlanNode visitJoin(JoinNode node, RewriteContext<Void> context)
591591
if (node.getType().equals(INNER)) {
592592
canonicalCriteria.stream()
593593
.filter(clause -> clause.getLeft().getType().equals(clause.getRight().getType()) && clause.getLeft().getType().equalValuesAreIdentical())
594-
.filter(clause -> node.getOutputVariables().contains(clause.getLeft()))
594+
.filter(clause -> node.getOutputVariables().contains(clause.getRight()))
595595
.forEach(clause -> map(clause.getRight(), clause.getLeft()));
596596
}
597597

598+
List<VariableReferenceExpression> canonicalizedOutput = canonicalizeAndDistinct(node.getOutputVariables());
599+
if (canonicalCriteria.stream().map(x -> x.getRight().getName()).anyMatch(mapping::containsKey)) {
600+
canonicalizedOutput = ImmutableList.<VariableReferenceExpression>builder()
601+
.addAll(canonicalizedOutput.stream().filter(left.getOutputVariables()::contains).collect(Collectors.toList()))
602+
.addAll(canonicalizedOutput.stream().filter(right.getOutputVariables()::contains).collect(Collectors.toList()))
603+
.build();
604+
}
605+
598606
return new JoinNode(
599607
node.getSourceLocation(),
600608
node.getId(),
601609
node.getType(),
602610
left,
603611
right,
604612
canonicalCriteria,
605-
canonicalizeAndDistinct(node.getOutputVariables()),
613+
canonicalizedOutput,
606614
canonicalFilter,
607615
canonicalLeftHashVariable,
608616
canonicalRightHashVariable,

0 commit comments

Comments
 (0)