morrySnow opened a new pull request, #67790:
URL: https://github.com/apache/doris/pull/67790

   ## 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 regression coverage for GROUP BY, 
DISTINCT, reversed branch order, and duplicate constant rows.
   
   ## Tests
   
   - SetOperationOutputMappingTest: 4 tests passed
   - merge_one_row_relation_into_union regression suite: passed
   - Full FE build with UI disabled: passed
   - Checkstyle: passed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to