Skip to content

Conversation

kryonix
Copy link
Contributor

@kryonix kryonix commented Apr 29, 2025

This PR implements the recently published version of @neumannt's query unnesting strategy "Improving Unnesting of Complex Queries"—which is an updated version of "Unnesting Arbitrary Queries".

Why do we want this? Separation of concerns and phase separation. With bottom-up decorrelation, we never fully algebraize plans containing (nested) subqueries into a logical plan—possibly containing DEPENDENT_JOINS. This results in problems trying to decorrelate complex SQL constructs such as recursive CTEs (see #13404). With this PR, that changes. Subqueries are fully algebraized, before entering a single decorrelation pass. This potentially provides optimization opportunities, that would not have been possible before.


Fix: #15307
Fix: #15483

kryonix added 2 commits April 29, 2025 11:41
Do not blindly mark all CTE scans as correlated.
This is no longer a valid assumption.
@duckdb-draftbot duckdb-draftbot marked this pull request as draft April 29, 2025 09:50
@kryonix kryonix marked this pull request as ready for review April 29, 2025 09:51
@Mytherin
Copy link
Collaborator

Thanks! Looks great - amazing that you got this to work :)

@Mytherin Mytherin merged commit 4e7d003 into duckdb:main Apr 30, 2025
47 of 49 checks passed
@arjenpdevries
Copy link
Contributor

For future reference: the BTW 2025 paper introducing the method.

krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 18, 2025
Switch from Bottom-Up to Top-Down Decorrelation Strategy (duckdb/duckdb#17294)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 18, 2025
Switch from Bottom-Up to Top-Down Decorrelation Strategy (duckdb/duckdb#17294)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 19, 2025
Switch from Bottom-Up to Top-Down Decorrelation Strategy (duckdb/duckdb#17294)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

internal error with recursive SQL query INTERNAL Error: Attempted to access index 5 within vector of size 5
3 participants