Skip to content

[SQL] Retry compiling a query with CTEs by converting CTEs to local views - #6836

Merged
mihaibudiu merged 1 commit into
feldera:mainfrom
mihaibudiu:issue6827
Aug 10, 2026
Merged

[SQL] Retry compiling a query with CTEs by converting CTEs to local views#6836
mihaibudiu merged 1 commit into
feldera:mainfrom
mihaibudiu:issue6827

Conversation

@mihaibudiu

@mihaibudiu mihaibudiu commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

A query containing CTEs such as

CREATE VIEW V AS 
WITH e AS (SELECT ...)
SELECT ... FROM e;

Is compiled by Calcite into a single complex plan, which sometimes can stump the decorrelator.

This PR introduces a retry phase: if decorrelation of this plan fails, the query is rewritten as

CREATE LOCAL VIEW e AS (SELECT ...);
CREATE VIEW V AS
SELECT ... FROM e;

This is compiled into TWO separate queries, which are decorrelated and optimized separately. Sometimes the decorrelator can cope with the simpler queries.

…iews

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu
mihaibudiu added this pull request to the merge queue Aug 10, 2026
Merged via the queue into feldera:main with commit 33c5ffd Aug 10, 2026
1 check passed
@mihaibudiu
mihaibudiu deleted the issue6827 branch August 10, 2026 19:10
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.

2 participants