-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-32730][SQL] Improve LeftSemi and Existence SortMergeJoin right side buffering #29572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1a49356
acc6646
037b876
3937e4c
5cf3ab3
f699118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,7 +156,8 @@ case class SortMergeJoinExec( | |
| RowIterator.fromScala(rightIter), | ||
| inMemoryThreshold, | ||
| spillThreshold, | ||
| cleanupResources | ||
| cleanupResources, | ||
| false | ||
| ) | ||
| private[this] val joinRow = new JoinedRow | ||
|
|
||
|
|
@@ -201,7 +202,8 @@ case class SortMergeJoinExec( | |
| bufferedIter = RowIterator.fromScala(rightIter), | ||
| inMemoryThreshold, | ||
| spillThreshold, | ||
| cleanupResources | ||
| cleanupResources, | ||
| false | ||
| ) | ||
| val rightNullRow = new GenericInternalRow(right.output.length) | ||
| new LeftOuterIterator( | ||
|
|
@@ -216,7 +218,8 @@ case class SortMergeJoinExec( | |
| bufferedIter = RowIterator.fromScala(leftIter), | ||
| inMemoryThreshold, | ||
| spillThreshold, | ||
| cleanupResources | ||
| cleanupResources, | ||
| false | ||
| ) | ||
| val leftNullRow = new GenericInternalRow(left.output.length) | ||
| new RightOuterIterator( | ||
|
|
@@ -251,7 +254,8 @@ case class SortMergeJoinExec( | |
| RowIterator.fromScala(rightIter), | ||
| inMemoryThreshold, | ||
| spillThreshold, | ||
| cleanupResources | ||
| cleanupResources, | ||
| condition.isEmpty | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @peter-toth !
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @juliuszsompolski, I think you are right. Shall I open a follow-up PR or a different ticket?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a followup PR is fine.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've opened #29727 |
||
| ) | ||
| private[this] val joinRow = new JoinedRow | ||
|
|
||
|
|
@@ -287,7 +291,8 @@ case class SortMergeJoinExec( | |
| RowIterator.fromScala(rightIter), | ||
| inMemoryThreshold, | ||
| spillThreshold, | ||
| cleanupResources | ||
| cleanupResources, | ||
| false | ||
| ) | ||
| private[this] val joinRow = new JoinedRow | ||
|
|
||
|
|
@@ -330,7 +335,8 @@ case class SortMergeJoinExec( | |
| RowIterator.fromScala(rightIter), | ||
| inMemoryThreshold, | ||
| spillThreshold, | ||
| cleanupResources | ||
| cleanupResources, | ||
| condition.isEmpty | ||
| ) | ||
| private[this] val joinRow = new JoinedRow | ||
|
|
||
|
|
@@ -662,7 +668,8 @@ private[joins] class SortMergeJoinScanner( | |
| bufferedIter: RowIterator, | ||
| inMemoryThreshold: Int, | ||
| spillThreshold: Int, | ||
| eagerCleanupResources: () => Unit) { | ||
| eagerCleanupResources: () => Unit, | ||
| bufferFirstOnly: Boolean) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, fixed. |
||
| private[this] var streamedRow: InternalRow = _ | ||
| private[this] var streamedRowKey: InternalRow = _ | ||
| private[this] var bufferedRow: InternalRow = _ | ||
|
|
@@ -673,8 +680,9 @@ private[joins] class SortMergeJoinScanner( | |
| */ | ||
| private[this] var matchJoinKey: InternalRow = _ | ||
| /** Buffered rows from the buffered side of the join. This is empty if there are no matches. */ | ||
| private[this] val bufferedMatches = | ||
| new ExternalAppendOnlyUnsafeRowArray(inMemoryThreshold, spillThreshold) | ||
| private[this] val bufferedMatches: ExternalAppendOnlyUnsafeRowArray = | ||
| new ExternalAppendOnlyUnsafeRowArray(if (bufferFirstOnly) 1 else inMemoryThreshold, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this change avoid spilling?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not this change does it, but the one in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this change? How about just setting 1 in the caller side? https://github.com/apache/spark/pull/29572/files#diff-2649ee0724bbc5ee6a64d7de308c527eR255
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is another call site in existence join: https://github.com/apache/spark/pull/29572/files#diff-2649ee0724bbc5ee6a64d7de308c527eR336 |
||
| spillThreshold) | ||
|
|
||
| // Initialization (note: do _not_ want to advance streamed here). | ||
| advancedBufferedToRowWithNullFreeJoinKey() | ||
|
|
@@ -834,7 +842,9 @@ private[joins] class SortMergeJoinScanner( | |
| matchJoinKey = streamedRowKey.copy() | ||
| bufferedMatches.clear() | ||
| do { | ||
| bufferedMatches.add(bufferedRow.asInstanceOf[UnsafeRow]) | ||
| if (!bufferFirstOnly || bufferedMatches.isEmpty) { | ||
| bufferedMatches.add(bufferedRow.asInstanceOf[UnsafeRow]) | ||
| } | ||
| advancedBufferedToRowWithNullFreeJoinKey() | ||
| } while (bufferedRow != null && keyOrdering.compare(streamedRowKey, bufferedRowKey) == 0) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -749,6 +749,14 @@ class JoinSuite extends QueryTest with SharedSparkSession with AdaptiveSparkPlan | |
| ) | ||
| } | ||
|
|
||
| // LEFT SEMI JOIN without bound condition does not spill | ||
| assertNotSpilled(sparkContext, "left semi join") { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this fix this UT fails. |
||
| checkAnswer( | ||
| sql("SELECT * FROM testData LEFT SEMI JOIN testData2 ON key = a WHERE key = 2"), | ||
| Row(2, "2") :: Nil | ||
| ) | ||
| } | ||
|
|
||
| val expected = new ListBuffer[Row]() | ||
| expected.append( | ||
| Row(1, "1", 1, 1), Row(1, "1", 1, 2), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please avoid the unnecessary changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, reverted them.