Skip to content

refactor(test): make planner fixture ownership explicit - #29638

Merged
XuPeng-SH merged 3 commits into
mainfrom
codex/quality-29627-explicit-planner-owners-20261005
Oct 6, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
codex/quality-29627-explicit-planner-owners-20261005

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 5, 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:

Fixes #29636.
Fixes #29637.

Refs #29249 and #29627. Continues merged #29629 as one complete planner fixture ownership migration. #29627 remains open for standalone-cluster, supplied-pool, alias and remaining-owner reconciliation; this PR does not complete the 100,000-line cleanup goal.

What this PR does / why we need it:

One explicit owner, with existing construction and cleanup

Four mock compiler/optimizer constructors now borrow an explicit process. GetProcess is a pure lookup and preserves override precedence, including nil. Context copies retain the injected process and executor identities. The holder, Once and global constructor mutex are retired; scoped executor selection uses the existing context and exact process identity without invoking a getter or publishing a global executor.

Migrate all 2,218 constructor calls and propagate actual caller TBs through the existing helper graph (23 named helper signatures and 316 helper calls). Callers reuse the existing testutil.NewProcess owner. Planner fixtures use MEMORY file services with explicit caller cleanup. Proved metadata-only consumers pass nil; supplied-process overrides and independent parent/child compile sessions remain intact. Manual AssertPlan releases its process, FS and pool on return. Fulltext binds its resolver once to the final wrapper and still observes later wrapper state changes.

Preserve isolation and bound fixture retention

Reuse the existing runtime storage and a scoped test helper to restore both prior value and prior absence for hints, protocol versions, runtime-filter limits and SQL executors. Register restoration before mutation, preserve later writes through LIFO cleanup, and retire replaced restorers and runtime resets. No parallel mutation is introduced.

Keep fresh mutable contexts but attach their resources to actual child scenarios: fulltext/HAVING, deterministic UPDATE builds, serialization, prepared-value rows and BOOL compatibility controls. Fixed-config benchmarks share one process per benchmark while retaining fresh catalogs per iteration; the existing statement runner releases each successful AST immediately. No scenario counts or result/type/error/layout assertions are weakened.

Retire discarded mock statistics construction, Schema.outcnt, the write-only context PK cache and its writes, and the unused PrimaryKeyDef.Cols calculation. Schema.pks and the used metadata remain. Remove a 58-line inactive protocol-test comment; normalized active Go syntax is identical, and existing protocol/error/fuzz-seed tests remain.

Verified counterexamples

  • [Bug]: Planner mock pads composite primary key names with empty entries #29636: composite primary-key Names was pre-sized and then appended, producing leading empty names through public Resolve. Fill the existing slice by index. The regression uses literal single/composite key names, including nonadjacent key columns; it does not compute expectations with the implementation.
  • [Bug]: External scan compiler tests depend on host CPU capacity #29637: five external-scan UTs inherited host CPU capacity but asserted three scopes or a spare-capacity footer path. Configure the existing logical Compile.ncpu explicitly. The clean main probe reproduces all five failures with GOMAXPROCS=2; repaired fixtures preserve file uniqueness, row-group coverage, empty-file exclusion and schema-mismatch rejection. Production scheduling and host CPU limits are unchanged.

Reconcile incoming main NTILE and binary/unary test consumers with the same owner instead of restoring obsolete nil/default fixture paths.

Retire unreachable export coverage without losing its error contract

Remove the export merge test whose constant-true guard always skipped execution, together with its exclusive setup and lock helpers. Preserve missing-file coverage in the existing ETL-reader fixture: assert a nil reader and the exact ErrFileNotFound category. Existing active CSV/TAE, merge, filter and discard scenarios remain.

The complete export package passes (53 test events, zero skips), and focused reader normal/race runs each pass five test events. A production overlay that swallows the file-open error is rejected by the new assertion. Formatting, vet, incremental configured lint and molint pass. Actual gpt-6.1-sol / xhigh separately reviewed this checkpoint: APPROVE, no unresolved blockers. This removes 90 net lines; it makes no runtime-speed claim because the old test never ran.

Validation and independent QA

Based on fetched main 614ab46453638324a7997ac3ecc6813e5c810309, Go 1.26.4. Heavy jobs ran serially with GOMAXPROCS=2, GOMEMLIMIT=2GiB, package/test parallelism one, offline modules and the repository CGo wrapper.

  • All nine owning packages ran completely, uncached: 10,037 top-level PASS. Three inherited skips (one frontend test and two planner subtests) receive no pass credit.
  • Complete planner and compile race runs: 3,498 / 1,387 PASS, respectively. Planner has the same two inherited skipped subtests; compile has none. Eight affected frontend/compiler/unary/binary race selections also pass, with zero skips.
  • Four individual getter/executor/resolver race selections each reach 100 repetitions within the recorded 30-second budget and cap: 400 PASS, zero skips. Their unchanged semantic inputs were checked after rebase.
  • Incremental formatting, vet, configured lint and molint cover the nine changed packages; all pass, configured lint reports zero issues and molint reports no findings. The preceding full 28-package PR closure also passed before the latest main integration; it is recorded separately, not substituted for final checks.
  • Independent lifecycle probes check native/heap bytes, registry removal, child teardown and borrowed-resource survival. Omitting TB cleanup is rejected by the public registry oracle. Benchmark retention probes pass, and restoring per-iteration acquisition is rejected. Restoring runtime replacement is rejected by the existing identity regression.
  • Actual gpt-6.1-sol / xhigh reviewed the complete change map, ownership design and QA evidence, then reviewed only the converged source corrections and new-main integration. All source blockers and mandatory validation gates are closed. No review documents are committed.

Four controlled fixture-construction-plus-cleanup benchmark shapes satisfy the <=5% time/allocated-byte regression budget. Default fixture shapes improve about 9.7–9.9% in time and 6.1% in allocated bytes; the metadata-only and eight-context shapes also pass. These are local fixture costs, not production query, total CI CPU/RSS or TPCC claims. The hot-path inputs remain unchanged after rebase, so that evidence is reused.

Implementation +62/-157; tests +3,090/-3,205; docs/BVT zero; net -210 lines across 256 files. Most constructor edits are API migration, not large-deletion credit. Product SQL behavior is unchanged, so this stage requires no SQL BVT; no full-CI-green claim is made.

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

Deep review of 6655ceef2b587275db1075cdd46bf2a4c60cf1db against 614ab46453638324a7997ac3ecc6813e5c810309: code review PASS — no verified blocking findings. This records the assessment as COMMENT because the authenticated account is also the PR author; it is not a GitHub APPROVE event. CI is still running.

The design places ownership in the existing testutil.NewProcess(TB) lifecycle. Mock contexts borrow their process, preserve explicit nil/override behavior and copy identity, and select their scoped executor without calling an override or publishing it globally. Removing the holder, lazy initialization and constructor mutex is consistent with that ownership. The small package-local memory-FS helpers do not introduce a second lifecycle framework.

Reviewed the complete 256-file range, separating mechanical constructor/TB migration from behavioral changes. Child fixtures use the actual child lifetime; fixed-configuration benchmarks retain fresh catalogs while sharing their process outside the measured loop; the fulltext resolver binds once to the final wrapper. Shared runtime restoration retains runtime identity and prior value/absence through scoped cleanup. Manual AssertPlan cleanup covers every return after acquisition. The discarded statistics, write-only PK cache, unused PK column computation and replaced restoration paths have no remaining consumers requiring them.

The two linked issue contracts are addressed at their existing owners:

  • #29636: public Resolve returns exact declared key names, including the nonadjacent composite-key columns, with an independent literal oracle.
  • #29637: all five external-scan fixtures declare the logical capacity their assertions require. File/row-group coverage, empty-file handling and schema-error assertions remain intact; production scheduling is unchanged.

The removed export merge test always skipped because of its constant-true guard. Its exclusive setup was retired, and the existing ETL-reader fixture now checks nil reader plus the exact missing-file error. The inactive protocol-test comment supplied no executing coverage. No product SQL behavior, wire format or production execution path changes; no product-throughput improvement is inferred from fixture benchmarks.

Reviewer-run validation on this exact head, Go 1.26.4 darwin/arm64, verified matching native artifacts, GOMAXPROCS=2 and serialized package/test execution:

  • 12 selected planner/compiler top-level tests passed (24 total test events), zero failures/skips: process/copy/executor/resolver identity, child pool deregistration, runtime restoration, PK metadata, and all five low-CPU external-scan cases.
  • A separate temporary overlay exercised public AssertPlan success, parse failure, binding failure, unsupported statement and pattern mismatch. All five scenarios preserved the pool registry and allowed a subsequent successful call.
  • Removing pool deregistration through a mutation overlay made that independent probe fail, including a concrete expected pool count 0 / actual 1. No mutation or probe was applied to the tracked PR source.
  • git diff --check passed; the review worktree remains clean.

The PR body's full-package/race/static/fixture-benchmark results were considered as author-reported evidence; those complete suites were not redundantly rerun here. At the final refresh, shared build and preflight passed, while UT, SCA, coverage and two BVT jobs were still in progress. Pending/cancelled/skipped checks are not counted as passed; merge remains subject to the required CI results.

There are no human inline review comments or prior review requests on this PR, and no comments on #29636/#29637 awaiting resolution. Separate delta accounting: implementation +62/-157 (net -95), tests +3090/-3205 (net -115), documentation/BVT unchanged; total net -210. The API migration is not counted as broad simplification beyond those actual changes. No subagents were used for this review.

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

Independent senior-QA follow-up on exact head 6655ceef2b587275db1075cdd46bf2a4c60cf1db, reusing the complete change-map/white-box review above. No subagents; all new probes were temporary overlays, with no tracked source edits.

No new verified defects or request-changes findings.

  • Abrupt teardown exercised in child test processes: cancelled context + deliberate FailNow with an initially absent runtime key, and deliberate panic with a prior runtime value. Cleanup receipts prove child native/heap bytes are zero, the public pool registry returns to baseline, the prior runtime presence/value is restored, and the parent-owned borrowed process/executor remains usable.
  • Real ParseOne/BuildPlan calls prove mutable catalog changes in one context do not contaminate another context sharing the borrowed process. Public metadata-only resolution with nil process acquires no hidden pool; scoped execution does not publish a global executor.
  • Both existing scalar-subquery branch-limit benchmarks were invoked at eight iterations. Each calibrated invocation acquires one process, and teardown restores the registry baseline. Go reuses testing.B across calibration runs; the probe accounts for cleanup between invocations.
  • All three probe groups and four subtests pass normally and with -race. Race package elapsed 4.684s; no race reports.
  • Negative control: replacing NewProcess(t, ...) with NewProcess(nil, ...) removes TB cleanup registration. Both abrupt-exit scenarios correctly fail on the public registry oracle (expected 1 pool, actual 2), proving the probes detect owner leakage.

UT, SCA, coverage, both BVT configurations and CI Required are now SUCCESS on this head. Cancelled/skipped optional jobs are not counted as passed.

Performance boundary: this independent run proves bounded benchmark resource retention, not a before/after timing result. Existing author-controlled fixture benchmarks report roughly 9.7–9.9% lower default construction/cleanup time and 6.1% fewer allocated bytes, with all four shapes within the 5% regression budget. This does not establish unchanged total CI duration or production SQL throughput. Production execution paths are outside this mock-fixture change.

QA assessment: PASS within the reviewed scope. COMMENT is used because the authenticated reviewer account is also the PR author; this is not a formal GitHub approval.

This branch was previously deployed

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

Labels

kind/api-change kind/bug Something isn't working kind/enhancement kind/refactor Code refactor kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: External scan compiler tests depend on host CPU capacity [Bug]: Planner mock pads composite primary key names with empty entries

2 participants