Skip to content

Commit

Permalink
Disable OUTER JOIN(TRUE) -> INNER JOIN rewrite
Browse files Browse the repository at this point in the history
This rewrite is not valid for OUTER joins as it would give incorrect
results in case when we have empty table on INNER side.
After rewrite query would return no rows, instead
rows from OUTER table complemented with NULLs.
  • Loading branch information
losipiuk authored and erichwang committed Jun 8, 2016
1 parent c09afe5 commit c7825f6
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ public PlanNode visitJoin(JoinNode node, RewriteContext<Expression> context)
if (leftSource != node.getLeft() ||
rightSource != node.getRight() ||
!expressionEquivalence.areExpressionsEquivalent(session, newJoinPredicate, joinPredicate, types)) {
if (newJoinPredicate.equals(BooleanLiteral.TRUE_LITERAL)) {
if (node.getType() == JoinNode.Type.INNER && newJoinPredicate.equals(BooleanLiteral.TRUE_LITERAL)) {
// this rewrite is not valid for OUTER joins as it would give incorrect results in case when we have empty table on INNER side
// after rewrite query would return no rows, instead rows from OUTER table complemented with NULLs.
output = new JoinNode(node.getId(), INNER, leftSource, rightSource, ImmutableList.of(), node.getFilter(), Optional.<Symbol>empty(), Optional.<Symbol>empty());
}
else {
Expand Down

0 comments on commit c7825f6

Please sign in to comment.