Skip to content

fix(compile): preserve prepared TP expression reuse - #32862

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/32840-tp-execution-reuse
Nov 17, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/32840-tp-execution-reuse

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #32840

Related follow-up: issue #32857. Disk-budget sampling remains tracked by issue #32818.

Please keep #32840 open until the original 129 workload has qualified the candidate. This PR does not claim that all #32492 overhead, ordinary text-protocol TP overhead, or the original-scale regression is already resolved.

What this PR does / why we need it:

#32492 enrolled TableScan, Filter and Projection in statement allocation-account ownership. For a cached prepared TP Compile, closing the account requires those operators to Free their expression executors and buffers during Reset. The next execution reconstructs them, losing the existing ResetForNextQuery reuse contract. Installing TableScan.OutputAllocation also enables additional accounted/reader-filter paths.

This patch restores the pre-#32492 ownership scope for these three operators only in prepared TP execution:

  • Use one reusesTPFlatExecutors() gate; preserve the TP check defensively even though prepared AP is currently rejected.
  • Capture that policy in the allocation attempt so runtime clones use the same policy.
  • Reuse the existing ResetForNextQuery/final-Free lifecycle; no new pool, owner category, account-transfer protocol, worker or retry mechanism.
  • Keep Group, Order/Top, HashBuild and other owners accounted. Ordinary TP, AP and remote-fragment owner collection retain the existing policy. Dependent-source direct ownership is unchanged.
  • Preserve existing memory/spill admission, account terminal checks and cleanup for the remaining owners. No disk-budget or Statfs change is included.

Relative to pre-#32492, this restores legacy flat-operator ownership. Relative to current main, it deliberately narrows the newly added statement-account coverage for prepared TP. It is not a rollback of all reader/blockio/kernel/dictionary changes, nor a claim that every allocation remains statement-accounted.

Tests added

  • Owner-policy matrix for prepared/ordinary TP and AP, runtime clones, and nested scopes retaining Group/Order/Top/HashBuild owners.
  • Real scan/filter/projection/count pipeline with changing parameters, NULL, empty results, reader errors, cancellation, repeated execution, stable retained capacity for bounded inputs and final zero MPool balance.
  • Aggregate budget rejection followed by successful reuse, without disabling the aggregate's admission check.
  • Direct TableScan executor lifecycle test: a non-pooled wrapper counts Reset and Free, checks actual rows across executions, requires no intermediate Free and exactly one final Free. Pointer equality alone would be insufficient because executor pooling can recycle an address.

Tested with

Validation was performed on base e1160015bb5895c1677d5fc1496c4bee440592b3 plus this exact patch. Upstream main at publication check is 28ffd6ae678744b6ff68bc239daefe9ad9ac1325; its three later commits do not touch the three changed files. CI must validate the merge with current main.

Passed:

mo-cgo-test -count=1 -timeout=180s ./pkg/sql/compile ./pkg/sql/colexec/table_scan
mo-cgo-test -race -count=20 -timeout=180s \
  -run 'Test(TableScanResetRetainsFilterExecutor|TPReusable)' \
  ./pkg/sql/compile ./pkg/sql/colexec/table_scan
golangci-lint 2.14.0 run --new-from-rev=e1160015bb --timeout=5m \
  ./pkg/sql/compile ./pkg/sql/colexec/table_scan
git diff --check

Real MySQL prepared-protocol smoke also passed changing bindings/NULL/reversed ranges, invalid JSON followed by a valid rebind, and concurrent UPDATE result checks. Existing full compile race evidence remains relevant; this final review centralized an equivalent predicate and added deterministic tests.

Local performance evidence

Separate unprofiled and profile-instrumented, order-reversed suites used identical tools and byte-verified seed copies within each suite. Every scalar query result was checked and all queries succeeded.

Unprofiled mean QPS, two runs per version/case:

Case Exact parent f70c37b Exact child 49d552e Candidate on e116
Prepared range COUNT 19,987.70 16,055.93 19,615.80
COM_QUERY range COUNT 14,933.38 14,191.01 14,266.50
COM_QUERY point read 16,667.73 16,403.50 16,483.11

Prepared range COUNT improves 22.2% over the child and reaches 98.1% of parent locally. The separate profiled suite reaches approximately 99% of parent and shows no TableScan.Free samples on the prepared candidate path. These are bounded local measurements, not original-scale acceptance.

The text-range residual is deliberately left for #32857. The small unprofiled point-read delta is inconclusive; its known Statfs cost is not a separate new issue.

Scope and merge qualification

  • Local setup: Apple M2 Pro/Darwin arm64, 1,000 rows, eight pinned connections, 15-second intervals, GOMAXPROCS=4 and GOMEMLIMIT=3GiB. All four binaries used the same Go/native build options with GOEXPERIMENT_OPT empty. The host is not dedicated. Do not extrapolate the percentage to Linux/129.
  • Pending before final performance acceptance: matched parent/candidate on 129 Slot A, ten 10M-row tables, 1,000 threads, 300 seconds. No full TPCC qualification is claimed here.
  • No production environment was changed. No new lifecycle framework or broad exemption for ordinary TP was added.
  • Review-ready, with original-scale performance acceptance explicitly pending; not an assertion that [Bug]: Sysbench 1000W Random Ranges throughput drops ~35% after #32492 #32840 can already be closed.

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

@mergify mergify Bot added the kind/bug Something isn't working label Nov 17, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Nov 17, 2026
@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 66c30224be48bd5c1324bc435ad588cefe269ae0

Review completed. Read the assessment.

@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: 66c30224be48bd5c1324bc435ad588cefe269ae0

Assessment: approve

The prepared-TP policy restores existing executor reuse while preserving accounting for retaining operators. Capturing the policy for runtime clones is justified and introduces no new lifecycle mechanism. No actionable defects remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed the complete three-file delta, affected owners and consumers, linked issues and all three discussion entries.

  • Current-input native builds and source, formatting and provenance audits passed; source remains unchanged.

  • Five focused roots and both owning packages passed normal and race runs. Each focused root also passed 100 race repetitions.

  • Public MySQL prepared tests passed, including changing bindings, NULLs, error recovery and two-round teardown.

  • Reversed-order component benchmarks reduced prepared-TP allocations from 154 to 85 per execution; AP remained at 154.

  • validation-reconciliation.json matches 23 successful execution receipts to frozen source fingerprints, commands and retained logs.

Limitations:

  • Original-scale 129 and full TPCC qualification were not run; general performance recovery is not established.

  • The component comparison uses an all-owner policy control, not an exact predecessor binary.

  • Frozen CI supplied no relevant package validation. Author-reported Darwin performance and lint results were not independently certified.

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

2 h 14 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 12:04 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 14:18 · 26e071a

Reason

Pull request #32862 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.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — 26e071a1 Deployed Nov 17, 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.

3 participants