Repository navigation
Revert #33011: typed prepared parameter refactor (Sysbench regression) - #33074
Closed
LeftHandCold wants to merge 1 commit into
Closed
LeftHandCold wants to merge 1 commit into
LeftHandCold wants to merge 1 commit into
Conversation
…prepared parameters as typed values (matrixorigin#33007) (matrixorigin#33011)" This reverts commit 520ee5c.
XuPeng-SH
marked this pull request as ready for review
November 23, 2026 02:33
XuPeng-SH
requested review from
XuPeng-SH,
aptend,
aunjgr and
iamlinjunhong
as code owners
November 23, 2026 02:33
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? |
Contributor
|
This pull request is closed, so it cannot be queued. Reopen it to get the box back. |
fengttt
requested changes
Nov 23, 2026
fengttt
left a comment
Contributor
There was a problem hiding this comment.
No we don't revert this. Refix.
This was referenced Nov 23, 2026
fengttt
added a commit
that referenced
this pull request
Nov 23, 2026
…ecution (#33076) (#33081) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #33076 ## What this PR does / why we need it: Fixes the sysbench regression from #33011 (typed prepared parameters) without reverting it. The affected workloads are `random_points`, `random_ranges` and `nopk_random_points`, with ps-mode=auto. **Rule applied:** a prepared statement allocates what parameter binding needs, holds it in the statement, and reuses it. After the first execution, binding allocates only when a value needs more room than before. ### Cause Binding allocated on every EXECUTE and in every expression executor: - `installTypedPrepareParams` built a new batch, plus one vector per parameter, on every execution. - Each `ParamExpressionExecutor` copied its parameter: a `Dup` of the typed value, or a new constant for a string. The per-EXECUTE diagnostic probes (`ProbePreparedDiagnosticCandidatesWithProof`) and `EvalFoldExpr` build fresh executor trees, so every `?` in `k IN (?, …)` was copied several times per statement. - A `?` that the planner narrows to its consumer's integer type (protocol BIGINT vs an INT column) built a whole CAST executor inside each executor. This matches the CI profiles in #33074, where 30–44% of CPU was under `evalTyped` and `runtime.Callers`. ### Changes - **Typed parameters.** `PrepareStmt` owns the typed parameter vectors and an integer-conversion store (`process.TypedParamConversions`). EXECUTE rewrites them in place and the process only borrows them. - A narrowed integer is converted once per (position, type), then rewritten in place. - A value that doesn't fit keeps the CAST adapter, so error and selection semantics are unchanged. - **Executor reads.** `ParamExpressionExecutor` returns a read-only reference instead of a copy. - The reference is a descriptor embedded in the executor, filled by the new `Vector.WindowInto` (a method only; no new Vector fields). - Typed values reference the statement-owned typed vector. - String values reference their row of the TEXT transport. - `EvalWithoutResultReusing` still hands out an owned copy. - A folded value is re-read when the process holds different parameter values, so a reference can't go stale. - **COM_STMT_EXECUTE TEXT transport.** The vector is rewritten from an empty area that keeps its capacity. `SetBytesAt` appends, so before this change the area grew (and reallocated) on every execution that had a string parameter longer than the inline varlena. - **SQL `EXECUTE … USING`.** The statement owns the TEXT vector and its metadata slices (`executeUserParams`), rewritten in place and borrowed by the process. Previously they were built fresh on every execution. ### Benchmark Setup: local single-node, ps-mode=auto, 16 threads, 60 s, 10 tables × 1M rows. `sbidx` has PK(id) + KEY(k); `sbnopk` has KEY(id) + KEY(k) and no PK, matching CI's nopk case. Runs are interleaved ABBA (main, fix, fix, main) with `sync` and a 90 s settle between them, because a fixed run order skewed earlier comparisons. | workload (qps) | main A1 | fix B1 | fix B2 | main A2 | main avg | fix avg | Δ | |---|---|---|---|---|---|---|---| | random_points | 12,329 | 18,664 | 19,332 | 13,846 | 13,088 | 18,998 | **+45%** | | random_ranges | 13,486 | 18,237 | 18,740 | 14,896 | 14,191 | 18,488 | **+30%** | | nopk_random_points | 11,501 | 17,069 | 17,628 | 12,715 | 12,108 | 17,348 | **+43%** | main = 4cadd4f. The fix binary includes the typed-parameter and string-parameter changes. The SQL `EXECUTE … USING` change is not exercised by sysbench. CPU profile of random_points: | | main | this PR | |---|---|---| | `ParamExpressionExecutor.Eval` | 16.3% | 0.9% | | `mpool.alloc` | 8.2% | 1.2% | ### Follow-ups - **Separate PR:** pointer storage for the planner's `paramVals` (`[]any` of `plan.ParamValue`), so building them no longer boxes each value per execution. - **#33082:** redesign so the planner reads the typed parameter batch and the `ParamValue` string-conversion machinery goes away. ## Tests - **New tests:** - Typed binding: a second EXECUTE makes zero mpool allocations and reuses the same vectors; the narrowed conversion is refreshed in place; a value that no longer fits isn't served; release detaches the process. - Fresh executors reading typed and string parameters allocate nothing and don't mutate the shared value. `EvalWithoutResultReusing` returns an owned copy. New TEXT parameters are re-read rather than served through a stale reference. - Integer conversion boundaries, plus out-of-range and negative→unsigned values keeping the CAST error. - COM_STMT_EXECUTE with a 40-byte string: no allocation on re-execute; a longer value grows the area once. - SQL `EXECUTE … USING`: storage reused with no allocation on re-execute; release detaches the borrowing process. - **Passing:** `pkg/frontend`, `pkg/sql/colexec`, `pkg/vm/process`, `pkg/container/vector`. - **Not run locally:** `make static-check`, plan/compile UTs and BVT. CI will cover them. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Requested exact revert of #33011, for the Main Sysbench regression tracked in #33064. Draft: not mergeable on current main. This is a one-commit inverse on top of the original squash
520ee5ceabb8, not a reset of main and not a proposed rollback of subsequent PRs. The resulting Git tree exactly matchesa43c86bb8e2d(tree0f21cdb3e5320f730b4ab4de6bbbe600254419f8).Integration blocker
Applying the same revert to
main@4cadd4f2f6edproduced 108 unmerged paths (87 content conflicts, 21 modify/delete). Examples: vector ownership/metadata, batch/pipeline codecs, parameter evaluation and process serialization. Intervening PRs include #33017, #33024, #33033, #33054, #33052 and a later prepared-DML compatibility change #32002. Do not resolve by taking historical files wholesale: that can roll back unrelated work. No current-main merge build, mixed-version test, or post-revert TPS is claimed.Performance evidence
The Nov 23 Main Weekly TP comparison tested
dea4f40b17d0and again reported random_points 3,181 vs 6,607 TPS, random_ranges 3,609 vs 8,047 TPS, and nopk_random_points 1,842 vs 3,091 TPS (current vs historical median). All three workload measurements ran 300s with zero reported errors.On TP CN
nightly-regression-dis-tp-cn-9s5c2, CPU profiles over 300s starting Nov 22 16:40:32 and 16:45:34 UTC put 40.7% and 44.4% of samples, respectively, belowParamExpressionExecutor.evalTyped; 36.7% and 40.1% of all samples were in itsruntime.Callersallocation-recording path. These are nested percentages, not additive. This corroborates the previously reported mechanism, not a controlled measurement of the gain from this revert.For No-PK at 19:20:45 UTC, the main-labelled scrape was empty, but the same TP pod and MO pprof endpoint (10.143.86.97:6060) had a CPU scrape under its enable-conntrack discovery label. In that scrape, 33.8% was under MO evalTyped, 33.8% under its vector duplicate and 30.7% under its runtime.Callers path. Only that one scrape was used for this window.
Keep #33064 open until an integrated candidate preserves the prepared-parameter SQL and transport contracts and a same-environment, same-data, profiling-on comparison shows recovery of the affected workloads.