Skip to content

[Bug]: BIT_COUNT exposes a parsing error instead of coercing nonnumeric strings #28219

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

No open or closed issue was found for this behavior.

Branch Name

main

Commit ID

e7bb0572235ec4bac81eb098eb0ad8900f0065ab

Other Environment Information

  • Local standalone MatrixOne
  • Reference: MySQL 8.3.0

Actual Behavior

BIT_COUNT() raises an internal strconv.ParseUint error for a nonnumeric string or a string with a numeric prefix followed by other characters:

SELECT BIT_COUNT('abc');
-- MatrixOne: ERROR 1105 (HY000): strconv.ParseUint: parsing "abc": invalid syntax
-- MySQL: 0

SELECT BIT_COUNT('12x');
-- MatrixOne: ERROR 1105 (HY000): strconv.ParseUint: parsing "12x": invalid syntax
-- MySQL: 2   -- numeric prefix 12; BIT_COUNT(12) = 2

The same conversion error aborts a query over a VARCHAR column as soon as one row contains either value:

CREATE TABLE t(id INT PRIMARY KEY, v VARCHAR(20));
INSERT INTO t VALUES (1, 'abc'), (2, '12x'), (3, '');
SELECT id, BIT_COUNT(v) FROM t ORDER BY id;
-- MatrixOne: ERROR 1105 (HY000): strconv.ParseUint: parsing "abc": invalid syntax
-- MySQL: (1,0), (2,2), (3,0)

Numeric strings, surrounding spaces, negative strings, and empty strings already produce the expected values. The affected constant and column cases reproduced identically in three runs.

Expected Behavior

BIT_COUNT() should use MySQL-compatible numeric string conversion: a nonnumeric string converts to zero, and a leading numeric prefix is consumed. It must not expose a Go parsing error or abort the whole row set for these inputs.

Steps to Reproduce

SELECT BIT_COUNT('abc');
SELECT BIT_COUNT('12x');

CREATE DATABASE bit_count_repro;
USE bit_count_repro;
CREATE TABLE t(id INT PRIMARY KEY, v VARCHAR(20));
INSERT INTO t VALUES (1, 'abc'), (2, '12x'), (3, '');
SELECT id, BIT_COUNT(v) FROM t ORDER BY id;

Additional information

BitCountNonBinaryString calls bitCountFromMysqlIntegerString, but the parser returns its conversion error instead of applying MySQL's string-to-integer coercion behavior. The unit test TestBitCountStringInvalidFormat currently asserts that these formats return an error, so the incorrect behavior is encoded in the implementation test.

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. Ariznawlll commented on Sep 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:bcd5ed833b5400fe95f322e4028adb2bde3de0a4
    • 部署方式:本地单 CN/TN/LogService,使用 etc/launch/launch.toml,SQL 端口 6001
    • 测试日期:2026-09-07

    原问题验证

    在上述版本执行原问题中的常量和列值:BIT_COUNT('abc')、BIT_COUNT('12x')、BIT_COUNT(''),并补充带空格和负号的前缀值 BIT_COUNT(' -3tail')。常量结果分别为 0、2、0、63,不再返回 strconv.ParseUint 错误。建立 VARCHAR 表插入相同四类值后逐行查询,结果为 (1,0)、(2,2)、(3,0)、(4,63)。

    以上 SQL 在同一环境连续执行 3 轮,3/3 轮结果一致,查询均正常完成;表和数据库均在每轮结束时清理。

    Happy Path 覆盖

    1. 普通数字字符串控制 BIT_COUNT('64') 返回 1。
    2. 非数字字符串、数字前缀字符串、空字符串和带符号前缀字符串分别返回 0、2、0、63。
    3. VARCHAR 列逐行执行相同转换,所有行均返回结果且行顺序、值与输入一致。

    Unhappy Path 覆盖

    1. 纯非数字字符串 abc:不再暴露解析错误,返回 0。
    2. 数字前缀后跟非数字字符 12x:不报错,按数字前缀转换并返回 2。
    3. 空字符串及带空格/负号的边界输入:不报错,分别返回 0 和 63;失败后表数据保持完整并完成清理。

    白盒验证

    不适用。本问题通过公开 SQL 接口验证,未使用内部故障注入。

    回归测试

    已加入现有 MOTR PR #147,新增:

    suites/14_issue_regression/t/issue_28219_bit_count_string_coercion.test

    对应结果文件:

    suites/14_issue_regression/r/issue_28219_bit_count_string_coercion.result

    本地 MOTR 定向回归命令 ./motr --repeat 3 14_issue_regression.issue_28219_bit_count_string_coercion 结果为 3/3 success、27/27 statements success。

    测试证据

    测试结论

    测试通过。

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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions