Skip to content

[Bug]: protocol prepared SELECT returns empty HEX(BLOB) after prepared UPDATE #25439

Closed

Description

@Ariznawlll

Summary

On latest main (7e70bee98), after a binary-protocol prepared UPDATE updates a BLOB column, a binary-protocol prepared SELECT hex(b) can return empty strings for BLOB values, while the same data is correct when queried through the MySQL CLI / text protocol.

This was found during protocol-level prepared statement exploration with Go database/sql + go-sql-driver/mysql (db.Prepare, i.e. COM_STMT_PREPARE), comparing MySQL 8.0.45 and MatrixOne.

Environment

  • MatrixOne: latest main at 7e70bee98
  • MySQL oracle: MySQL 8.0.45
  • Driver: github.com/go-sql-driver/mysql v1.8.1
  • Path: binary-protocol prepared statement (db.Prepare), not SQL-level PREPARE ... FROM

Reproduce

Table/data setup:

drop database if exists pp_json_blob_seq;
create database pp_json_blob_seq;
use pp_json_blob_seq;

create table t (
  id int primary key,
  j json,
  txt text,
  b blob,
  d decimal(12,4),
  tm time(6),
  status varchar(20),
  key idx_status_d(status,d)
);

insert into t values
  (1,'{"a":1,"b":"x"}','hello',x'414243',12.3456,'10:20:30.123456','new'),
  (2,'{"a":2,"b":null}',null,null,null,null,'new'),
  (3,null,'bye',x'00ff',-1.2500,'-01:02:03.000000','old');

Run the following via Go database/sql prepared statements:

// Before update: prepared SELECT returns correct hex(b).
db.Prepare("select id, hex(b) from t order by id")

stmt, _ := db.Prepare("update t set d=?, tm=?, b=? where id=?")
stmt.Exec("88.1250", "08:08:08.000001", []byte{0x88, 0x12}, 2)

// After update: prepared SELECT returns wrong hex(b) on MO.
db.Prepare("select id,d,tm,hex(b) from t order by id")

Expected

MySQL 8.0.45 returns:

before:
1  414243
2  NULL
3  00FF

after prepared UPDATE:
1  12.3456   10:20:30.123456   414243
2  88.1250   08:08:08.000001   8812
3  -1.2500   -01:02:03.000000  00FF

Actual on MatrixOne

Before the prepared UPDATE, the prepared SELECT is correct:

1  414243
2  NULL
3  00FF

After the prepared UPDATE, protocol prepared SELECT returns empty hex values for rows 1 and 2:

1  12.3456   10:20:30.123456   <empty>
2  88.1250   08:08:08.000001   <empty>
3  -1.2500   -01:02:03.000000  00FF

However, querying the same table through the MySQL CLI / text protocol returns the correct values on MO:

1  12.3456   10:20:30.123456   414243
2  88.1250   08:08:08.000001   8812
3  -1.2500   -01:02:03.000000  00FF

So the stored data appears correct; the wrong result is specific to the binary-protocol prepared SELECT path after a prepared UPDATE involving BLOB data.

Related issues

I did not find an existing issue for this BLOB/HEX prepared SELECT behavior.

Activity

  1. added this to the MO-202607 milestone on Jul 3, 2026
  2. added
    kind/bug
    on Jul 3, 2026
  3. added theissue type on Jul 3, 2026
  4. added
    severity/s0
    and removed on Jul 10, 2026
  5. ck89119 commented on Jul 11, 2026

    @ck89119
    Contributor

    Verified end-to-end against the current main production code using database/sql with go-sql-driver/mysql and protocol-level prepared statements.

    The issue is no longer reproducible. After executing the prepared update:

    updated rows: 1
    

    The subsequent prepared SELECT returns:

    id=1 d=12.3456 tm=10:20:30.123456 hex=414243
    id=2 d=88.1250 tm=08:08:08.000001 hex=8812
    id=3 d=-1.2500 tm=-01:02:03.000000 hex=00FF
    

    A direct text-protocol SELECT returns the same values.

    The root cause is the binary-protocol TIME microsecond width bug fixed by commit 5fe5e46fc in #25448: the encoder previously wrote the 4-byte microsecond field as 8 bytes, shifting the client-side decode offset for subsequent columns such as hex(b). Therefore, this issue is already fixed on current main.

  6. Ariznawlll commented on Jul 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main@2865ed6cc8a39727b8b274bb52b88fe441d0b30c 重新做 protocol-level 端到端验证,结果通过。

    • database/sql + go-sql-driver/mysql v1.8.1,interpolateParams=false,固定单物理连接。
    • prepared UPDATE 写入 TIME(6) 和 BLOB 后,同一个 prepared SELECT 连续执行 3 次;hex(b) 依次为 414243 / 8812 / 00FF。
    • 与 COM_QUERY/text protocol 逐行对比完全一致。
    • 额外把 hex(b) 同时放在 TIME(6) 前后,覆盖列解码 offset,两个投影值始终一致。

    确认 #25448 的 TIME 微秒宽度修复已覆盖本问题,当前 main 不再复现。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions