-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Use NestedLoopJoin
instead of HashJoin
/SortMergeJoin
for small tables
#16450
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
base: main
Are you sure you want to change the base?
Conversation
I will try to run a benchmark on a table with smaller rows and return the result when finished. |
NestedLoopJoin
NestedLoopJoin
// If we can use nested loop join then we will combine the expressions in `join_on` | ||
// and pass it into the join filter; create your join filters normally otherwise. | ||
let join_filter: Option<JoinFilter> = if use_nested_loop_join_equijoin { | ||
let combined_join_on_expression: Expr = filter |
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.
It seems that when we combine the JoinOn
expressions here it will cause an error when both sides in the expression have the same unqualified name leading to duplicate unqualified fields. Is there a function that is able to qualify it with the schema, I can't seem to find one.
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.
To clarify, this is originally not a problem when the expression is in JoinOn
as each unqualified column is referring to their own table before being combined into one expression.
The upside is that it performs well when both tables are extremely small < 50 rows 😆 |
Maybe it'll be clear to change the title as "Use NestedLoopJoin instead of HashJoin/SortMergeJoin for small tables", I'm confused when I saw the PR title first. |
Do we have some benchmark results? |
NestedLoopJoin
NestedLoopJoin
instead of HashJoin
/SortMergeJoin
for small tables
@xudong963 These were tests run with one of the sides having 5 rows: Click to expand
Interesting I noticed I wasn't using a filter for the The reason why |
I'll try to open a pull request later for creating a performance bench file for specifically benchmarking joins. |
Which issue does this PR close?
Rationale for this change
We want to support equijoins in
NestedLoopJoin
in the case where one of the tables in the join is very small.What changes are included in this PR?
I have added a
nested_loop_equijoin_threshold
to theOptimizerOptions
which has a default value of 5 (same as DuckDB, here). This is the threshold for the number of rows that can be in either table so that the physical planner will choose aNestedLoopJoinExec
overSortMergeJoin
andHashJoin
.If either table has less than 5 rows then we will pass the
join_on
expressions to thejoin_filter
.Are these changes tested?
By existing tests