Skip to content

branch-4.1 [fix](rbo) Rewrite LogicalGenerate lateral conjuncts together with generators - #67399

Draft
englefly wants to merge 1 commit into
apache:branch-4.1from
englefly:pick-66803-4.1
Draft

branch-4.1 [fix](rbo) Rewrite LogicalGenerate lateral conjuncts together with generators#67399
englefly wants to merge 1 commit into
apache:branch-4.1from
englefly:pick-66803-4.1

Conversation

@englefly

@englefly englefly commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick of #66803 to branch-4.1

fix Rewrite LogicalGenerate lateral conjuncts together with generators

…er with generators

### What problem does this PR solve?

Problem Summary:

GenerateExpressionRewrite rewrote only LogicalGenerate.getGenerators() and
rebuilt the node via withGenerators(), which preserved the lateral ON
conjuncts unchanged. Whole-tree ExprId replacements (e.g. any_value wrapping
of a group-by key in EliminateGroupByKeyByUniform / EliminateGroupByKey) that
renamed a slot referenced by an ON conjunct therefore left the conjunct with a
stale ExprId after the child switched to the wrapped slot, and final slot
validation rejected the query.

Fix: GenerateExpressionRewrite now rewrites getConjuncts() in the same
operation and rebuilds the node with a new
LogicalGenerate.withGeneratorsAndConjuncts() helper, so generators and lateral
ON conjuncts stay consistent under any expression rewrite.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - New GenerateConjunctRewriteTest.testExprIdRewriterRewritesLateralConjuncts:
      builds a LogicalGenerate with a conjunct referencing a slot, runs
      ExprIdRewriter with an old->new ExprId map and asserts the conjunct is
      rewritten (fails on the old code: expected 999 but was the old id).
    - Full GenerateConjunctRewriteTest / EliminateGroupByKeyByUniformTest /
      MergeGeneratesTest / FdTest classes are green.
- Behavior changed: No. Internal correctness fix for plan rewriting; no
  intended plan-shape or performance change.
- Does this need documentation: No
@englefly

englefly commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

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