Skip to content

[Bug]: Prepared signed BIGINT string lookups select and update adjacent keys above 2^53 #29551

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Related #29506 concerns block-filter selectivity and explicitly preserves the historical DOUBLE fallback at the signed 2^53 boundary. #27492 covered BIGINT UNSIGNED/BIT and is closed. This is the remaining signed prepared-statement correctness/DML scope, supported by new independent MySQL prepared-protocol evidence; it is not another selectivity complaint. No dedicated open issue for the signed collateral-update witness was found.

Branch Name

main

Commit ID

79fa30e10c0b298567eb073cdfd88bdc91ab09b9 (final re-confirmation). Initially reproduced at e784c47e112756612cbdc792340e75161aab36d1.

Other Environment Information

  • Debian Linux x86_64, Go 1.26.4; CPU build from the pinned main commit.
  • Isolated standalone real SQL service, tested both before and after DN flush.
  • SQL PREPARE/EXECUTE using a VARCHAR variable; binary COM_STMT using mysql-connector-python.
  • Independent reference: MySQL 8.0.44, same schema, statements, and parameter values.
  • Current-main behavior is confirmed; this report does not claim that the recent performance fix introduced it.

Actual Behavior

Binding the complete integer string '9007199254740993' to a signed BIGINT predicate converts the key and parameter to DOUBLE. Adjacent keys 9007199254740992 and 9007199254740993 then both match.

A prepared UPDATE intended for the latter key changes both rows, commits successfully, and emits no warnings. MySQL's SQL and binary prepared executions update only the requested key. Binary integer binding and an explicit signed-CAST control also select only the requested row on MatrixOne; the failure depends on text binding.

Verified beyond equality: <>, <, <=, >, >= also return incorrect row sets at these neighboring values. Same-handle string→integer→NULL binary rebinding, repeated SQL execution, and a flushed-table witness distinguish this from stale state or a client decoding artifact.

Expected Behavior

A prepared exact signed-integer lookup supplied with a complete, representable integer string must preserve that integer's identity. UPDATE must not modify another primary-key row. MySQL prepared semantics must be checked independently: MySQL ordinary string-vs-integer comparison can use approximate comparison, but a marker inferred from a BIGINT peer is not the same contract.

Steps to Reproduce

DROP DATABASE IF EXISTS qa_signed_prepared;
CREATE DATABASE qa_signed_prepared;
USE qa_signed_prepared;
CREATE TABLE t(id BIGINT PRIMARY KEY,n INT);
INSERT INTO t VALUES
 (9007199254740992,0),
 (9007199254740993,0),
 (9007199254740994,0);

PREPARE p FROM 'SELECT id FROM t WHERE id=? ORDER BY id';
SET @v='9007199254740993';
EXECUTE p USING @v;
-- MatrixOne: 9007199254740992 and 9007199254740993
-- MySQL 8.0.44: only 9007199254740993
EXPLAIN FORCE EXECUTE p USING @v;
-- MatrixOne: CAST(t.id AS DOUBLE) = CAST(... AS DOUBLE)
DEALLOCATE PREPARE p;

PREPARE u FROM 'UPDATE t SET n=n+1 WHERE id=?';
EXECUTE u USING @v;
SHOW WARNINGS;
SELECT id,n FROM t ORDER BY id;
-- MatrixOne: (9007199254740992,1),(9007199254740993,1),(9007199254740994,0)
-- MySQL:     (9007199254740992,0),(9007199254740993,1),(9007199254740994,0)
-- Both report no warnings.
DEALLOCATE PREPARE u;

SELECT id FROM t WHERE id=CAST(@v AS SIGNED) ORDER BY id;
-- MatrixOne exact-domain control: only 9007199254740993.
DROP DATABASE qa_signed_prepared;

Additional information

Root cause at the existing prepared comparison owner:

  • preparedComparisonExactIntegerExpr in pkg/sql/plan/visit_plan_rule.go rejects signed representable values outside [-(2^53)+1, (2^53)-1], while its unsigned path checks the actual target integer width.
  • bindPreparedConsumerArguments in pkg/sql/plan/prepared_binding.go then casts text markers against integer peers to FLOAT64. The comparison overload also widens the BIGINT key, producing the observed collision and collateral UPDATE.
  • The signed cutoff intentionally retained old approximate behavior for the selectivity work in [Bug]: Prepared non-integer values on signed BIGINT keys lose block filtering #29506. Independent MySQL SQL/binary prepared execution demonstrates that retaining it is a correctness gap rather than a necessary prepared-compatibility fallback. This new evidence should inform the contract decision; do not silently conflate ordinary literal comparison with a typed prepared marker.

Suggested priority: P1 because the public DML witness updates an unrelated row. A fix must remain in the existing binding/comparison owner and distinguish complete in-range integer strings from fractional, trailing-text, invalid, NULL, scientific, signed/unsigned, and out-of-range inputs. Cover equality/ranges plus UPDATE/DELETE, SQL+binary protocols, same-handle type alternation, and memory/flushed scans. Do not require huge datasets or broaden ordinary explicit CAST semantics to verify this three-row failure.

Activity

  1. self-assigned this
    on Oct 1, 2026
  2. added
    kind/bug
    on Oct 1, 2026
  3. added a commit that references this issue on Oct 2, 2026
    7a169dd
  4. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:本地全新单 CN mo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE
    • 测试日期:2026-10-02

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。大于 2^53 的精确 BIGINT prepared select/update 只命中指定 key。

    Happy Path 覆盖

    覆盖相邻 BIGINT、正负值、查询与 DML。

    Unhappy Path 覆盖

    覆盖字符串/float 来源、NULL 和 BIGINT 越界;未发生相邻键碰撞。

    白盒验证

    关联修复 #29556 已进入当前 main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:大于 2^53 的精确 BIGINT prepared select/update 只命中指定 key。
    • 回归代码与 golden result 已提交到 MOTR #209;本地全量 14_issue_regression 中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。

    测试结论

    测试通过。

  5. Ariznawlll commented on Oct 8, 2026

    @Ariznawlll
    Collaborator

    在当前 main bab4b3286a0dd5683a9b291763817722233e586c 上使用真实 MySQL binary prepared statement 扩展了完整整数文本的查询和 DML 边界。

    数据包含 2^53-1、2^53、2^53+1、2^53+2、MaxInt64-1、MaxInt64 六个相邻/边界主键。同一 prepared handle 交替绑定文本、int64、NULL 和文本恢复,连续执行 3 轮。

    结果:

    • 文本 9007199254740993 的等值查询只返回该键,NULL 返回 NULL 集合,恢复后仍只返回该键;
    • < / <= / > / >= 的边界集合逐项准确,没有 2^53 相邻键碰撞;
    • derived JOIN 只连接 9007199254740993;
    • IN('9007199254740992','9007199254740993') 和对应 BETWEEN 各返回准确的两个键;
    • 文本 9223372036854775807 精确命中 MaxInt64;
    • UPDATE affected=1,只有 9007199254740993 的 n 从 0 变为 1;
    • 事务内 DELETE affected=1、剩余 5 行,回滚后数据恢复;
    • ODKU affected=2,只把目标键 n 从 1 更新为 11,其余五行保持 0。

    控制场景也保留原有非完整整数文本语义:小数文本、尾随字符和超出 BIGINT 的文本没有被错误纳入完整整数文本的精确收窄规则;随后再次绑定完整文本仍准确命中目标键。

    本轮没有观察到相邻键误选、collateral UPDATE/DELETE/ODKU 或同一 prepared handle 的类型/值泄漏。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions