Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Outer to Inner join optimization doesn't work #24718

Open
pydima opened this issue Jan 15, 2025 · 1 comment
Open

Outer to Inner join optimization doesn't work #24718

pydima opened this issue Jan 15, 2025 · 1 comment

Comments

@pydima
Copy link

pydima commented Jan 15, 2025

If I have a query like that:
SELECT "a"."ca_state" AS "STATE", "c"."c_customer_sk", "c"."c_current_addr_sk", "s"."ss_customer_sk", "s"."ss_sold_date_sk", "s"."ss_item_sk" FROM customer_address a LEFT JOIN customer c ON "a"."ca_address_sk" = "c"."c_current_addr_sk" INNER JOIN store_sales s ON "c"."c_customer_sk" = "s"."ss_customer_sk"

There would be a tree where inner join is on top of left join. Since inner join would filter out all null records it's safe to convert left join to inner join. The problem is that PredicatePushDown would do this optimization only if dynamic filtering is enabled. It seems wrong, since there is no need of dynamic filtering to figure out that we can convert this join. The problem in the code is that Trino doesn't push down join condition if dynamic filtering is disabled. Here is the relevant piece of code: https://github.com/trinodb/trino/blob/master/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/PredicatePushDown.java#L525C84-L525C99 . I wonder, is it done on purpose or it's a bug?

@raunaqmorarka
Copy link
Member

This is probably the same issue as #2392
We have tried adding and pushing down IS NOT NULL predicate for INNER JOINs before #3688 and #2415
It didn't give much benefits overall.
Dynamic filter functions happen to filter nulls most of the time and influence optimizer decisions like whether LEFT join can be converted to INNER and also help in filtering nulls on the probe side scan.
There is no practical reason to turn off dynamic filtering, so there hasn't been a need to do this optimization separately.
cc: @sopel39

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

2 participants