Repository navigation
Description
Summary
MatrixOne accepts and reads back session values for auto_increment_increment and auto_increment_offset, but implicit ID allocation does not use them with MySQL session semantics. The increment is ignored, while a non-default offset is captured only when the table is created and then affects other sessions as table state.
This is a concrete behavior within the broader AUTO_INCREMENT enhancement request #23371: applications can successfully configure the advertised variables but receive IDs that violate the configured sequence.
Environment
- MatrixOne official
main:e7bb0572235ec4bac81eb098eb0ad8900f0065ab - Clean local single-CN build and isolated data directory
- MySQL 8.3 comparison instance
Reproduction
Existing table
CREATE DATABASE ai_session_vars;
USE ai_session_vars;
CREATE TABLE t_existing (
id INT AUTO_INCREMENT PRIMARY KEY,
v INT
);
SET SESSION auto_increment_increment = 3,
auto_increment_offset = 2;
SELECT @@session.auto_increment_increment,
@@session.auto_increment_offset;
-- 3 | 2
INSERT INTO t_existing(v) VALUES (1),(2),(3);
SELECT * FROM t_existing ORDER BY id;MatrixOne generates:
1 | 1
2 | 2
3 | 3
MySQL generates:
2 | 1
5 | 2
8 | 3
Table created under a non-default session
SET SESSION auto_increment_increment = 3,
auto_increment_offset = 2;
CREATE TABLE t_cross (
id INT AUTO_INCREMENT PRIMARY KEY,
who VARCHAR(20)
);Use three sessions afterward:
-- session A retains default 1/1
INSERT INTO t_cross(who) VALUES ('default');
-- session B uses 4/3
SET SESSION auto_increment_increment = 4,
auto_increment_offset = 3;
INSERT INTO t_cross(who) VALUES ('four-three-a'),('four-three-b');
-- original DDL session still uses 3/2
INSERT INTO t_cross(who) VALUES ('three-two');MatrixOne produces IDs 2,3,4,5: the DDL-time offset becomes a table-level starting point and every session advances by one. MySQL produces 1,3,7,11: each insert selects values according to the writing session's increment and offset.
The mismatch is also visible after setting values to 7/4: MatrixOne reads the variables back as 7/4, while allocation still follows step 1.
Expected behavior
If these MySQL-compatible session variables are accepted and exposed, implicit allocation should honor the current writing session:
- values must satisfy the session's increment/offset progression;
- changing the variables must affect existing tables;
- a table created under one session must not force that session's offset on other sessions.
If the capability is intentionally unavailable, SET should not silently accept a configuration that has no corresponding write semantics.
Code observation
The DDL planner resolves auto_increment_offset and stores offset - 1 in the table's AUTO_INCREMENT metadata. There is no corresponding DML-time use of either session variable, and auto_increment_increment is only registered as a frontend variable. The increment service therefore continues with the table's persisted step of 1.
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 session AUTO_INCREMENT compatibility cases in this issue.The implementation now applies the current writing session's
auto_increment_incrementandauto_increment_offsetduring DML allocation, including for existing tables. The table creator's session settings no longer become shared table-level writer state. Statement boundaries and ALTER COPY reconciliation were also covered so session values do not leak into later statements or copied-table metadata.Validation includes non-default session series, multiple writers, creator/writer isolation, existing-table allocation, same-COM_QUERY session refresh, and multi-CN allocation invariants. Cross-CN reservation gaps remain allowed; the contract is the writer-session series, not globally consecutive IDs.
This resolves the behavior described by the issue's reproductions.
Ariznawlll commentedon Sep 8, 2026
测试版本
main8198fd4d7ec0c616a6c8b138f3c86284d70b2a5amo-search-commit-8198fd4d7e-20260908,3 CN、1 DN、3 LogService,通过 Proxy 端口转发连接原问题验证
在目标环境执行原问题的两组场景:
已有表
id INT AUTO_INCREMENT,当前 session 设置auto_increment_increment=3、auto_increment_offset=2,批量插入 3 行,返回 ID2,5,8,该单 session 场景符合预期。新建表的 session 设置为
3/2,随后使用三个独立连接:默认1/1插入一行、4/3插入两行、3/2插入一行。按 ID 排序,3 轮结果均为:MySQL 兼容语义应为各写入 session 按自身配置生成
1,3,7,11。目标环境仍将表创建时/分配块状态带入后续连接,未按写入 session 的 increment/offset 生成序列。Happy Path 覆盖
3/2。2,5,8。Unhappy Path 覆盖
该 issue 针对合法 session 配置的语义错误,不涉及非法输入或拒绝路径;本轮没有将合法配置误分类为 Unhappy Path。
白盒验证
不适用。本轮通过公开 SQL 和独立连接验证 session/协议可见行为,未修改源码或使用 injection。
回归测试
尚未新增回归文件。该场景需要多个独立连接验证 session 隔离,后续应放入 motr scenario/多连接回归,而不是仅用单连接 SQL 快照。
测试证据
目标环境 Proxy 查询输出:单 session 为
2,5,8;跨 session 3/3 均为2,10001,20003,20007。临时数据库和端口转发已清理。测试结论
测试不通过。
Ariznawlll commentedon Sep 8, 2026
测试版本
原问题验证
已有 AUTO_INCREMENT 表在 increment=3、offset=2 的会话中三行 INSERT,3 轮均生成 2,5,8。
Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
pkg/tests/issues 的 TestIssue28349AutoIncrementPublicPaths 覆盖公开 AUTO_INCREMENT 路径。
回归测试
已加入 motr#151:14_issue_regression.issue_28237_28239_auto_increment_session,MOTR 3 轮通过。
测试证据
每轮结果均为已有表 2,5,8、跨会话表 1,3,7,11。
测试结论
测试通过。
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…