Skip to content

fix: preserve set-operation columns through remapping - #30028

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-29989-set-operation-remap
Oct 13, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-29989-set-operation-remap

Conversation

@XuPeng-SH

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:

Fixes #29989
Fixes #30007

Related: #30010. This fixes the malformed string-vector query trigger; generic protocol recovery after an internal error is separately scoped.

What this PR does / why we need it:

Set-operation outputs describe left operand columns, so normal expression counts cannot discover right operand positional demands. Filter pushdown can wrap an operand PROJECT, bypassing the previous direct-PROJECT retention logic. This produces both explicit width errors and equal-width wrong values (SUM returns 12 instead of 30), including persisted INSERT SELECT/CTAS output.

  • Preserve the existing operand projection boundary through untagged identity FILTER/ASSERT/SORT/PARTITION wrappers.
  • Retain corresponding original positions on both operands, balance temporary edge demands, and check both returned remapping maps.
  • Reuse correctly aligned inputs. Add an ordinary local projection only when an edge needs to select/reorder already evaluated vectors; inner DISTINCT/INTERSECT/EXCEPT keep their complete equality tuples. Keep common type/nullability and physical equality-key remapping aligned.
  • Preserve branch side effects through aliases inside expressions. Bound alias analysis with a temporary per-operation memo; conservatively retain cyclic or unresolved lineage. No persistent state or additional executor path.
  • Reuse the existing planner and canonical one-CN SQL fixtures. Regression oracles cover exact numeric/string results, membership, NULL, CTE/window, prepared reuse across empty input, persisted writes and exactly-once sequence effects. Internal tests cover nonidentity alignment, invalid maps and repeated-alias complexity.

Validation

Baseline and final validation: macOS ARM64, Go 1.27.1, matching CPU native dependencies. Baseline reproduces direct/prepared projection-width errors and SUM=12; unfiltered SUM control returns 30.

  • Final owning planner and explain normal suites passed (-count=1).
  • Final public SQL regression passed through a real MySQL connection.
  • Final focused race covers new tests and affected pruning, rollup/window, nullability and CHAR/equality controls plus public SQL (-race -count=1).
  • Incremental gofmt/diff, repository molint vet and pinned golangci-lint checks cover the complete four-file package/consumer closure.
  • Required actual gpt-6.1-sol / xhigh design and overall review: the confirmed repeated-alias performance finding is corrected and independently re-reviewed.

Performance and scope

Preserves UNION ALL column pruning and joint row-carrier selection. Common aligned inputs add no runtime projection. Alias analysis visits each logical owner/ordinal once per operation, with no cross-query cache. Membership inputs are projected only after complete tuple evaluation. No format or CI changes. Public proof uses one CN; multi-CN behavior and remote CI are not claimed validated.

@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 12, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: cd7676bef69a2d61a54e1715b09604c0dbe8ec9b

Assessment: request_changes

Reviewed the complete four-file delta and affected owners. The positional alignment fix is coherent, but the new alias guard regresses pruning of unused aggregate results in ordinary UNION ALL queries.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P2 pkg/sql/plan/query_builder.go:1113: With t(v INT) and t2(v INT), plan SELECT c FROM (SELECT COUNT() c, SUM(v) s FROM t UNION ALL SELECT COUNT(), SUM(v) FROM t2) u.
    Impact: The unused SUM(v) remains live in both branches, retaining aggregate computation and input-column reads that the baseline eliminates. Preserve the existing aggregate owner's pruning responsibility and add a regression covering unused aggregate outputs across UNION ALL.
    Evidence: Node_AGG reaches this default branch and returns false, causing remapSetOperation to pin the unused position. PROJECT then propagates that demand into AggList. The unchanged aggregate remapper already removes pure unused aggregates while independently retaining side effects. A source-extracted helper probe confirmed that the formerly prunable aggregate alias is now retained; the table-scan control remains prunable.

Validation:

  • Verified exact HEAD, merge-base, clean source and frozen patch correspondence; whitespace and Go formatting checks passed.

  • Traced operand boundaries, balanced temporary demands, alignment projections, equality keys, nullability, alias memoization and test cleanup.

  • Compared aggregate pruning against the merge-base and ran a bounded standalone helper probe; diagnostic results are recorded in the job directory.

  • Reviewed author-reported planner/explain, public SQL, race and static validation. Substantive CI remained pending in the frozen snapshot.

Limitations:

  • The counterexample was established through source tracing and helper execution, not a production BuildPlan or live SQL run; no runtime slowdown measurement is claimed.

  • Local native tests were not run. Linked issue bodies and raw author test logs were not supplied.

  • Public execution evidence is author-reported and limited to one CN; multi-CN execution and generic protocol recovery were not validated.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: cd7676bef69a2d61a54e1715b09604c0dbe8ec9b

Assessment: request_changes

Reviewed the complete four-file delta and affected owners. The positional alignment fix is coherent, but the new alias guard regresses pruning of unused aggregate results in ordinary UNION ALL queries.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P2 pkg/sql/plan/query_builder.go:1113: With t(v INT) and t2(v INT), plan SELECT c FROM (SELECT COUNT() c, SUM(v) s FROM t UNION ALL SELECT COUNT(), SUM(v) FROM t2) u.
    Impact: The unused SUM(v) remains live in both branches, retaining aggregate computation and input-column reads that the baseline eliminates. Preserve the existing aggregate owner's pruning responsibility and add a regression covering unused aggregate outputs across UNION ALL.
    Evidence: Node_AGG reaches this default branch and returns false, causing remapSetOperation to pin the unused position. PROJECT then propagates that demand into AggList. The unchanged aggregate remapper already removes pure unused aggregates while independently retaining side effects. A source-extracted helper probe confirmed that the formerly prunable aggregate alias is now retained; the table-scan control remains prunable.

Validation:

  • Verified exact HEAD, merge-base, clean source and frozen patch correspondence; whitespace and Go formatting checks passed.

  • Traced operand boundaries, balanced temporary demands, alignment projections, equality keys, nullability, alias memoization and test cleanup.

  • Compared aggregate pruning against the merge-base and ran a bounded standalone helper probe; diagnostic results are recorded in the job directory.

  • Reviewed author-reported planner/explain, public SQL, race and static validation. Substantive CI remained pending in the frozen snapshot.

Limitations:

  • The counterexample was established through source tracing and helper execution, not a production BuildPlan or live SQL run; no runtime slowdown measurement is claimed.

  • Local native tests were not run. Linked issue bodies and raw author test logs were not supplied.

  • Public execution evidence is author-reported and limited to one CN; multi-CN execution and generic protocol recovery were not validated.

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · superseded

Commit: cd7676bef69a2d61a54e1715b09604c0dbe8ec9b

new same-head PR feedback/CI evidence requires a fresh task

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · done

Commit: cd7676bef69a2d61a54e1715b09604c0dbe8ec9b

Approved the exact committed candidate. All prior material findings are resolved, required validation is complete, and no unresolved blocker remains.

Verified commit: 9d82a71; fresh CI is pending

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 9d82a7119f0424a1a1d0e4c292e6ea3006adcdac

Assessment: request_changes

Reviewed the complete five-file delta and affected owners. Positional alignment and the prior aggregate-pruning concern are addressed, but the new alias guard regresses external-column pruning.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

  • P2 pkg/sql/plan/query_builder.go:1106: For external table ext(a INT,b INT), execute SELECT a FROM (SELECT a,b FROM ext UNION ALL SELECT a,b FROM ext) u. Column b is unused.
    Impact: EXTERNAL_SCAN falls through the new whitelist and returns false, forcing b to survive in both operands. This adds unnecessary conversion and materialization. With CSV row '1,notanint', it also introduces a conversion failure for a column the baseline prunes.
    Evidence: The source-extracted guard probe returned baselineCanPrune=true/headCanPrune=false for an external ColRef (exit 0). Production-source tracing confirms remapSetOperation pins that ordinal, PROJECT propagates its demand, and the scan retains b. compile/operator.go:1486 creates its attribute; external.go:1575/1765 converts it and rejects 'notanint'. Preserve ordinary external-column pruning and add planner/public-SQL coverage. Probe and reproduction artifacts: alias-probe.log and external-pruning-repro.sql.

Validation:

  • Verified assigned HEAD, clean source and exact frozen-patch equality. Reviewed all changed hunks, remapping owners, projection consumers, failure cleanup and tests.

  • Checked every frozen comment/review. The previous aggregate-pruning finding is addressed by existing owner delegation and targeted planner/SQL cases.

  • Reused author-reported final-revision planner/explain suites, targeted race coverage, one-CN MySQL regression and incremental static checks. Substantive frozen CI checks remain pending.

  • Executed the bounded source-extracted alias-guard probe successfully. Saved detailed evidence and extraction provenance in the attempt directory; source remains unchanged.

Limitations:

  • The external-scan SQL reproduction was not executed locally. Native provenance verification failed because the retained artifact stamp is missing; no native tests were run. The finding rests on the guard probe and production-source tracing.

  • Author validation was not independently rerun; multi-CN behavior and quantitative performance were not measured.

  • Linked-issue bodies were absent from frozen evidence; requirements were checked against the supplied PR description and comments.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 9d82a7119f0424a1a1d0e4c292e6ea3006adcdac

Assessment: request_changes

Reviewed the complete five-file delta and affected owners. Positional alignment and the prior aggregate-pruning concern are addressed, but the new alias guard regresses external-column pruning.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

  • P2 pkg/sql/plan/query_builder.go:1106: For external table ext(a INT,b INT), execute SELECT a FROM (SELECT a,b FROM ext UNION ALL SELECT a,b FROM ext) u. Column b is unused.
    Impact: EXTERNAL_SCAN falls through the new whitelist and returns false, forcing b to survive in both operands. This adds unnecessary conversion and materialization. With CSV row '1,notanint', it also introduces a conversion failure for a column the baseline prunes.
    Evidence: The source-extracted guard probe returned baselineCanPrune=true/headCanPrune=false for an external ColRef (exit 0). Production-source tracing confirms remapSetOperation pins that ordinal, PROJECT propagates its demand, and the scan retains b. compile/operator.go:1486 creates its attribute; external.go:1575/1765 converts it and rejects 'notanint'. Preserve ordinary external-column pruning and add planner/public-SQL coverage. Probe and reproduction artifacts: alias-probe.log and external-pruning-repro.sql.

Validation:

  • Verified assigned HEAD, clean source and exact frozen-patch equality. Reviewed all changed hunks, remapping owners, projection consumers, failure cleanup and tests.

  • Checked every frozen comment/review. The previous aggregate-pruning finding is addressed by existing owner delegation and targeted planner/SQL cases.

  • Reused author-reported final-revision planner/explain suites, targeted race coverage, one-CN MySQL regression and incremental static checks. Substantive frozen CI checks remain pending.

  • Executed the bounded source-extracted alias-guard probe successfully. Saved detailed evidence and extraction provenance in the attempt directory; source remains unchanged.

Limitations:

  • The external-scan SQL reproduction was not executed locally. Native provenance verification failed because the retained artifact stamp is missing; no native tests were run. The finding rests on the guard probe and production-source tracing.

  • Author validation was not independently rerun; multi-CN behavior and quantitative performance were not measured.

  • Linked-issue bodies were absent from frozen evidence; requirements were checked against the supplied PR description and comments.

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · superseded

Commit: 9d82a7119f0424a1a1d0e4c292e6ea3006adcdac

new same-head PR feedback/CI evidence requires a fresh task

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · superseded

Commit: 9d82a7119f0424a1a1d0e4c292e6ea3006adcdac

new same-head PR feedback/CI evidence requires a fresh task

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · superseded

Commit: 9d82a7119f0424a1a1d0e4c292e6ea3006adcdac

new same-head PR feedback/CI evidence requires a fresh task

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · done

Commit: 9d82a7119f0424a1a1d0e4c292e6ea3006adcdac

Approved the unchanged committed candidate. Required validation remains valid, no material blocker remains, and the accepted design’s CI dispositions and incident action are preserved exactly. Fresh candidate CI is pending.

Cause issue: #30040
Verified commit: 0e3edbb; fresh CI is pending

@XuPeng-SH

XuPeng-SH commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 4d427129bad9f606250f5ed02a9a217861350e40

Assessment: approve

Reviewed the complete six-file delta and surrounding owners/callers. Operand alignment preserves set-operation semantics while retaining existing pruning and side-effect responsibilities. The aggregate, external-scan, table-function and shared-CTE concerns are addressed; no actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

Validation:

  • Current-head focused planner, EXPLAIN and all three public SQL fixtures passed without skips: 186 passing test/subtest events. Coverage includes wrong results, INSERT/CTAS persistence, prepared reuse, NULL/empty inputs, effects, fallible expressions and column pruning.

  • Reconciled retained full planner/EXPLAIN normal and race runs and three SQL fixtures in both modes from 6dd25ae. All six PR files are byte-identical; source manifests, rebase changes, commands, log hashes and 11 exit receipts were independently audited.

  • Verified native compatibility through 192 source inputs, 44 dependency artifacts, libmo/compiler identity and the successful repository Make build receipt. Private-/tmp and loopback preflight passed.

  • Reconciled retained build, vet, lint, formatting and whitespace evidence. Five molint advisories affect files unchanged from the current merge base. Reviewed frozen discussion concerns, test quality, error-path cleanup, bounded alias traversal and shared-CTE ownership.

  • Source remains clean at the assigned HEAD. Evidence is preserved under /home/xupeng/.local/state/mo-bot/jobs/e2b09ac08dfd721902635bec/attempt-1: current-focused.log, checks/1791895931254674765-2.json, terminal-evidence-audit.json, retained-evidence-audit.json and review-report.json. Terminal reconciliation receipt: checks/1791896213988818619-2.json.

Limitations:

  • Full-suite race evidence was reused from the verified pre-rebase implementation; focused normal tests were freshly executed at the assessed HEAD. Two unrelated existing full-suite skips remain.

  • Runtime evidence covers Linux CPU and the embedded single-CN fixture; no quantitative performance or distributed-cluster claim is made.

  • Current-head remote CI results and complete linked-issue threads were not supplied. Behavioral contracts were assessed from frozen PR reproductions and discussion. Generic protocol recovery for related issue [Bug]: string UNION ALL projection error desynchronizes the MySQL connection #30010 remains outside this change.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 4d427129bad9f606250f5ed02a9a217861350e40

Assessment: approve

Reviewed the complete six-file delta and surrounding owners/callers. Operand alignment preserves set-operation semantics while retaining existing pruning and side-effect responsibilities. The aggregate, external-scan, table-function and shared-CTE concerns are addressed; no actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

Validation:

  • Current-head focused planner, EXPLAIN and all three public SQL fixtures passed without skips: 186 passing test/subtest events. Coverage includes wrong results, INSERT/CTAS persistence, prepared reuse, NULL/empty inputs, effects, fallible expressions and column pruning.

  • Reconciled retained full planner/EXPLAIN normal and race runs and three SQL fixtures in both modes from 6dd25ae. All six PR files are byte-identical; source manifests, rebase changes, commands, log hashes and 11 exit receipts were independently audited.

  • Verified native compatibility through 192 source inputs, 44 dependency artifacts, libmo/compiler identity and the successful repository Make build receipt. Private-/tmp and loopback preflight passed.

  • Reconciled retained build, vet, lint, formatting and whitespace evidence. Five molint advisories affect files unchanged from the current merge base. Reviewed frozen discussion concerns, test quality, error-path cleanup, bounded alias traversal and shared-CTE ownership.

  • Source remains clean at the assigned HEAD. Evidence is preserved under /home/xupeng/.local/state/mo-bot/jobs/e2b09ac08dfd721902635bec/attempt-1: current-focused.log, checks/1791895931254674765-2.json, terminal-evidence-audit.json, retained-evidence-audit.json and review-report.json. Terminal reconciliation receipt: checks/1791896213988818619-2.json.

Limitations:

  • Full-suite race evidence was reused from the verified pre-rebase implementation; focused normal tests were freshly executed at the assessed HEAD. Two unrelated existing full-suite skips remain.

  • Runtime evidence covers Linux CPU and the embedded single-CN fixture; no quantitative performance or distributed-cluster claim is made.

  • Current-head remote CI results and complete linked-issue threads were not supplied. Behavioral contracts were assessed from frozen PR reproductions and discussion. Generic protocol recovery for related issue #30010 remains outside this change.

@XuPeng-SH

XuPeng-SH commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · done

Commit: 4d427129bad9f606250f5ed02a9a217861350e40

Accept the complete candidate with no material findings or missing required scoped validation. Confirm all five attempt-1 failure dispositions and both cause signatures. Frozen attempt 2 remains unresolved; overall CI is not claimed passed.

Independent CI cause (no issue created): github-checkout:git-fetch:gnutls-receive-error-early-eof
Independent CI cause (no issue created): ci-tool-setup:setup-cmake:ninja-download-tls-handshake-disconnect

@mergify

mergify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

This branch was previously deployed

1 inactive deployment
ci — 65cb09b6 Deployed Oct 13, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

3 participants