Skip to content

[Bug]: prepared SET inserts reject label strings as uint64 #27331

Closed as not planned
Closed as not planned

Description

@Ariznawlll

Description

Prepared INSERTs into a MySQL SET column reject normal label strings such as
a or a,b by trying to convert them to an unsigned integer. Numeric SET
indexes still work. Literal SQL, Connector/J client-prepared statements, and
MySQL server-prepared statements accept the same label values.

The failure affects both MySQL binary-protocol prepared statements and SQL
PREPARE / EXECUTE.

Environment

  • Branch: main
  • Commit: 47e022e10f2dbdf5f6b440417f8be80908027e63
  • Deployment: local mo-service, 1 Log / 1 TN / 1 CN
  • Connector/J: 8.0.33 and 8.0.15
  • JDBC server path: useServerPrepStmts=true, cachePrepStmts=false,
    emulateUnsupportedPstmts=false
  • Control: MySQL 8.0.46

Steps to reproduce

create database prepared_set_repro;
use prepared_set_repro;
create table t(id int primary key, tags set('a','b','c'));

JDBC binary prepared statement:

try (PreparedStatement ps = connection.prepareStatement(
        "insert into t(id,tags) values (?,?)")) {
    ps.setInt(1, 1);
    ps.setString(2, "a,b");
    ps.executeUpdate();
}

SQL prepared statement:

prepare p from 'insert into t(id,tags) values (?,?)';
set @id = 2, @tags = 'a,b';
execute p using @id, @tags;

Actual behavior

Both prepared paths fail without inserting a row:

SQLState HY000 / error 20203
invalid argument cast to uint64, bad value a,b

setString("a") fails in the same way. Binding integer 3, or the numeric
string "3", succeeds and stores a,b.

Expected behavior

Prepared INSERT should apply normal MySQL SET assignment semantics and store
label strings such as a and a,b. MySQL 8.0 accepts both values through the
same binary and SQL prepared paths.

Stability and controls

  • MatrixOne binary server-prepared reproduction: 3/3 with Connector/J 8.0.33.
  • MatrixOne SQL PREPARE reproduction: 3/3.
  • Connector/J 8.0.15: same MatrixOne failure in 3/3 runs.
  • MatrixOne useServerPrepStmts=false: label INSERT succeeds in 3/3 runs.
  • MatrixOne literal INSERT ... 'a,b': succeeds.
  • MySQL 8.0.46 server/client prepared and SQL prepared controls: all succeed in
    3/3 runs.
  • Failed executions leave no partial row; the connection remains usable.
  • ENUM label INSERT is a passing control.

Code analysis

MatrixOne represents a SET column with a uint64 storage type plus its member
definition. The special assignment conversion is selected in
pkg/sql/plan/make.go (funcCastForSetType) from the prepare-time expression
type. In this path the late-bound string reaches numeric index conversion,
which is consistent with the exact cast to uint64 error and with integer
bindings succeeding. The fix should preserve label conversion for string
bindings while retaining numeric-index semantics.

Regression coverage

Add real binary-protocol and SQL prepared regressions for single and multiple
SET labels, numeric indexes, NULL, invalid labels, repeated rebinding, batch
INSERT, and recovery after a rejected value. Keep literal/client-prepared and
MySQL-compatible stored-value controls.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 19, 2026
  2. added
    kind/bug
    on Aug 19, 2026
  3. Ariznawlll commented on Aug 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充在最新 main 的 SQL PREPARE/EXECUTE 复现:

    • commit:e866c535f5723fca6a8522c8338f7277e4b9e40f
    • 环境:本地 mo-service,1 Log / 1 TN / 1 CN,临时全新数据目录
    • 结果:以下最小用例连续复现 3/3。
    create table t (id int primary key, tags set('x', 'y', 'z'));
    prepare p from 'insert into t(id, tags) values (?, ?)';
    
    set @id = 1, @tags = 'x,z';
    execute p using @id, @tags; -- ERROR 20203: invalid argument cast to uint64, bad value x,z
    
    set @id = 2, @tags = 5;
    execute p using @id, @tags; -- succeeds and stores x,z
    insert into t values (3, 'x,z'); -- literal control succeeds
    select id, tags from t order by id;

    每轮失败后表中只保留 2 | x,z 和 3 | x,z,说明失败写入没有部分落盘;随后 SELECT 1 也正常,服务保持可用。该结果与本 issue 的 INSERT 路径结论一致。

  4. Ariznawlll commented on Aug 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:e866c535f5723fca6a8522c8338f7277e4b9e40f
    • 部署:本地全新数据目录,1 Log / 1 TN / 1 CN
    • 驱动:Connector/J 8.4.0、9.7.0

    原问题验证

    以 SET('a','b') 列和参数值 a,b 验证,两个驱动各连续执行 3 轮:

    1. 文字 SQL INSERT ... VALUES (1, 'a,b') 成功并插入 1 行。
    2. useServerPrepStmts=false 的客户端 PREPARE 成功并插入 1 行。
    3. useServerPrepStmts=true 的服务端 PREPARE,PreparedStatement.setString(2, "a,b") 均失败:invalid argument cast to uint64, bad value a,b,失败后表中没有该行。

    Happy Path 覆盖

    1. 文字 SQL 和客户端 PREPARE 都将 a,b 正确存为 SET 成员。
    2. 使用数值索引 3 的 SQL PREPARE 仍可存储 a,b,和已有 issue 中的对照一致。

    Unhappy Path 覆盖

    1. 服务端 PREPARE 的标签参数 a,b 在两个驱动中均失败。
    2. 失败后表中没有该行,相同 statement 随后仍可执行其他 SQL,连接没有失效。

    白盒验证

    不适用。本次通过 JDBC 服务端 PREPARE 外部接口复现;本 issue 既有 uint64 转换路径分析可解释该错误。

    回归测试

    未新增回归用例。该路径尚未修复,不能将标签字符串失败固化为成功基线。

    测试证据

    两代 Connector/J 各 3 轮,共 6/6 轮稳定复现;文字 SQL、客户端 PREPARE 和数值索引路径均作为对照执行。

    测试结论

    测试不通过。

  5. added theissue type on Sep 23, 2026
  6. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    This report is now tracked together with #27332. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.

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