Skip to content

[Bug]: Prepared string parameters lose exact BIGINT UNSIGNED and BIT(64) comparison precision above 2^53 #27492

Closed

Description

@ck89119

Is there an existing issue for the same bug?

  • I have checked the existing issues.

This is a leaf issue for PR #27466. It is intentionally separate from the DECIMAL common-domain scope of #27088 / PR #27483.

Branch Name

issue-25408-runtime-main (PR #27466)

Commit ID

1181297077afd7fb9de428a54e5cf8bbe1759add

Other Environment Information

  • Local embedded MatrixOne engine through pkg/tests/issues
  • SQL PREPARE / EXECUTE USING
  • Boundary values around IEEE-754 2^53

Actual Behavior

On PR #27466, a string-backed prepared parameter used against an exact BIGINT UNSIGNED or BIT(64) column is converted through FLOAT64. Adjacent integer values above 2^53 then compare equal.

For BIGINT UNSIGNED with parameter '9007199254740993':

  • Direct string comparison returns only row 2.
  • SQL prepared comparison returns rows 1,2.

For BIT(64) with the same parameter:

  • Direct string comparison returns only row 2.
  • SQL prepared comparison returns rows 1,2.

The exact-base control at 6ff9be9646a6ac43e05ba3063de27b2248bbac62 returned only row 2 for the prepared BIGINT UNSIGNED witness, confirming that case as a PR #27466 regression.

Expected Behavior

Prepared execution must preserve the exact comparison domain established by BIGINT UNSIGNED and BIT(64). Direct and prepared forms must both return only row 2; no string-backed exact operand may be rounded through FLOAT64.

Steps to Reproduce

CREATE TABLE prepared_exact_integer_cmp (
  id INT PRIMARY KEY,
  u BIGINT UNSIGNED,
  b BIT(64)
);

INSERT INTO prepared_exact_integer_cmp VALUES
  (1, 9007199254740992, 9007199254740992),
  (2, 9007199254740993, 9007199254740993),
  (3, 9007199254740994, 9007199254740994);

SELECT id
FROM prepared_exact_integer_cmp
WHERE u = '9007199254740993'
ORDER BY id;
-- Expected and direct actual: 2

PREPARE pu FROM
  'SELECT id FROM prepared_exact_integer_cmp WHERE u = ? ORDER BY id';
SET @p = '9007199254740993';
EXECUTE pu USING @p;
-- Expected: 2
-- PR #27466 actual: 1,2

SELECT id
FROM prepared_exact_integer_cmp
WHERE b = '9007199254740993'
ORDER BY id;
-- Expected and direct actual: 2

PREPARE pb FROM
  'SELECT id FROM prepared_exact_integer_cmp WHERE b = ? ORDER BY id';
EXECUTE pb USING @p;
-- Expected: 2
-- PR #27466 actual: 1,2

Additional information

The current PR-head implementation in pkg/sql/plan/visit_plan_rule.go recognizes a fixed exact prepared comparison only when a non-parameter operand is DECIMAL. Otherwise, a string-backed numeric argument is converted to FLOAT64, which loses integer identity above 2^53.

Ownership and acceptance:

Activity

  1. self-assigned this
    on Aug 23, 2026
  2. added
    kind/bug
    severity/s1
    and removed on Aug 23, 2026
  3. ck89119 commented on Aug 31, 2026

    @ck89119
    ContributorAuthor

    Verified against the latest main (3f05ced24a). This issue is no longer reproducible.

    The fix is present in bebb63f02f (fix: preserve exact BIGINT and BIT prepared comparisons). I ran:

    go test ./pkg/tests/issues -run TestIssue27088PreparedDecimalCommonType -count=1 -v
    

    The issue-specific SQL PREPARE and COM_STMT regression cases both passed for BIGINT UNSIGNED and BIT(64):

    TestIssue27088PreparedDecimalCommonType/issue_27492_COM_STMT_exact_integer_comparison
    TestIssue27088PreparedDecimalCommonType/issue_27492_SQL_PREPARE_exact_integer_comparison
    

    The full targeted test passed as well. This issue can be closed.

  4. Ariznawlll commented on Sep 1, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • MatrixOne main@33af6ae3c0c23e4f277137460577ea64678f7ecf
    • 1 Log / 1 TN / 2 CN / Proxy,2026-09-01

    原问题验证

    BIGINT UNSIGNED 与 BIT(64) 在 2^53-1、2^53、2^53+1、2^53+2 边界上,prepared 字符串参数均精确命中对应唯一行,未再发生浮点舍入误匹配。

    Happy Path 覆盖

    • direct 与 prepared 查询结果一致。
    • 同一 handle 在字符串、整数及相邻边界值之间复用,各次结果独立且正确。

    Unhappy Path 覆盖

    • NULL 参数返回空集,未沿用前一次绑定值。
    • 相邻超大整数分别命中不同记录,覆盖最容易被舍入合并的边界。

    白盒验证

    不适用。问题可通过公开 prepared SQL 与精确结果集合验收。

    回归测试

    • 已加入 motr#136:issue_27492_prepared_exact_integer.test/.result。
    • Big-data / Stability / Chaos 均不需要:缺陷是单参数精度转换,与行数、运行时长和外部故障无关。

    测试证据

    • BIGINT UNSIGNED 边界与 prepared 复用语义已用 MySQL 8.3 对照。
    • MySQL 的 BIT(64) 文本比较转换与本 issue 的精确值契约不同,因此该部分 golden 依据 issue 契约,并由 MatrixOne direct/prepared 两条路径互相校验。
    • MOTR 重复 3/3 轮通过,完整套件中本用例通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions