Repository navigation
Done
Description
Summary
Redesign how the planner receives prepared-statement parameters. The typed parameter batch from #33011 should be the single source of truth. plan.ParamValue (Value any plus StringConversionKind) and its string-conversion branches should go.
Background
One EXECUTE currently carries each parameter in three representations:
- The TEXT transport vector. Protocol values and user variables are rendered to text.
- The typed parameter batch, added in refactor(vector): remove prepareParamKind from Vector; carry prepared parameters as typed values (#33007) #33011. One row per parameter, in its source SQL type, read by
ParamExpressionExecutor. paramVals []anyofplan.ParamValue. Read by the planner:ResetParamRefRule, prepared binding, field types, pagination and so on. It carriesValue any(astringfor COM_STMT_EXECUTE, native Go types for user variables) and aStringConversionKindthat tells consumers how to undo the stringification.
The consumers of (3) branch on what Value holds: about 70 ParamValue unwrap sites across 14 files, each followed by type switches on Value. A large part of the prepared-parameter compatibility history lives in those branches.
Proposal
- The planner reads parameter values from the typed batch, plus the TEXT transport for string or untyped parameters, instead of from
paramVals. - Remove
ParamValue.Value anyandStringConversionKind, and the per-consumer string-conversion branches they require. This is the follow-up noted in [Subtask]: Vector cleanup, prepareParamKind related. #33007. - Keep one parameter representation per execution, owned by the prepared statement and rewritten in place. See [Performance]: Performance regression: sysbench #33076 / fix(prepare): never allocate for parameter binding after the first execution (#33076) #33081 for the no-allocation rule.
Non-goals and cautions
- No zero-copy strings into storage that is reused in place. Parameter values can outlive an execution: plan literals, specialized-plan caches, binding keys, warning and error text, remote plan serialization, CTAS semantic params. If an allocation-free string is needed, copy into a per-execution buffer that is replaced, never overwritten (the same class as the
QuickBytesToStrretention bugs). - The allocation win over the interim fix (pointer storage for
ParamValue, separate PR) is small. The motivation is correctness and simplicity: one source of truth and no string-conversion machinery.
Acceptance
- Unit tests and
test/distributed/cases/prepareBVT pass unchanged. - sysbench ps-mode=auto (random_points, random_ranges, nopk_random_points, point_select) is no slower than the interim fix, measured with an ABBA ordering.
Activity
fengttt commentedon Nov 23, 2026
Suggested by Claude. It seems to be reasonable design.
fengttt commentedon Nov 23, 2026
The interim fix (pointer storage for planner
paramVals) is #33083, stacked on #33081.fengttt commentedon Nov 23, 2026
Stage 1 (COM_STMT integer/float/Boolean parameters as native values; integer/float/Boolean string re-interpretation removed) is #33091, stacked on #33083 → #33081. Next: stage 2 (DECIMAL/temporal onto the binding), stage 3 (PrepareParamKind → type predicates).
refactor(prepare): decode a COM_STMT DECIMAL once; drop MaterializedV…
refactor(prepare): derive a parameter's conversion kind from its type (…
fix(prepare): never allocate for parameter binding after the first ex…
refactor(prepare): remove PrepareParamKind; a parameter's kind is its…
perf(prepare): statement-owned storage for planner parameter values (#…
refactor(prepare): plan prepared parameters from typed values; remove…