Skip to content

fix(plan): project shared CTE output before publication - #30636

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/4121e6794b89d46023e8c0e62ef58979cbd7e89284d67df963853a587d7414dd
Oct 20, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/4121e6794b89d46023e8c0e62ef58979cbd7e89284d67df963853a587d7414dd

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

The issue remains open after merge for verification by the reporter.

What this PR does / why we need it:

A shared aggregate CTE over (g,h,v)=(1,7,10) can return (1,10,10) instead of (1,7,7) when readers select MAX(h) and omit the preceding SUM(v).

This follows #30145. Readers use the compacted logical SINK schema, but the producer can retain extra computations to preserve their error semantics. Publishing that wider child batch makes a reader fetch SUM at the ordinal intended for MAX.

At the planner's column-remapping boundary, add an explicit PROJECT before a shared CTE SINK when its publication schema differs from the evaluated child. Track the actual shared CTE sinks created by CTE reuse so this projection is paired with positional remapping of all readers. Other sources also use CTESinkOption, including foreign-key maintenance row images; their established layouts must remain intact. The compiler consumes the explicit plan and does not interpret SINK metadata as another executable projection.

Validation on macOS arm64, Go 1.27.1 with the repository CGo test wrapper:

  • Reproduced both failed CI UTs on the original PR head: self-referencing functional-index cascade and repeated-alias cascade/SET NULL updates. All their subcases pass after the fix.
  • A new planner regression fails before the correction on the wider child/compacted SINK mismatch. Planner tests verify published width, identity ordinals and types; compiler tests verify actual values, reordered/narrowed outputs, streaming fallback, child errors, orphan cleanup and non-executable SINK metadata.
  • Complete pkg/sql/plan and pkg/sql/compile packages, focused public SQL integration tests, incremental go vet, configured golangci-lint and formatting checks pass.
  • Normal mo-tester comparison passes twice on the same isolated 1 CN + 1 TN + 1 LogService instance for cte/projection_pruning.sql and all three failed CI SQL files: update_multi_target_modern.sql, fk_issue_26831.sql and update_modern_fk.sql. Database teardown is checked between rounds. CTE cases include distinct SUM/MAX values, asymmetric readers, NULL/empty/multiple groups, prepared reuse, INSERT SELECT and ROLLUP.

Identity layouts need no additional operator. Nonidentity shared CTE layouts reuse the existing projection executor with bounded per-batch column work. No wire or storage format changes. Linux/x64 multi-CN CI will run on the updated head.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 796eed89b5150edcfba98b1a5da9cdd5c17d8e18

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: 796eed89b5150edcfba98b1a5da9cdd5c17d8e18

Review belongs to an older commit; it is not a review of the current head.

@XuPeng-SH XuPeng-SH 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.

mo-bot review · mo-bot-local · review

Commit: 796eed89b5150edcfba98b1a5da9cdd5c17d8e18

Assessment: approve

Reviewed the complete eight-file delta and affected planner/compiler paths. The explicit projection restores shared CTE publication order while preserving required child evaluation and excluding foreign-key row-image sinks. Ownership, cleanup and compatibility remain coherent; no actionable defects found.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Reconciled the frozen head, clean source, complete patch and changed-file fingerprints. Static audit passed: checks/1792489257994951149-3.json and review-audit-v2.log under the assigned attempt directory. The earlier audit failure was solely the exported patch's omitted final newline.

  • Reused exact-head CI snapshot successes for shared build, Ubuntu/x86 UT, Linux/arm64 SCA, UT coverage, Compose PROXY BVT and Compose PESSIMISTIC BVT.

  • Inspected planner schema/ordinal assertions, compiler value and error tests, orphan cleanup, streaming fallback and legacy-sink exclusions. Reviewed SQL/result coverage for distinct SUM/MAX values, asymmetric readers, NULL/empty input, prepared reuse, INSERT SELECT and ROLLUP.

  • Performance tracing found bounded column-projection work only for nonidentity shared CTE layouts; ordinary column vectors are borrowed, and narrowed publication reduces downstream materialization volume. Identity layouts add no operator.

  • Detailed review and evidence reconciliation retained in /home/xupeng/.local/state/mo-bot/jobs/0160ffdc80bd72b7714c102a/attempt-1/review-notes.txt.

Limitations:

  • No fresh Go/native/SQL tests or benchmarks were run. Supplied CI evidence contains terminal summaries rather than individual test logs; author-reported local runs have no retained receipts in local_validation.

  • The linked issue's independent body was not supplied; its behavioral contract was assessed from the frozen PR description and regression SQL.

@mergify mergify Bot added the queued label Oct 20, 2026
@mergify

mergify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-20 09:43 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-20 13:50 UTC · at 8df6e099b056e1e37121e7d10ce07190d6ef8bfd

This pull request spent 4 hours 7 minutes 14 seconds in the queue, with no time running CI.

Reason

Pull request #30636 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@aptend aptend 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.

Deep-reviewed the complete eight-file change at exact head 796eed8 against base/merge-base 309f618, issue #30141 and all review/discussion history. No blocking issue found.

The publication projection is inserted at the remapping owner, after the wider child's required evaluations, and SINK metadata becomes identity references at the compacted width/types. Actual shared-CTE creation, rather than the generic CTESinkOption tag, gates the new operator, preserving foreign-key row-image and recursive/legacy layouts. Traced positional readers, projection removal, compiler consumers, materialized fanout and streaming fallback. Reviewed the independent typed-plan and actual-value/error/orphan tests and all SQL/golden changes.

Lifecycle audit:

Contract Closure
Ownership Projection borrows child vectors; source owns publication clones; merge owns reader clones; executor/source/reader cleanup stays paired.
Wait termination Existing source notification, producer Finish(error), context cancellation and compile-owner close remain reachable; the projection adds no wait.
Bounds New metadata is query-sized, projection is column-bounded, and materialization retains its existing memory/spill admission and release limits.

Reused exact-head terminal evidence after reading raw logs/artifacts: UT 118514406109 and normal coverage 118514409034 pass; SCA 118514408749 reports zero issues. The formerly affected functional-index cascade and repeated-alias cascade/SET NULL public test roots pass. PROXY BVT 118514410162 explicitly reports projection_pruning.sql 53/53, update_multi_target_modern.sql 309/309, fk_issue_26831.sql 36/36, and update_modern_fk.sql 190/190, with no failed/ignored statements. No duplicate local build/test or product edits were needed; author-reported local same-instance reruns are not presented as fresh reviewer executions.

This branch had an error being deployed

1 failed deployment
ci — 8df6e099 Deployed Oct 20, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants