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.
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
Improve TableScan with filters pushdown unparsing (joins) #13132
Improve TableScan with filters pushdown unparsing (joins) #13132
Changes from 2 commits
15d6560
e82340e
774550a
936b076
e560ece
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 noticed you put the pushdown condition in the join condition instead of the
WHERE
. In my opinion, the SQL plan will be different if we sometimes put the condition in a different place.I did some tests for different join type and different place (join condition or filter) in DataFusion
The result is
We can find the plan is the same in
inner join
andleft join
. The filter pushdown works fine. However, inright join
andfull join
cases, if we put the predicate in the join condition, the filter pushdown doesn't work.In the DataFusion case, the filter pushdown always works when putting the filter in
WHERE
.I'm not pretty sure if it's a common rule (putting the predicate in
WHERE
is better) for the other database. However, in the DataFusino case, we're better to put them inWHERE
.By the way, this PR is ok for me now. I think it can be improved by a follow-up PR if we care about the performance of the generated SQL.
cc @alamb @phillipleblanc
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.
@goldmedal - thank you for deep review. I suspect that filters were not fully pushed down for the right join and full join cases by DF during optimization for samples above as two test queries are not exactly the same as how records are filtered:
It seems in all examples above the original
WHERE
was moved inside Join by optimizer (all cases), so optimized plan should be unparsed as below for right join, for exampleselect o_orderkey from orders right join (select c_custkey from customer where c_name = 'Customer#000000001') on o_custkey = c_custkey
and we will translate it to
@goldmedal - Is my understanding correct that tha main concern is that the first option is preferred as it could be executed more efficient by target engine?
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.
Yes, if we can push down the predicate to the table scan, it usually means it will perform better.
I tried the subquery pattern:
Every predicate is pushed down to the table scan. It's better 👍
I haven't checked the planner of other databases but I think they're similar.
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.
@sgrebnov Do you want to improve it in this PR? or we can do it in the follow-up PR (maybe file an issue). WDYT?
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.
@goldmedal - I would prefer the incremental approach with a follow-up PR. Thank you!