-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix hash join with sort push down #13560
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ea4a7f5
fix: join with sort push down
haohuaijin 5e5fa7d
chore:
haohuaijin 528b57e
Merge branch 'main' into fix-join-with-sort-push-down
haohuaijin 7f81178
apply suggestion
haohuaijin 13b98b5
recover handle_costom_pushdown change
haohuaijin 52d9def
Merge branch 'apache:main' into fix-join-with-sort-push-down
haohuaijin e080ee0
Merge branch 'apache:main' into fix-join-with-sort-push-down
haohuaijin b4e214d
apply suggestion
haohuaijin 64fac8f
add more test
haohuaijin 2f05a33
add partition
haohuaijin 64f0188
Merge branch 'apache:main' into fix-join-with-sort-push-down
haohuaijin 3b1f50a
Merge branch 'apache:main' into fix-join-with-sort-push-down
haohuaijin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2864,13 +2864,13 @@ explain SELECT t1_id, t1_name FROM left_semi_anti_join_table_t1 t1 WHERE t1_id I | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
05)--------CoalesceBatchesExec: target_batch_size=2 | ||
06)----------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
07)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
08)--------------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
04)------CoalesceBatchesExec: target_batch_size=2 | ||
05)--------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
06)----------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)------------MemoryExec: partitions=1, partition_sizes=[1] | ||
08)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
09)--------CoalesceBatchesExec: target_batch_size=2 | ||
10)----------RepartitionExec: partitioning=Hash([t1_id@0], 2), input_partitions=2 | ||
11)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
|
@@ -2905,13 +2905,13 @@ explain SELECT t1_id, t1_name FROM left_semi_anti_join_table_t1 t1 LEFT SEMI JOI | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
05)--------CoalesceBatchesExec: target_batch_size=2 | ||
06)----------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
07)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
08)--------------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
04)------CoalesceBatchesExec: target_batch_size=2 | ||
05)--------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
06)----------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)------------MemoryExec: partitions=1, partition_sizes=[1] | ||
08)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
09)--------CoalesceBatchesExec: target_batch_size=2 | ||
10)----------RepartitionExec: partitioning=Hash([t1_id@0], 2), input_partitions=2 | ||
11)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
|
@@ -2967,10 +2967,10 @@ explain SELECT t1_id, t1_name FROM left_semi_anti_join_table_t1 t1 WHERE t1_id I | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
05)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
04)------MemoryExec: partitions=1, partition_sizes=[1] | ||
05)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
06)--------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)----------MemoryExec: partitions=1, partition_sizes=[1] | ||
|
||
|
@@ -3003,10 +3003,10 @@ explain SELECT t1_id, t1_name FROM left_semi_anti_join_table_t1 t1 LEFT SEMI JOI | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
05)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)] | ||
04)------MemoryExec: partitions=1, partition_sizes=[1] | ||
05)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
06)--------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)----------MemoryExec: partitions=1, partition_sizes=[1] | ||
|
||
|
@@ -3061,13 +3061,13 @@ explain SELECT t1_id, t1_name, t1_int FROM right_semi_anti_join_table_t1 t1 WHER | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@1 != t1_name@0 | ||
05)--------CoalesceBatchesExec: target_batch_size=2 | ||
06)----------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
07)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
08)--------------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@1 != t1_name@0 | ||
04)------CoalesceBatchesExec: target_batch_size=2 | ||
05)--------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
06)----------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)------------MemoryExec: partitions=1, partition_sizes=[1] | ||
08)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
09)--------CoalesceBatchesExec: target_batch_size=2 | ||
10)----------RepartitionExec: partitioning=Hash([t1_id@0], 2), input_partitions=2 | ||
11)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
|
@@ -3083,13 +3083,13 @@ explain SELECT t1_id, t1_name, t1_int FROM right_semi_anti_join_table_t2 t2 RIGH | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@0 != t1_name@1 | ||
05)--------CoalesceBatchesExec: target_batch_size=2 | ||
06)----------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
07)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
08)--------------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=Partitioned, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@0 != t1_name@1 | ||
04)------CoalesceBatchesExec: target_batch_size=2 | ||
05)--------RepartitionExec: partitioning=Hash([t2_id@0], 2), input_partitions=2 | ||
06)----------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)------------MemoryExec: partitions=1, partition_sizes=[1] | ||
08)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
09)--------CoalesceBatchesExec: target_batch_size=2 | ||
10)----------RepartitionExec: partitioning=Hash([t1_id@0], 2), input_partitions=2 | ||
11)------------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
|
@@ -3143,10 +3143,10 @@ explain SELECT t1_id, t1_name, t1_int FROM right_semi_anti_join_table_t1 t1 WHER | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@1 != t1_name@0 | ||
05)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
03)----HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@1 != t1_name@0 | ||
04)------MemoryExec: partitions=1, partition_sizes=[1] | ||
05)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
06)--------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)----------MemoryExec: partitions=1, partition_sizes=[1] | ||
|
||
|
@@ -3160,10 +3160,10 @@ explain SELECT t1_id, t1_name, t1_int FROM right_semi_anti_join_table_t2 t2 RIGH | |
---- | ||
physical_plan | ||
01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST] | ||
02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
03)----CoalesceBatchesExec: target_batch_size=2 | ||
04)------HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@0 != t1_name@1 | ||
05)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
02)--CoalesceBatchesExec: target_batch_size=2 | ||
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. These plans imply that the sort has been pushed into the second (probe) input which makes sense I think : https://docs.rs/datafusion/latest/datafusion/physical_plan/joins/struct.HashJoinExec.html |
||
03)----HashJoinExec: mode=CollectLeft, join_type=RightSemi, on=[(t2_id@0, t1_id@0)], filter=t2_name@0 != t1_name@1 | ||
04)------MemoryExec: partitions=1, partition_sizes=[1] | ||
05)------SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true] | ||
06)--------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1 | ||
07)----------MemoryExec: partitions=1, partition_sizes=[1] | ||
|
||
|
@@ -4313,3 +4313,29 @@ physical_plan | |
04)------HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(binary_col@0, binary_col@0)] | ||
05)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
06)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
|
||
statement ok | ||
CREATE TABLE test(a INT, b INT, c INT) | ||
|
||
statement ok | ||
insert into test values (1,2,3), (4,5,6) | ||
|
||
query TT | ||
explain select * from test where a not in (select a from test where b > 3) order by c desc; | ||
---- | ||
logical_plan | ||
01)Sort: test.c DESC NULLS FIRST | ||
02)--LeftAnti Join: test.a = __correlated_sq_1.a | ||
03)----TableScan: test projection=[a, b, c] | ||
04)----SubqueryAlias: __correlated_sq_1 | ||
05)------Projection: test.a | ||
06)--------Filter: test.b > Int32(3) | ||
07)----------TableScan: test projection=[a, b] | ||
physical_plan | ||
01)CoalesceBatchesExec: target_batch_size=3 | ||
02)--HashJoinExec: mode=CollectLeft, join_type=RightAnti, on=[(a@0, a@0)] | ||
03)----CoalesceBatchesExec: target_batch_size=3 | ||
04)------FilterExec: b@1 > 3, projection=[a@0] | ||
05)--------MemoryExec: partitions=1, partition_sizes=[1] | ||
06)----SortExec: expr=[c@2 DESC], preserve_partitioning=[false] | ||
07)------MemoryExec: partitions=1, partition_sizes=[1] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think it would be great eventually to get this kind of operator specific logic into the operators (e.g. some method in HashJoinExec). Definitely not in this PR, but having assumptions about the operator separate from its implementation gives us a larger chance of introducing inconsistencies I think