Repository navigation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review for #26725 (preserve prepared numeric semantics for BIT casts). The packed-metadata architecture, lifecycle reset across vector/group/timewin/window, legacy-decode safety, and the signed-integer BIT(64) bit-pattern path are correct. Two findings are merge-blocking; details in the two inline comments. A third (F-5, high) is noted for the group partial-agg serialization: the kind-state bytes are appended with no version token in the ExtraBuf, so a mixed-version group spill/scan can read agg-payload bytes as kind state and hard-abort with 'invalid aggregate prepared parameter state'.
| return uint64(rounded), true, nil | ||
| } | ||
|
|
||
| func preparedDecimalToBit(input string, bitSize int) (value uint64, inRange bool, err error) { |
There was a problem hiding this comment.
Blocking — F-1: preparedDecimalToBit silently drops the fractional part.
fractionPart is parsed/validated but never used: the value is built only from integerPart.
unsigned, parseErr := strconv.ParseUint(integerPart, 10, 64)
...
return unsigned, true, nilConcrete failure:
PREPARE s FROM 'INSERT INTO t VALUES (?)'; -- t(b bit(64))
SET @d = CAST(5.9 AS DECIMAL(10,1));
EXECUTE s USING @d; -- stored 5 (fraction discarded)
INSERT INTO t VALUES (5.9); -- stored 6 (literal path rounds, like the float branch)Same characters, different result — this violates the PR's own "same characters retain same semantics" invariant for the PrepareParamDecimal kind. The float path (preparedFloatToBit) rounds via math.Round, and literal decimal→BIT rounds too, so decimal should round as well (only the integer part should truncate for exact-whole decimals). Also note issue_26725_test.go binds only int64, so this path has no integration coverage.
Suggested fix: apply rounding to the parsed fractional digits (matching the float path), and add a DECIMAL-to-BIT prepared case to issue_26725_test.go.
There was a problem hiding this comment.
Not adopted after checking the typed conversion contract. MatrixOne decimal-to-BIT conversion already truncates the fractional part (the typed path formats the decimal and consumes the integer part), so prepared DECIMAL must preserve that behavior; rounding it would introduce a new inconsistency. The focused decimal_truncates regression passes.
| ) | ||
|
|
||
| func hasBinaryPrepareParam(param pb.ReadParam) bool { | ||
| func hasVersionedPrepareParamMetadata(param pb.ReadParam) bool { |
There was a problem hiding this comment.
Blocking — F-3: the numeric-kind version gate never fires for numeric-only params.
hasVersionedPrepareParamMetadata is identical to the old hasBinaryPrepareParam — it scans only the first section:
func hasVersionedPrepareParamMetadata(param pb.ReadParam) bool {
for _, isBin := range param.Process.PrepareParams.IsBin {
if isBin {
return true
}
}
return false
}But a numeric-only param (e.g. FLOAT/DECIMAL/BOOLEAN kind with isBin all-false) has its kind bits packed in sections 1-3 of the SAME IsBin slice (via prepareParamMetadata, whose section 0 copy stays all-false when there are no binary params). So hasVersionedPrepareParamMetadata returns false, newReadRequest sends Method_ShardRead (not V2), and validateRemoteReadCompatibility is skipped entirely — the 4×-length packed slice reaches an older replica, which decodes it as plain binary flags and materializes garbage/mis-typed values with no fail-fast.
Concretely: the new TestNewReadRequestUsesVersionedMethodForPrepareParamMetadata cases craft IsBin: []bool{false,false,true} (FLOAT) and []bool{false,false,false,true} (BOOLEAN) and assert the versioned method is selected — but the production function iterates len entries of the first section and returns false for both. The test passes only because it is an assertion; the shipped function does not implement the asserted behavior.
Suggested fix: have hasVersionedPrepareParamMetadata detect the packed layout (scan the kind sections, or treat len(IsBin) % paramCount != 0 / a marker in section 0 as "versioned"), so numeric-only params route to Method_ShardReadV2 and are gated by validateRemoteReadCompatibility; and correct the test to exercise the real function.
There was a problem hiding this comment.
Not adopted: IsBin is the complete packed slice here, and the range loop scans every section, not section 0 only. FLOAT/BOOLEAN bits in the higher sections are therefore detected. TestNewReadRequestUsesVersionedMethodForPrepareParamMetadata directly exercises the production helper and passes.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review on 0157638.
[P1] Keep the distributed Group partial format compatible across rolling upgrades (pkg/sql/colexec/group/exec2.go:636-646 and mergeGroup.go:196-211). The new writer inserts one provenance byte per aggregate unconditionally between nAggs and the first aggregate state, while the new reader unconditionally consumes nAggs bytes. The existing payload has no version marker, protocol negotiation, or legacy fallback. A new MergeGroup reading a valid old-CN partial therefore consumes the first aggregate magic byte as provenance; the counterexample fails with invalid aggregate prepared parameter state 173. The reverse direction shifts an old reader into the provenance byte and corrupts aggregate decoding too. This affects ordinary distributed aggregation even when no prepared parameter is present because a zero byte is still emitted for every aggregate.
Please introduce a rollout-safe version/protocol gate or self-identifying backward-compatible encoding, retain legacy decoding, and add old-writer/new-reader plus new-writer/old-reader tests. Same-version round trips cannot cover this.
The empty-partial state model and operator-local execution state otherwise look correct. Affected package tests, focused race tests, and TestIssue26725PreparedBit64Numeric pass. I found no additional lifecycle, hang, unbounded-memory, or material hot-path performance blocker.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed and updated the exact current head. The rolling-upgrade blocker is closed with a protocol-gated, self-identifying trailer after the byte-identical legacy aggregate payload. Old-writer/new-reader and new-writer/old-reader paths both succeed; ordinary aggregates retain identical wire bytes. Malformed trailers fail cleanly. The gate is generation-local and reset on lifecycle boundaries; there are no new wait/resource edges or per-row hot-path costs. Focused compatibility and unhappy-path tests, adaptive race stress, full affected package tests, build, vet, and diff checks pass. Approved.
|
已在
PR 上另外两条 inline comment 经核验未采纳,并已逐条回复:DECIMAL→BIT 的 typed contract 是截断小数; 验证通过:完整 affected package matrix、group owning/dependent packages、embedded |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review:REQUEST_CHANGES
Reviewed head: 81edd4efab1febe2d7ac1c5a4a8f9a0934dbc867。
P1 — 表达式物化丢失 prepared source kind
pkg/sql/colexec/evalExpression.go:948-966 的 evalSelectedRows 只复制 IsBin,没有复制 PrepareParamKind;最终结果 :994-1014 也只恢复 IsBin。底层 Vector.UnionOne 不会自动传播该字段。
因此 CAST(IF(TRUE, ?, 'x') AS BIT(8)) 这类表达式会丢失 FLOAT/DECIMAL/BOOLEAN/INTEGER provenance,退回字符串字节语义。例如 prepared FLOAT 5.5 应按 numeric BIT 规则得到 6,经过 IF 物化后可能按字节串解析并报错或产生错误结果。CASE/COALESCE、部分 select list、执行器复用同样受影响。
请统一定义表达式物化时的 provenance 复制/冲突规则,并补充上述嵌套表达式、空分支、部分选中行和复用测试。修复应采用向量级元数据处理,避免给所有 Union 热路径增加逐行成本。
P1 — remote compile 缺少 mixed-version metadata gate
pkg/vm/process/process_codec.go:80-91 将四段 metadata 打包进既有 PrepareParams.IsBin;pkg/sql/compile/remoterunServer.go:913-932 在远端直接按该字段恢复。旧 CN 只认识前 paramCount 个 binary flags,不认识后面的 kind sections,因此新 coordinator -> 旧 CN 的滚动升级路径会静默丢失 numeric provenance,远端 BIT cast 回退到字符串语义。
请为 remote compile 增加协议能力协商/版本 gate;不能静默丢失语义。需要覆盖 new->old、old->new 两个方向的远程编译兼容测试,并明确升级/回滚顺序。
P2 — 通用复制/追加边界仍可能清除 provenance
pkg/container/vector/vector.go:1819-1900 的 CloneToFlatCompact,以及 pkg/container/batch/batch.go:955-980、:1263-1302 的 clone/append 路径复制数据但不复制或合并 PrepareParamKind。请明确这些 API 是否是 provenance ownership boundary;若不是,应保持 kind;若是,应显式记录并补充 window/order/spool/max-by 路径测试。
维护性
将新语义编码进 []bool IsBin 能保持旧 wire 结构,但 section 布局隐式且耦合面很大。建议集中封装 metadata 编解码,避免后续消费者直接按 offset 访问。
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of the frozen range base 629cbbe to head fcfc903 found two material correctness gaps; both are detailed inline above.
The earlier expression-provenance, remote mixed-version gating, and aggregate partial-wire compatibility concerns were rechecked: the latter two are addressed in this head, but heterogeneous row lineage and generic batch/spill materialization remain incomplete. git diff --check passed and focused controlled-CGo tests for the touched components passed. Several GitHub UT/SCA/BVT/coverage/e2e checks are still pending, so CI is not treated as a pass.
Please address the two P1 findings and add the requested semantic regressions before merge.
| expr.flowControlKind = kind | ||
| expr.flowControlKindSeen = true | ||
| } else if expr.flowControlKind != kind { | ||
| expr.flowControlKind = vector.PrepareParamNone |
There was a problem hiding this comment.
[P1] Preserve provenance per output row (or perform the destination cast before merging heterogeneous arms). observeFlowControlPrepareParamKind collapses a batch containing, for example, IF(flag, ?, '5') with flag=[true,false] and a prepared numeric ? to vector-wide PrepareParamNone when the second arm is observed. strToBit subsequently reads that one kind for every row; None intentionally uses byte-string semantics, so the prepared numeric row can become ASCII 53 instead of numeric 5. The added mixed-arm test currently asserts this lossy None state but does not exercise the following BIT cast. Please add a regression covering the actual cast result.
| // Copy simply does v[vi] = w[wi] | ||
| func (v *Vector) Copy(w *Vector, vi, wi int64, mp *mpool.MPool) error { | ||
| disjoint := v.areaDisjoint | ||
| destinationHasValue := v.length > 0 && !v.AllNull() |
There was a problem hiding this comment.
[P1] Do not treat a pre-sized destination as having observed values when reconciling prepare-param provenance. TOP spill (pkg/sql/colexec/top/top.go:562-582) unmarshals a batch through the vector wire format, whose Marshal/Unmarshal path does not carry prepareParamKind/prepareParamKindSeen, then allocates an output vector, calls SetLength(chunkSize), and fills rows with Copy. That makes destinationHasValue true before the first real row is copied, so the first source kind is immediately collapsed to None; the later BIT cast loses numeric semantics. Please carry this lineage through batch spill/serialization and initialize overwrite builders as empty (or reconcile based on rows actually written), with a spill/round-trip regression.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 40440071d4f5e9a647655fd112c64953e088b50b (base 629cbbe2fe51d6d457a31f450c7e5c1bc4628213): REQUEST_CHANGES.
发现 4 个实质问题,详见 inline comments:
- P1:MIN/MAX 等值候选的 provenance 取决于 partial 到达顺序,最终 BIT 结果可能在数值 5 与 ASCII 53 之间漂移。
- P1:通用 group spill 只恢复 aggregate provenance,group-by key 的 provenance 在落盘/回读后丢失。
- P2:异构 provenance sidecar 的 Shrink/Shuffle 重映射在分配失败时 panic,而不是返回可处理的 OOM/error。
- P2:sliding/gapfill time-window 广播 partition key 时使用 SetConst*,未复制 source provenance。
此前 review 中的 expression mixed-lineage、remote/shard gate、TOP spill 与 decimal contract 已重新核对,未重复提交。协调器 worktree 的定向 Go 测试受本机缺少 usearch.h、roaring.h、xxhash.h 阻断;git diff --check 通过,CI 仍有 UT/SCA/BVT/coverage 检查 pending。独立 Critical-lane supervisor 也对该 head 给出了 REQUEST_CHANGES。
| if exec.state[x1].vecs[0].IsNull(y1) { | ||
| exec.state[x1].vecs[0].UnsetNull(y1) | ||
| aggs1[y1] = aggs2[y2] | ||
| if err := exec.state[x1].vecs[0].SetPrepareParamKindAtWithMP( |
There was a problem hiding this comment.
[P1] Resolve equal MIN/MAX candidates deterministically, including provenance. Both the fixed and byte implementations replace the incumbent only when comp(...) < 0; equal visible values therefore retain whichever partial arrived first. With one candidate carrying Float provenance and the other ordinary-string provenance, the same value 5 later becomes numeric BIT 5 or byte BIT 53. Parallel partials are merged in arrival order, so this is externally observable scheduling-dependent corruption. Define an associative/commutative tie/conflict rule (for example collapse conflicting provenance to ordinary/unknown) and add reversed-order, parallel, and spill regressions that assert the final BIT value, not only the metadata.
| } | ||
| } | ||
| if hasPrepareParamKinds { | ||
| if err := writePrepareParamKindTrailer(proc.Ctx, buf, ctr.aggExprs, |
There was a problem hiding this comment.
[P1] Group spill still drops provenance on group-by key vectors. gbBatch is built with UnionInt32 (which preserves row sidecars), but the record is serialized with the stable MarshalBinaryWithBuffer at lines 407-408 and reloaded with legacy UnmarshalFromReader at lines 625-626. The PPK trailer added here covers only aggregate winner state; it never covers gbBatch.Vecs. A prepared numeric group key that survives in memory therefore becomes ordinary byte semantics only when a forced spill occurs, so a value 5 can become 53 instead of numeric 5 on a later BIT cast. The current spill tests tag only the aggregate input vector, not the group key. Use the provenance-aware batch codec or an equivalent key trailer and add a forced-spill group-key-to-BIT regression.
| v.resetPrepareParamKind() | ||
| return | ||
| } | ||
| kinds, owner, err := v.allocatePrepareParamKinds(len(selected), nil) |
There was a problem hiding this comment.
[P2] Do not turn sidecar allocation failure into panic. Shrink has no error return, and this new remapper allocates a second row-kind slice while the old sidecar is still owned; an allocation-account/MPool limit can therefore return an error here. The unconditional panic(err) converts recoverable query OOM into an internal panic after the payload has already been mutated. Shuffle has the same panic path at lines 2934-2937. Remap in place where possible, or make the operation transactional/error-returning, and add capped-MPool tests for heterogeneous sidecars.
| } | ||
| } | ||
|
|
||
| func (timeWin *TimeWin) observePrepareParamKinds() { |
There was a problem hiding this comment.
[P2] The new observation here covers only aggregate arguments; partition-key provenance is still lost in the non-T_any broadcast path. Sliding/gapfill uses setPartVecsForWindows, whose partSet is GetConstSetFunction; its SetConstFixed/SetConstBytes writes the broadcast value but does not copy w's PrepareParamKind. Thus a prepared numeric partition key is retained through evalPartVector but is lost when emitted across window rows, and a later BIT cast sees byte semantics. The interval path forwards the source vector and does not have this gap. Add a prepared partition-key-to-BIT regression for sliding/gapfill and copy the metadata in this setter boundary.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes: I found one correctness gap in the prepared-parameter provenance mapping.
MYSQL_TYPE_BIT is decoded as a numeric uint64 in ParseExecuteData, but binaryProtocolPrepareParamKind does not classify it as PrepareParamInteger. Therefore a COM_STMT_EXECUTE parameter whose wire type is MYSQL_TYPE_BIT reaches strToBit with PrepareParamNone and is interpreted as bytes. For a canonical value 1, that yields ASCII 49 rather than numeric 1. This affects binary prepared BIT assignments/casts even though the broader numeric provenance tests pass.
Please add MYSQL_TYPE_BIT to the integer mapping and add a regression that sends a COM_STMT_EXECUTE packet with new_params_bound_flag=1 and MYSQL_TYPE_BIT, together with an ordinary string control.
Validation on the exact head:
- Focused changed packages passed, including frontend, vector/batch, cast, aggregate/group/window/timewin/top/spill, process, shardservice, dispatch and compile.
- TestIssue26725PreparedBit64Numeric passed.
- Focused race tests passed for vector, batch, aggexec, group, timewin and top.
- PR CI has no failed checks, but Ubuntu UT, ARM64 SCA, coverage, pessimistic E2E and proxy-compose remain pending.
| func binaryProtocolPrepareParamKind(mysqlType defines.MysqlType) vector.PrepareParamKind { | ||
| switch mysqlType { | ||
| case defines.MYSQL_TYPE_TINY, defines.MYSQL_TYPE_SHORT, defines.MYSQL_TYPE_INT24, | ||
| defines.MYSQL_TYPE_LONG, defines.MYSQL_TYPE_LONGLONG, defines.MYSQL_TYPE_YEAR: |
There was a problem hiding this comment.
ParseExecuteData explicitly accepts MYSQL_TYPE_BIT and decodes it as a numeric uint64, but this classifier falls through to PrepareParamNone because MYSQL_TYPE_BIT is omitted here. That makes a binary prepared BIT parameter such as numeric 1 reach strToBit through the ordinary byte-string path and become ASCII 49, instead of numeric 1. Please include MYSQL_TYPE_BIT in the integer cases and add an exact protocol regression with new_params_bound_flag=1, plus a string control.
XuPeng-SH
left a comment
There was a problem hiding this comment.
[P1] Make provenance allocation failure transactional across vector/batch union paths.
Vector.UnionOne publishes the new logical length at vector.go:4634 and copies the payload before appendPrepareParamKindAt can allocate the heterogeneous sidecar at vector.go:4681. If that allocation is rejected by the destination allocation account or MPool, the method returns an error but leaves the appended row visible.
I reproduced this on exact head 5b6688925ef6e32dd595fa3b53a252130b3cf7b8: create an accounted T_text destination with one allocation slot, PreExtend(2), append ordinary "6"; create source "5" with PrepareParamFloat; then dst.UnionOne(src, 0, mp) returns mpool.ErrAllocationMetadataSlots, but dst.Length() is 2 instead of the original 1. Through Batch.UnionOne, the vector is length 2 while Batch.RowCount() remains 1; with multiple columns, earlier columns may also have committed before a later one fails. The same post-publication propagation ordering exists in UnionMulti/Union/UnionBatch/GetUnionAll.
Please preflight provenance growth before publishing data/length, or roll every affected vector and batch back on provenance failure, and add hard-cap allocation-account regressions for the vector and batch union variants.
Other focused checks on this head passed: vector/batch/pSpool, aggexec/group/dispatch/TOP, fill/mergeorder, timewin/window, cast/function, frontend provenance tests, and TestIssue26725PreparedBit64Numeric. The uniform UnionBatch benchmark remains ~68 ns/op, 0 allocs.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review complete at 827d61c. The main-branch conflict is resolved by preserving MORPCVersion11 for the bounded Sorted64 membership-filter wire format and assigning MORPCVersion12 to prepared-parameter provenance. Reviewed functional closure, mixed-version fail-closed behavior, allocation-failure atomicity, ownership/reset/free paths, aggregate/spill/remote boundaries, and regression coverage. No blocking issues found.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed exact head 827d61cf39e5f93200b40cecd263eef5a088d0cf against current origin/main ec06a68b80750b77d1b0eeb6634e2ba9f5529219. No P0-P3 findings remain.
I re-reviewed the complete 71-file diff and the prepared-parameter provenance paths through frontend resolution, vector/batch ownership and OOM rollback, expression/aggregate/window propagation, spill/remote transport, and BIT casting. The prior P1 from my review at 74ff50eb was explicitly answered in the PR conversation and is resolved by the declared-type lookup plus DECIMAL/YEAR/VARCHAR and shadowing coverage.
While this review was in progress, the head advanced from 0f2c77c6 to 827d61cf and merged current main. I checked that resolution specifically: v11 remains reserved for Sorted64, prepared provenance is gated on v12, and the v11 fail-closed/v12-enabled compatibility matrix covers dispatch, group partial wire, and process metadata. Six focused compatibility tests passed locally; git diff --check passed; all pre-merge checks on this head reached terminal non-failing states.
The PR was merged externally while this review was being finalized; this review event records the result against the exact reviewed head.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #26740.
What this PR does / why we need it:
MatrixOne transports prepared parameters internally through a transient text vector. That transport erased the source conversion semantics before assignment to
BIT(M), so the same value could be interpreted as ASCII bytes instead of a number.This PR preserves the source conversion category across binary COM_STMT_EXECUTE, SQL EXECUTE USING, normal user-variable evaluation, prepared multi-assignment SET staging and rollback, process serialization, remote compile, and shard reads:
The metadata uses the existing process transport with backward decoding for legacy/no-metadata and the prior integer-only layout. Mixed-commit shard reads use the versioned method and are rejected before execution. The default path keeps metadata nil, so ordinary string parameters do not add an allocation.
Validation