[fix](fe) Merge one row union outputs by slots#64906
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: MergeOneRowRelationIntoUnion previously built constant rows by matching one-row child projects to UNION outputs by list index. When a UNION child output used a different position or fewer columns than the one-row child projects, the rewrite could read past the UNION output list or place the wrong constant into the UNION constant expression list. The fix builds a slot-to-expression map from the one-row child and rewrites each regular child output expression through that map, preserving the UNION child output order and cardinality.
### Release note
Fix incorrect results or failures for UNION ALL constant queries whose one-row child output order differs from the UNION output order.
### Check List (For Author)
- Test: Regression test / Unit Test
- ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.MergeOneRowRelationIntoUnionTest
- ./run-regression-test.sh --run -d query_p0/compress_materialize -s compress_materialize -forceGenOut
- Behavior changed: Yes (fixes UNION constant-row rewrite to follow child output mapping instead of project indexes)
- Does this need documentation: No
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
/review |
|
run buildall |
There was a problem hiding this comment.
Review summary: I did not find a blocking correctness issue in the PR-scoped diff.
Critical checkpoint conclusions:
- Goal and proof: The change addresses the stated UNION constant-row ordering bug by deriving merged constant rows from
regularChildrenOutputsinstead of one-row project indexes. The new unit test covers a one-row child with extra projects and a selected second slot; the regression test covers compressed-materialize UNION ALL grouping/project-order cases. - Scope and clarity: The implementation is small and focused on
MergeOneRowRelationIntoUnion; test changes are limited to the affected Nereids rule and regression suite. - Optimizer semantics and parallel paths: I checked
BindExpression.bindSetOperation,PushProjectThroughUnion,ProjectMergeable/PlanUtils.mergeProjections,PushDownEncodeSlot, and physical UNION translation. The child-output slots remain ExprId-compatible with merged one-row aliases, so the replacement map preserves output order and cast/project aliases. - Concurrency, lifecycle, persistence, compatibility, FE-BE protocol, and configuration: Not materially involved; no new config, protocol field, storage format, transaction path, or threaded lifecycle is introduced.
- Tests and expected results: The new
order_qt_const_union_*labels match the updated.outsections, use ordered output capture, and the removedexplain_sort_agg/exec_sort_aggblocks are stale relative to the current suite.git diff --checkpasses for the four PR files. - Performance and observability: The added per-child map is bounded by the one-row project count and is not a hot runtime path; no extra observability is needed for this planner rewrite.
User focus: No additional user-provided review focus was present.
Subagent conclusions: optimizer-rewrite and tests-session-config both reported no candidates in the initial pass. After the main ledger recorded dismissed points and an empty inline-comment set, both subagents replied NO_NEW_VALUABLE_FINDINGS in convergence round 1.
Validation limit: I did not rerun FE UT or regression tests in this runner because thirdparty/installed and thirdparty/installed/bin/protoc are absent; this matches the local validation limit recorded in the ledger.
No inline review comments were submitted.
TPC-H: Total hot run time: 28787 ms |
TPC-DS: Total hot run time: 171684 ms |
ClickBench: Total hot run time: 25.04 s |
FE Regression Coverage ReportIncrement line coverage |
What problem does this PR solve?
Issue Number: None
Related PR: #24060
Problem Summary: MergeOneRowRelationIntoUnion previously built constant rows by matching one-row child projects to UNION outputs by list index. When a UNION child output used a different position or fewer columns than the one-row child projects, the rewrite could read past the UNION output list or place the wrong constant into the UNION constant expression list. The fix builds a slot-to-expression map from the one-row child and rewrites each regular child output expression through that map, preserving the UNION child output order and cardinality.
Release note
Fix incorrect results or failures for UNION ALL constant queries whose one-row child output order differs from the UNION output order.
Check List (For Author)