Skip to content

branch-4.1: [fix](fe) Preserve CTE column order for repeated slots (branch-4.1) - #69676

Merged
yiguolei merged 1 commit into
apache:branch-4.1from
924060929:codex/fix-cte-column-order-41
Oct 28, 2026
Merged

yiguolei merged 1 commit into
apache:branch-4.1from
924060929:codex/fix-cte-column-order-41

Conversation

@924060929

@924060929 924060929 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

cherry pick from #69388

### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#69388

Problem Summary: A CTE selecting a key, a payload and the same key exposes
[x,z,y] instead of [x,y,z] because the reverse producer-to-consumer multimap
groups repeated producer ExprIds. Derive output positions from the ordered
consumer-to-producer map and preserve entry order through nullability and
variant subpath rewrites. Carry only this independent CTE repair to 4.1;
leave USING binding unchanged and use the branch-native FE result API.

### Release note

Preserve CTE result column positions when a source column appears more
than once in its output.

### Check List (For Author)

- Test: Unit Test
    - Reproduced the original column-order failure before the repair.
    - 31 focused FE tests passed; retry the pruning fixture after a random
      HTTP-port collision at startup.
    - FE server build with DISABLE_BUILD_UI=ON, Checkstyle and diff checks.
    - No BE execution or full regression suite was run locally.
- Behavior changed: Yes, repeated CTE columns retain their positions.
- Does this need documentation: No
@924060929
924060929 requested a review from yiguolei as a code owner October 27, 2026 07:49
@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?

@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@924060929 924060929 changed the title [fix](fe) Preserve CTE column order for repeated slots (branch-4.1) branch-4.1: [fix](fe) Preserve CTE column order for repeated slots (branch-4.1) Oct 27, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all five changed files at b72cb88. No actionable correctness issue found and no existing blocking inline findings to retain. Review converged in two rounds, including independent ordering/execution, nullable/test, and additional ordered-map/variant risk reviews.

The forward consumer map preserves x/y/z positions for producer outputs a/b/a. Nullability reconstruction retains each consumer identity, and variant expansion preserves original keys and relative order. Copies, pruning, expression/type rewrites, CTE inlining and materialized translation preserve this invariant; physical translation resolves producer/consumer ExprIds rather than pairing reverse-map values by position.

Critical checkpoint conclusions:

  1. Goal and proof: the added analysis test asserts names x/y/z and the FE-computed row (1,10,1); direct consumer tests cover repeated slots, copies, pruning and nullable propagation. These tests were inspected, not executed.
  2. Scope and clarity: three focused production changes with two test files; the partial backport stays within CTE ordering and leaves branch-native USING binding unchanged.
  3. Concurrency and locking: local map builders and immutable plan snapshots introduce no new shared state, threads, locks, expensive critical sections or lock-order change.
  4. Lifecycle and initialization: no new resources, callbacks, ownership cycles or static initialization dependencies; existing property-copy behavior remains consistent.
  5. Configuration: none added or altered.
  6. Compatibility: no public symbol, persisted/storage format or protocol changes requiring rolling-upgrade handling.
  7. Thrift/protobuf: no changed definitions; cross-release field/enum comparison is inapplicable.
  8. Parallel paths: inline/materialized consumers, deep copies, output pruning, expression/type replacement, nested pruning and optimizer-created CTEs were traced; all applicable forward-map rebuilds preserve order.
  9. Conditional checks: existing variant guards and nullable debug checks remain intact; no new special condition needs justification.
  10. Test coverage: focused JUnit5 assertions cover the reported scalar ordering trigger and plan transformations; existing analysis negatives and nested/variant fixtures were also inspected. No added regression directly covers BE-executed materialized repeated outputs or combined nested/repeated variant ordering.
  11. Expected results: x/y/z, the row (1,10,1), pruned y/z and nullable true/false/true agree with the SQL and fixtures. No golden output file changes.
  12. Observability and errors: no new distributed operation or failure path requires logs/metrics; existing invariant/error handling remains in place.
  13. Transactions and persistence: no EditLog, commit/publish, metadata persistence or failover path changed.
  14. Data writes and crash safety: no storage mutation, transaction atomicity or resource-acquisition path changed.
  15. FE/BE variables: none added; existing translation preserves producer/consumer identity and matching projection/tuple order.
  16. Performance: consumer reconstruction is linear and removes repeated reverse-group visits for duplicate producers; ordered-map overhead is bounded per entry.
  17. Other invariants: slot identity/metadata, property copies, map equality and generated subpath slots were checked without finding another defect. Committed-data visibility, versions, delete bitmaps and BE memory accounting are unaffected.

No additional user focus was supplied. No unresolved code question or uncovered changed-file scope remains. Validation limits: static source review only; no builds, tests, benchmarks or BE execution were run, and no submodules were initialized. The absent direct execution cases above limit validation breadth and are not evidence of a verified bug.

Review converged after 2 round(s).

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 2.37% (9/379) 🎉
Increment coverage report
Complete coverage report

@924060929

Copy link
Copy Markdown
Contributor Author

run feut

@924060929

Copy link
Copy Markdown
Contributor Author

run cloud_p0

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (9/9) 🎉
Increment coverage report
Complete coverage report

@yiguolei
yiguolei merged commit 2769895 into apache:branch-4.1 Oct 28, 2026
43 of 45 checks passed
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.

3 participants