You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: REPLACE does not publish its generated AUTO_INCREMENT value through LAST_INSERT_ID #28237
REPLACE can generate and persist a new AUTO_INCREMENT value without publishing that value through the session's LAST_INSERT_ID(). The stored row and the protocol/session state therefore disagree.
Environment
MatrixOne official main: e7bb0572235ec4bac81eb098eb0ad8900f0065ab
Clean local single-CN build and isolated data directory
MySQL 8.3 comparison instance
Reproduction
CREATEDATABASEreplace_last_id;
USE replace_last_id;
CREATETABLEt (
id INT AUTO_INCREMENT PRIMARY KEY,
u INT UNIQUE,
v INT
);
INSERT INTO t(u,v) VALUES (10,1);
-- stored row: id=1
REPLACE INTO t(u,v) VALUES (10,2);
-- replacement deletes id=1 and inserts id=2SELECT id,u,v FROM t;
SELECT LAST_INSERT_ID();
MatrixOne returns:
t: 2 | 10 | 2
LAST_INSERT_ID(): 1
MySQL returns:
t: 2 | 10 | 2
LAST_INSERT_ID(): 2
The stale value is not merely the replaced row's ID. If another AUTO_INCREMENT table first sets the session value to 700, then the same replacement inserts a new row but LAST_INSERT_ID() remains 700.
Affected rows remain 2, so the statement is correctly recognized as delete plus insert; only the generated ID is missing from session/protocol state.
Expected behavior
When REPLACE generates an AUTO_INCREMENT value, LAST_INSERT_ID() and the OK packet's insert ID should expose the generated value, matching the row actually inserted and MySQL behavior.
Applications using REPLACE followed by LAST_INSERT_ID() must not receive an unrelated value from an earlier statement.
Scope
Basic REPLACE row semantics are correct here: the conflicting unique-key row is deleted, a new row with the next ID is inserted, and affected rows is 2. This issue is limited to publishing the generated ID.
PR #28349 has been merged into main and fixes the original reproduction in this issue.
When REPLACE deletes a conflicting row and inserts a new row with a generated AUTO_INCREMENT value, the generated value is now published through the statement/session LAST_INSERT_ID() path. The fix covers the stale-value case where the session previously held an unrelated insert ID.
The merged PR includes a real SQL regression covering REPLACE, the inserted row ID, affected rows, and LAST_INSERT_ID(). This resolves the contract described by this issue; broader REPLACE behavior outside generated AUTO_INCREMENT ID publication is not changed by this fix.
Activity
fix(auto-increment): honor session and ordered insert semantics (#28349)
XuPeng-SH commentedon Sep 8, 2026
Resolution update
PR #28349 has been merged into
mainand fixes the original reproduction in this issue.When
REPLACEdeletes a conflicting row and inserts a new row with a generated AUTO_INCREMENT value, the generated value is now published through the statement/sessionLAST_INSERT_ID()path. The fix covers the stale-value case where the session previously held an unrelated insert ID.The merged PR includes a real SQL regression covering
REPLACE, the inserted row ID, affected rows, andLAST_INSERT_ID(). This resolves the contract described by this issue; broader REPLACE behavior outside generated AUTO_INCREMENT ID publication is not changed by this fix.Ariznawlll commentedon Sep 8, 2026
测试版本
原问题验证
初始 INSERT 后执行唯一键冲突 REPLACE,3 轮均读回新行 2|10|2 且 LAST_INSERT_ID()=2。
Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
pkg/tests/issues 的 TestIssue28349AutoIncrementPublicPaths 覆盖 REPLACE generated id 发布。
回归测试
已加入 motr#151:14_issue_regression.issue_28237_28239_auto_increment_session,MOTR 3 轮通过。
测试证据
每轮均验证 2/2 与陈旧值控制后的 3/3。
测试结论
测试通过。
fix(auto-increment): honor session and ordered insert semantics (matr…
fix(auto-increment): honor session and ordered insert semantics (matr…
fix(auto-increment): honor session and ordered insert semantics (matr…