refactor(query): decouple logical optimization from physical planning - #20604
Open
forsaken628 wants to merge 4 commits into
Open
forsaken628 wants to merge 4 commits into
forsaken628 wants to merge 4 commits into
Conversation
Keep logical preparation on SExpr and extract selected implementations as an independent PExpr tree. Migrate physical passes and recursive builders in place without changing their algorithms or execution order. Separate bound and planned query/mutation lifecycles, apply physical EvalScalar cleanup directly, and retain mutation distribution policy on the physical tree. Remove reverse expression conversion and obsolete logical-pipeline Memo capture. Include lifecycle, expression-fork, cleanup, mutation and plan-golden regression coverage with the final interfaces, without intermediate wrapper/pass designs.
Read lineage for planned queries and mutations only from binding-time snapshots. Return no lineage when a planned statement has no snapshot, rather than attempting to reconstruct SQL dependencies from an execution tree. Keep direct extraction for bound statements and cover snapshot/no-snapshot behavior for INSERT, CTAS, multi-table INSERT, UPDATE and DELETE.
forsaken628
force-pushed
the
refactor-mut
branch
from
October 1, 2026 11:18
555cbad to
a0c79dc
Compare
forsaken628
marked this pull request as ready for review
October 1, 2026 15:32
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Previously, a single
SExprrepresentation andSExpr → SExproptimizer interface tied frontend logical rewrites to CBO and physical-plan finalization. Logical semantics and execution-stage concerns shared the samecontract, making maintenance difficult and constraining how CBO could evolve to model physical implementations.
This PR separates those stages without changing the existing search and costing algorithms:
SExpr, and introduce a separate physical-planning entry that consumesSExprand producesPExpr.PExpr, with no reverse conversion toSExpr.This establishes an independently evolvable physical representation. It does not yet introduce new physical implementation alternatives or change the CBO cost model.
Tests
Type of change
AI assistance
This change is