Repository navigation
fix(sql): preserve inline CTE identity for correlated aggregates - #30834
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: c36a4424fc9e92bdba43d9129885ac7bd2348c34
Assessment: approve
Reviewed the complete seven-file delta and its binding, decorrelation, CTE reuse, alias and column-remapping consumers. The design preserves native row identity privately, stages projection changes until admission, and reuses existing aggregation and cleanup owners. The transport-width guard prevents later CTE sharing from discarding that identity. No actionable defects remain within the stated scope.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Isolation preflight passed. Independently verified 192 current native-build inputs and 46 retained output hashes against the successful build-owner receipt.
-
All three new planner tests and the frontend regression passed, covering duplicate rows, NULL/empty inputs, aliases, EXISTS ordering and prepared reuse after errors and data changes. Receipt: 1792665472229439364-4.json.
-
The entire planner package passed: 4,091 top-level tests. Receipt: 1792665525526888198-3.json.
-
Independent SQL probes passed twice, covering nested sorted CTEs, repeated projected columns, predicate composition, DISTINCT/LIMIT and empty outer input. The exact BVT passed 9/9 statements twice on one instance, with database removal verified between runs. Receipt: 1792665638907495187-3.json.
-
The merge-base production-file control preserved success for both original issue queries and reproduced the intended identity errors for the newly supported CTE cases. Mixed equality/range LEFT JOIN composition remained rejected on both revisions. Receipt: 1792665649731793442-4.json.
-
go vet passed for both changed Go packages. Formatting, clean pinned source, complete patch and receipt/log reconciliation passed. Evidence and review mapping are retained under /home/xupeng/.local/state/mo-bot/jobs/e5e7f000bd7b9dc5cd436cbc/attempt-1/review-evidence.json and review-map.json.
Limitations:
-
Runtime CI was pending in the frozen snapshot. Linked issue bodies and retained author-validation artifacts were absent; author race, MySQL-oracle and performance claims were not counted as verified checks.
-
Local validation used Linux amd64, Go 1.27.1 and the canonical one-CN fixture. No distributed-topology or race run was required by the unchanged execution and concurrency contracts.
-
No throughput benchmark was run. Newly supported CTE queries carry a private Row_ID and forgo sharing of widened occurrences; existing native-table paths retain their fast path. No measured performance improvement is claimed.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #23083
What this PR does / why we need it:
A correlated range aggregate over a transparent inline CTE currently fails with error 20102 because the CTE projection hides the native row identity needed by scalar decorrelation. This also rejects a SELECT combining correlated EXISTS and MAX over the same CTE.
Forward the existing hidden Row_ID through eligible raw-column CTE projections, keeping it outside the visible binding and result schema. Reuse the existing LEFT JOIN, scalar reaggregation, empty-input reconstruction and column-alias owner. Stage projection changes until the complete rewrite is admitted. CTE occurrences whose private identity exceeds the captured transport width stay inline, so later CTE sharing cannot discard that identity. No new execution operator or identity enumeration is introduced.
The proof is deliberately limited to deterministic, row-preserving projections of one native table. Computed projections, duplicate-producing UNION ALL, DISTINCT/GROUP BY, multiplying joins and pagination retain their guarded rejection. General derived-table decorrelation is outside this change.
The issue's original two queries already pass the frozen main baseline, including the complete indexed schema and an ANALYZE control. This PR preserves those regressions and fixes the remaining inline-CTE boundary; it does not attribute the historical queries' existing success to this patch.
Validation on macOS arm64 / Go 1.27.1, with the supported CGo runner and fresh matching native build:
pkg/sql/planin normal and race modes,-count=1: passed.scalar_cte_row_identityBVT: 9/9 twice against the same instance, with explicit database teardown checks. Golden results were manually authored and checked against the independent oracle.go vet, configured incremental golangci-lint: passed; no new molint diagnostics against the base. The four existing molint diagnostics are unchanged.Performance: original base-table paths keep the existing row-identity fast path and execution operators. Three paired planning controls retain the same allocation counts. Eight longer alternating pairs for a range-planning control show mixed timing differences (mean paired change +0.88%; separate revision medians +2.3%, overlapping ranges); this is not an execution-throughput measurement or proof of zero overhead. Newly supported CTE queries carry one private Row_ID through affected projections and forgo sharing of that widened CTE. No global CTE-reuse switch or per-row window is added.
Design and final overall review passed using explicitly selected gpt-6.1-sol / xhigh; final review found no unresolved material blockers. Remote CI has not yet run for this branch.