Repository navigation
branch-4.1: [fix](rbo) Preserve union constant rows across rewrites #67790 - #68172
Merged
Merged
Conversation
## Problem A UNION ALL could lose constant rows when a later rewrite exposed another one-row child. Queries that combine an existing constant branch with a single-row GROUP BY or DISTINCT branch returned only the newly exposed row. ## Root cause MergeOneRowRelationIntoUnion rebuilt the union constant-expression list from only the current children. If an earlier rewrite pass had already moved a constant child into the union metadata, a later pass replaced that metadata instead of retaining it. ## Reproduction ```sql SELECT 1 AS c UNION ALL SELECT c FROM (SELECT 2 AS c) s GROUP BY c; ``` The result incorrectly omitted the row containing 1. The same behavior occurred with DISTINCT and with the branches reversed. ## Fix Seed the rebuilt constant-expression list with the union existing constant rows before appending newly converted one-row children. This preserves row multiplicity across repeated rewrite passes. Add a focused rewrite unit test and named regression queries with runner-generated golden output for GROUP BY, DISTINCT, reversed branch order, and duplicate constant rows. ## Tests - `SetOperationOutputMappingTest`: 4 tests passed - `merge_one_row_relation_into_union`: named golden regression passed in both force-generation and normal comparison modes - Full FE build with UI disabled: passed - Checkstyle: passed
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
yiguolei
approved these changes
Sep 19, 2026
Contributor
Author
|
PR approved by anyone and no changes requested. |
Contributor
Author
|
PR approved by at least one committer and no changes requested. |
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.
Cherry-picked from #67790