Uh oh!
There was an error while loading. Please reload this page.
[fix](rbo) Rewrite LogicalGenerate lateral conjuncts together with generators - #66803
Merged
Conversation
…erators ### 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
requested review from
924060929, morrySnow and starocean999
as code ownersAugust 16, 2026 04:45
hello-stephen
commented
Aug 16, 2026
Contributor
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
16 tasks
englefly
commented
Aug 16, 2026
ContributorAuthor
run buildall |
hello-stephen
commented
Aug 16, 2026
Contributor
FE UT Coverage ReportIncrement line coverage |
hello-stephen
commented
Aug 16, 2026
Contributor
TPC-H: Total hot run time: 17748 ms |
hello-stephen
commented
Aug 16, 2026
Contributor
TPC-DS: Total hot run time: 85219 ms |
hello-stephen
commented
Aug 16, 2026
Contributor
ClickBench: Total hot run time: 14.5 s |
hello-stephen
commented
Aug 16, 2026
Contributor
FE Regression Coverage ReportIncrement line coverage |
englefly added a commit
that referenced
this pull request
Aug 17, 2026
…rapping (#64849) ### What problem does this PR solve? When a group-by key is functionally dependent on another key (e.g. s_suppkey -> s_name via PK) but required in output, remove it from GROUP BY and wrap with ANY_VALUE(). Previously EliminateGroupByKey kept such keys in GROUP BY to preserve SQL semantics. Now they are replaced with ANY_VALUE wrappers in the output, allowing the group-by set to be minimized while keeping the column in SELECT. Public findCanBeRemovedExpressions() API preserved for backward compatibility. Internal logic split into FindResult with separate removeExpression and wrapWithAnyValue sets. Test: testEliminateByPkWithOutputNeeded verifies ANY_VALUE wrapping when SELECT contains an FD-redundant group-by key. Issue Number: close #xxx Related PR: #65982#66801#66803 上面 3 个 pr 是原有 master 的bug fix. pick 这个 pr 前, 确保上面 3 个 pr 已经 pick Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
morrySnow
approved these changes
Aug 17, 2026
Contributor
PR approved by at least one committer and no changes requested. |
Contributor
PR approved by anyone and no changes requested. |
englefly
commented
Aug 18, 2026
ContributorAuthor
run feut |
Uh oh!
There was an error while loading. Please reload this page.
github-actionsBot
pushed a commit
that referenced
this pull request
Aug 21, 2026
…nerators (#66803) ### 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: ```text Generate[UNNEST(tags#T2), ON tag#G = name#N] // name#N is stale after the child outputs name#N2 Project[..., name#N2, ...] Aggregate[..., ANY_VALUE(name)#N2, ...] ``` 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 <!-- At least one of them must be included. --> - [x] 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: <old id>`). - Full `GenerateConjunctRewriteTest` / `EliminateGroupByKeyByUniformTest` / `MergeGeneratesTest` / `FdTest` classes are green. - [ ] Regression test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - Behavior changed: - [x] No. - [ ] Yes. <!-- Explain the behavior change --> Internal correctness fix for plan rewriting; no intended plan-shape or performance change. - Does this need documentation? - [x] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
morrySnow pushed a commit
that referenced
this pull request
Aug 31, 2026
…nerators (#66803) ### 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: ```text Generate[UNNEST(tags#T2), ON tag#G = name#N] // name#N is stale after the child outputs name#N2 Project[..., name#N2, ...] Aggregate[..., ANY_VALUE(name)#N2, ...] ``` 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 <!-- At least one of them must be included. --> - [x] 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: <old id>`). - Full `GenerateConjunctRewriteTest` / `EliminateGroupByKeyByUniformTest` / `MergeGeneratesTest` / `FdTest` classes are green. - [ ] Regression test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - Behavior changed: - [x] No. - [ ] Yes. <!-- Explain the behavior change --> Internal correctness fix for plan rewriting; no intended plan-shape or performance change. - Does this need documentation? - [x] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
yiguolei pushed a commit
that referenced
this pull request
Sep 5, 2026
…nerators (#66803) ### 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: ```text Generate[UNNEST(tags#T2), ON tag#G = name#N] // name#N is stale after the child outputs name#N2 Project[..., name#N2, ...] Aggregate[..., ANY_VALUE(name)#N2, ...] ``` 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 <!-- At least one of them must be included. --> - [x] 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: <old id>`). - Full `GenerateConjunctRewriteTest` / `EliminateGroupByKeyByUniformTest` / `MergeGeneratesTest` / `FdTest` classes are green. - [ ] Regression test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - Behavior changed: - [x] No. - [ ] Yes. <!-- Explain the behavior change --> Internal correctness fix for plan rewriting; no intended plan-shape or performance change. - Does this need documentation? - [x] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
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 freeto 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.
What problem does this PR solve?
Problem Summary:
GenerateExpressionRewriterewrote onlyLogicalGenerate.getGenerators()and rebuilt the node viawithGenerators(), which preserved the lateral ON conjuncts unchanged. Whole-tree ExprId replacements (e.g.any_valuewrapping of a group-by key inEliminateGroupByKeyByUniform/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:
GenerateExpressionRewritenow rewritesgetConjuncts()in the same operation and rebuilds the node with a newLogicalGenerate.withGeneratorsAndConjuncts()helper, so generators and lateral ON conjuncts stay consistent under any expression rewrite.Release note
None
Check List (For Author)
Test
GenerateConjunctRewriteTest.testExprIdRewriterRewritesLateralConjuncts: builds aLogicalGeneratewith a conjunct referencing a slot, runsExprIdRewriterwith an old->new ExprId map and asserts the conjunct is rewritten (fails on the old code:expected: 999 but was: <old id>).GenerateConjunctRewriteTest/EliminateGroupByKeyByUniformTest/MergeGeneratesTest/FdTestclasses are green.Behavior changed:
Internal correctness fix for plan rewriting; no intended plan-shape or performance change.
Does this need documentation?
Check List (For Reviewer who merge this PR)