You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem or challenge?
One case where pushing down sorts is when the sort has a fetch (aka TopK).
This will result in less input to the join, so the join will execute faster / with less memory usage.
Describe the solution you'd like
Push down sorts with fetch for joins is (at least) possible when there is no join filter and:
When sort expression is based on columns on the left side and type is left join
When sort expression is based on columns on the right side and type is right join.
We should still keep the final sort on top of the result as not all planned join types will preserve the input ordering.
As we have the TopK as input for join, the resulting. The other optimization rules might remove the final sort if the physical join does in fact preserve the ordering (e.g. right joins and others).
Thank you @Dandandan I think it’s a good idea.
I’m wondering that can this works with WHERE clause or some edge cases like sorts tie-breaking or null column handling? Will it have same results cardinality before and after the optimization?
Activity
[-]Push down sort with `fetch` after join[/-][+]Push down TopK below Join[/+]austin362667 commentedon Sep 29, 2024
Thank you @Dandandan I think it’s a good idea.
I’m wondering that can this works with WHERE clause or some edge cases like sorts tie-breaking or null column handling? Will it have same results cardinality before and after the optimization?
test: benchmarks and SLT tests for push-down TopK through join (apach…
Push down topk through join (apache#21621)
Push down topk through join (apache#21621)