Skip to content

Commit 979dfbc

Browse files
committed
Avoid unnecessary bufferring and copy in full outer sort merge join
1 parent 2ef60f7 commit 979dfbc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/joins/SortMergeJoinExec.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,15 +1631,19 @@ private class SortMergeFullOuterJoinScanner(
16311631
advancedRight()
16321632
true
16331633
} else if (leftRow != null && rightRow != null) {
1634-
// Both rows are present and neither have null values,
1635-
// so we populate the buffers with rows matching the next key
1634+
// Both rows are present and neither have null values.
16361635
val comp = keyOrdering.compare(leftRowKey, rightRowKey)
1637-
if (comp <= 0) {
1638-
findMatchingRows(leftRowKey.copy())
1636+
if (comp < 0) {
1637+
joinedRow(leftRow.copy(), rightNullRow)
1638+
advancedLeft()
1639+
} else if (comp > 0) {
1640+
joinedRow(leftNullRow, rightRow.copy())
1641+
advancedRight()
16391642
} else {
1640-
findMatchingRows(rightRowKey.copy())
1643+
// Populate the buffers with rows matching the next key.
1644+
findMatchingRows(leftRowKey.copy())
1645+
scanNextInBuffered()
16411646
}
1642-
scanNextInBuffered()
16431647
true
16441648
} else {
16451649
// Both iterators have been consumed

0 commit comments

Comments
 (0)