Skip to content

[Bug]: protocol prepared UPDATE corrupts indexed readback for VARBINARY and BIGINT UNSIGNED #25437

Closed

Description

@Ariznawlll

Summary

On latest main (7e70bee98), a binary-protocol prepared UPDATE can make indexed/point read paths return incorrect values for updated VARBINARY and BIGINT UNSIGNED columns, while a full table scan returns the correct data.

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

Go repro body:

stmt, err := db.Prepare("update pp_dst set status=?, amount=?, dt=?, tm=?, bin=?, u=? where tenant=? and id=?")
_, err = stmt.Exec(
    "paid",
    "99.50",
    "2024-03-03 03:03:03.123456",
    "03:03:03.123456",
    []byte{0x7a, 0x7b},
    "99",
    1,
    101,
)

Table/data setup:

drop database if exists pp_dml_readpath;
create database pp_dml_readpath;
use pp_dml_readpath;

create table pp_dst (
  tenant int not null,
  id int not null,
  acct varchar(20) not null,
  amount decimal(10,2),
  status varchar(20),
  dt datetime(6),
  tm time(6),
  bin varbinary(8),
  u bigint unsigned,
  primary key (tenant, id),
  unique key uk_dst_acct (tenant, acct),
  key idx_dst_status_amount_id (status, amount, id),
  key idx_dst_dt_tenant_id (dt, tenant, id),
  key idx_dst_u_status_id (u, status, id),
  key idx_dst_bin_id (bin, id)
);

insert into pp_dst values
  (1,101,'a1',10.25,'new','2024-01-02 10:20:30.123456','10:20:30.123456',x'4142',18446744073709551615),
  (1,102,'a2',20.25,'old','2024-01-03 11:00:00.000000','11:00:00.000000',x'414243',8),
  (2,201,'b1',30.75,'paid','2024-02-01 09:00:00.000000','12:00:00.000000',x'00ff',7);

After executing the protocol prepared UPDATE above, run these reads:

select tenant,id,status,amount,dt,tm,hex(bin),u
from pp_dst
where tenant=1 and id=101;

select tenant,id,status,amount,dt,tm,hex(bin),u
from pp_dst
where status='paid' and amount='99.50'
order by tenant,id;

select tenant,id,status,amount,dt,tm,hex(bin),u
from pp_dst
where u='99' and status='paid'
order by tenant,id;

select tenant,id,status,amount,dt,tm,hex(bin),u
from pp_dst
where bin=x'7a7b'
order by tenant,id;

select tenant,id,status,amount,dt,tm,hex(bin),u
from pp_dst
order by tenant,id;

Expected

MySQL returns the updated row consistently through all read paths:

1  101  paid  99.50  2024-03-03 03:03:03.123456  03:03:03.123456  7A7B  99

Actual on MatrixOne

Indexed/point predicates return corrupted bin and u values:

where tenant=1 and id=101:
1  101  paid  99.50  2024-03-03 03:03:03.123456  03:03:03.123456  <empty hex(bin)>  4771354034768445440

where status='paid' and amount='99.50':
1  101  paid  99.50  2024-03-03 03:03:03.123456  03:03:03.123456  <empty hex(bin)>  4771354034768445440

where u='99' and status='paid':
1  101  paid  99.50  2024-03-03 03:03:03.123456  03:03:03.123456  <empty hex(bin)>  4771354034768445440

where bin=x'7a7b':
1  101  paid  99.50  2024-03-03 03:03:03.123456  03:03:03.123456  <empty hex(bin)>  4771354034768445440

But a full table scan returns the correct stored values:

select ... from pp_dst order by tenant,id:
1  101  paid  99.50  2024-03-03 03:03:03.123456  03:03:03.123456  7A7B  99

So the base row appears correct, but read paths using predicates/index lookup return wrong projected values after the protocol prepared UPDATE.

Additional notes

A smaller table updating only VARBINARY / BIGINT UNSIGNED did not reproduce this by itself; this repro uses a composite primary key plus multiple secondary indexes, which is closer to the real protocol-prepare exploration matrix.

Existing related issues found during search:

I did not find an existing issue for this protocol prepared UPDATE readback corruption.

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
    ai-easy
    on Jul 4, 2026
  5. Ariznawlll commented on Jul 6, 2026

    @Ariznawlll
    CollaboratorAuthor

    Verified on latest main 2a00828.

    Result: fixed.

    Validation used a Go driver protocol-level prepared statement (database/sql + go-sql-driver/mysql), not SQL PREPARE ... FROM.

    Covered shape:

    • composite primary key: primary key (tenant, id)
    • composite unique key: unique key (tenant, acct)
    • composite secondary indexes over status/amount/id, dt/tenant/id, u/status/id, bin/id
    • protocol prepared UPDATE ... WHERE tenant=? AND id=? with VARBINARY and BIGINT UNSIGNED parameters
    • readback through primary key, secondary indexes, varbinary predicate, and full scan

    Latest MO returns the updated row consistently:

    1|101|paid|99.50|2024-03-03 03:03:03.123456|03:03:03.123456|7A7B|99
    

    Regression added in matrixorigin/motr#39, commit 75bf03f:

    • suites/14_issue_regression/t/issue_25437_protocol_prepare_update.test
    • suites/scenarios/14_issue_regression/issue_25437_protocol_prepare_update.sh
    • suites/scenarios/14_issue_regression/issue_25437_protocol_prepare_update.go
    • suites/scenarios/14_issue_regression/out/issue_25437_protocol_prepare_update.out

    MOTR validation passed:

    [ISSUE_25437_PROTOCOL_PREPARE_UPDATE] success
    SUMMARY | total=4 success=4 failed=0 skipped=0 | stmts=7 ok=7 fail=0
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s-1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions