Repository navigation
Description
Summary
In a multi-row INSERT IGNORE, MatrixOne assigns AUTO_INCREMENT candidates by original input position before duplicate rows are removed. MySQL assigns consecutive IDs to the accepted rows within the statement's reserved range and consumes the unused reservation afterward.
Consequently, a successful row receives a different generated primary key depending on where an ignored row appeared in the input list, even though MatrixOne and MySQL agree on the inserted payload rows and the next statement's high watermark.
Environment
- MatrixOne official
main:e7bb0572235ec4bac81eb098eb0ad8900f0065ab - Clean local single-CN build and isolated data directory
- MySQL 8.3 comparison instance
- Default
auto_increment_increment=1,auto_increment_offset=1
Reproduction
CREATE DATABASE insert_ignore_auto_id;
USE insert_ignore_auto_id;
CREATE TABLE t (
id INT AUTO_INCREMENT PRIMARY KEY,
u INT UNIQUE
);
INSERT INTO t(u) VALUES (10); -- id=1
INSERT IGNORE INTO t(u) VALUES (20),(10),(30);
SELECT * FROM t ORDER BY id;
INSERT INTO t(u) VALUES (99);
SELECT * FROM t ORDER BY id;MatrixOne assigns:
1 | 10
2 | 20
4 | 30
5 | 99
MySQL assigns:
1 | 10
2 | 20
3 | 30
5 | 99
The difference follows the ignored row's position:
Input values MatrixOne accepted IDs MySQL accepted IDs next ID in both
(10),(20),(30) 3,4 2,3 5
(20),(10),(30) 2,4 2,3 5
(20),(30),(10) 2,3 2,3 5
(10),(20),(10),(30) 3,5 2,3 6
In every row above, u=10 already exists before the multi-row statement.
Expected behavior
For MySQL-compatible INSERT IGNORE, accepted rows in one multi-row statement should receive the same generated IDs as MySQL. Ignored rows may consume reserved sequence space, as shown by the next statement starting at 5 or 6, but they should not shift the ID attached to a later accepted row inside the same statement.
The current behavior can break replication checks and application-side generated-key mapping even when the non-key payload and final sequence high watermark otherwise agree.
Code observation
AUTO_INCREMENT generation occurs in the pre-insert path before the duplicate-ignore filtering path shrinks the candidate batch. The remaining rows retain candidates associated with original positions, which matches the observed positional gaps.
Activity
XuPeng-SH commentedon Sep 8, 2026
Additional boundary: CHECK/FK-rejected rows also change the generated-ID mapping
A second, reproducible form of the same
INSERT IGNOREcontract gap exists when a row is ignored by aCHECKor childFOREIGN KEYconstraint, rather than by a duplicate key.Reproducer:
Observed result for
(id, uk):mainat0b195e4f5a23c06a40552a8db3e7fdf182979a3a(2,2), (4,3)0254156e80d190a2b7036b99f101ff816629cb60(2,2), (3,3)8.4.10(1,2), (2,3)The same result is reproduced with a child-FK violation: the first input row references a missing parent, while later rows reference an existing parent.
Root cause and scope
The execution order is currently:
INSERT IGNOREapplies CHECK/FK row filters.Therefore, a candidate belonging to a CHECK/FK-rejected row is removed before the arbiter can reuse it. PR #28349 improves the PK/UK arbitration path, but does not yet carry rejected-row provenance across these independent filters.
This is an inherited compatibility gap, not a regression newly introduced by PR #28349: the exact main baseline produces
2,4, while the PR improves it to2,3. It should nevertheless be tracked before claiming that #28238 is fully closed for everyINSERT IGNORErejection path.Recommended follow-up
Extend the acceptance criteria of this issue to cover all rows ignored by
INSERT IGNORE, including duplicate-key, CHECK, and FK rejection:LAST_INSERT_ID(), and base/index final-row identity.The separate limitation where a rejected positive explicit ID advances eager allocation remains documented in PR #28349 and should be tracked independently if it is not already covered by another issue.
fix(auto-increment): honor session and ordered insert semantics (#28349)
XuPeng-SH commentedon Sep 8, 2026
Scope update after PR #28349
PR #28349 has been merged into
main. It fixes the original duplicate PK/UKINSERT IGNOREcase: accepted rows are assigned AUTO_INCREMENT values in accepted-row order, while unused values may still remain reserved for the next statement. Composite and prefix unique-key arbitration, final index row identity, rollback/error cleanup, and multi-batch candidate handling are also covered by the merged tests.This issue should remain open for the broader
INSERT IGNOREcontract. The following boundary is still reproducible and is not closed by the merged change:The CHECK/FK rejection occurs before the ordered PK/UK arbiter receives the rows, so the rejected row's candidate provenance is not available for accepted-row assignment. The observed result on the PR validation head was
(2,2),(3,3), while MySQL returns(1,2),(2,3). The CHECK cases added to the PR use valid CHECK values and therefore do not cover this rejection path.The separate inherited case where a rejected positive explicit ID causes eager allocation/range checking to advance or fail is documented in the PR and also needs independent follow-up. The next fix should cover duplicate, CHECK, FK, and mixed rejection paths without rolling back globally owned reservations or evaluating volatile expressions twice.
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…
fix: make INSERT IGNORE tolerate NOT NULL violations (#32299)
fix(sql): preserve accepted INSERT IGNORE rows across constraint fail…