Repository navigation
Description
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
mainat7e70bee98 - 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-levelPREPARE ... 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:
- [Bug]: Binary-protocol COM_STMT_PREPARE rejects REPLACE (missing replace_stmt in prepareable_stmt grammar) #25429 covers COM_STMT_PREPARE rejecting
REPLACEgrammar. - [Bug]: Prepared CTAS rejects parameter markers in SELECT expression #25425 covers prepared CTAS parameter marker rejection.
I did not find an existing issue for this protocol prepared UPDATE readback corruption.
Activity
fix: binary protocol TIME microsecond encoding corrupts subsequent co…
fix: binary protocol TIME microsecond encoding corrupts subsequent co…
Ariznawlll commentedon Jul 6, 2026
Verified on latest main 2a00828.
Result: fixed.
Validation used a Go driver protocol-level prepared statement (
database/sql+go-sql-driver/mysql), not SQLPREPARE ... FROM.Covered shape:
primary key (tenant, id)unique key (tenant, acct)status/amount/id,dt/tenant/id,u/status/id,bin/idUPDATE ... WHERE tenant=? AND id=?withVARBINARYandBIGINT UNSIGNEDparametersLatest MO returns the updated row consistently:
Regression added in matrixorigin/motr#39, commit 75bf03f:
suites/14_issue_regression/t/issue_25437_protocol_prepare_update.testsuites/scenarios/14_issue_regression/issue_25437_protocol_prepare_update.shsuites/scenarios/14_issue_regression/issue_25437_protocol_prepare_update.gosuites/scenarios/14_issue_regression/out/issue_25437_protocol_prepare_update.outMOTR validation passed:
fix: binary protocol TIME microsecond encoding corrupts subsequent co…
fix: binary protocol TIME microsecond encoding corrupts subsequent co…
fix: binary protocol TIME microsecond encoding corrupts subsequent co…