Repository navigation
fix(plan): reuse bounded nested scalar CTEs on 4.2-dev - #32541
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? |
|
This pull request is merged. |
|
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: afe6b990b7b84dd2cd6f264eeb5bf79101d18091
Assessment: approve
The bounded scalar-CTE proof safely extends the existing reuse mechanism to nested UNION ALL consumers and CTAS-generated INSERT SELECT. Producer identity, live demand and non-truncating limits protect evaluation semantics; existing profitability, memory and materialized-runtime owners remain intact. The added proof complexity is justified without adding another execution mechanism. No actionable defect remains.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed the complete six-file delta, linked matrixflow issue 21333 and its comment, and all three discussion entries. discussion-assessment.json accounts for every key; the discussion contains no substantive prior finding or disputed design decision.
-
Traced SELECT and ordinary INSERT SELECT admission, numeric binding contexts, producer identity/types/snapshots, live/conditional demand, structural row bounds, excluded DML/fallback modes and exact CTAS-generated SQL. Reviewed existing sink/reader registration, generation/reset, cancellation/error propagation, cleanup and memory/spill owners.
-
Frozen exact-head evidence reports successful Ubuntu UT, SCA on arm64, shared build, coverage and both active compose BVT jobs (14 success, 13 skipped, 2 neutral). The repository UT owner includes planner/compiler/materialized packages. Skipped and neutral jobs are not counted as passes.
-
Author reports full planner tests, 18 compiler/materialized tests, vet/lint, the new BVT twice (35/35), the CTE directory (86/86), baseline-equivalent values/metadata/errors and synthetic original-query scan reductions from 8/4 to 1. These are author-reported results; raw local-validation records were not supplied.
-
Supplied isolation preflight passed. Local bounded delivery check passed: clean frozen head and full patch identity, git diff --check, gofmt for four changed Go files, all 35 SQL/result statement pairs, explicit database/prepare teardown, independent four-metric decimal arithmetic and exact discussion-key coverage. validation-audit.json reconciles both executor receipts with source, commands, exits and retained stdout/stderr.
Limitations:
-
No local Go product/race suite or live mo-tester run was repeated. CI statuses are supplied, but raw CI/author test logs are absent; local pairing/arithmetic checks do not claim SQL execution.
-
The original production SQL attachment, production deployment and production-scale CTAS latency were not independently validated. This scoped branch optimization does not establish that the linked production incident is resolved; unordered row-number-to-metric assignment remains unspecified.
What type of PR is this?
Which issue(s) this PR fixes:
Related to matrixorigin/matrixflow#21333.
Branch-specific adaptation of #32522 for
4.2-dev, not a mechanical cherry-pick. The mainline nested-CTE consumer-proof dependencies are intentionally not imported.What this PR does / why we need it:
The two reported CTAS queries repeat an expensive aggregate through nested CTEs and scalar UNION ALL branches. On this branch, nested references and any consumer LIMIT prevent reuse; moreover, the existing reuse pass only runs at the SELECT entry point, not for CTAS's internal INSERT SELECT.
Validation
Go 1.26.4, native libraries built in the target worktree; full
pkg/sql/plantests and 18 targeted compiler/materialized-source tests pass.Public planner regressions cover 2/4/8 branches, N−1/N/N+1 limits, live/dead column demand, unsafe shapes, producer identity, formatted metrics, and the exact CreateAsSelectSql emitted by CTAS.
New helper statement coverage: 80.75%; changed profile-line coverage: 75.38%. Matching-toolchain gofmt/vet and incremental golangci-lint 2.6.2 pass.
mo-tester-generated results were checked against the clean branch baseline: values, metadata, and expected errors are identical. New BVT passes twice (35/35 each); the CTE directory passes 86/86, with teardown checked.
Using the complete original SQL/DDL and 12 local synthetic rows:
Both source SELECT and executing CTAS-shaped INSERT SELECT plans have these counts. Actual CTAS outputs remain 8/4 rows, with business values and table metadata matching the branch baseline. Unordered row-number-to-metric assignment is not treated as deterministic.
No production deployment or production-scale CTAS latency measurement was performed. This PR does not claim that the production incident is already resolved.