Skip to content

[Bug]: AUTO_INCREMENT session increment is ignored while offset is bound at table creation #28239

Closed

Description

@Ariznawlll

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

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. XuPeng-SH commented on Sep 8, 2026

    @XuPeng-SH
    Contributor

    Resolution update

    PR #28349 has been merged into main and fixes the original session AUTO_INCREMENT compatibility cases in this issue.

    The implementation now applies the current writing session's auto_increment_increment and auto_increment_offset during 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.

  5. added
    severity/s0
    and removed on Sep 8, 2026
  6. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:8198fd4d7ec0c616a6c8b138f3c86284d70b2a5a
    • 部署方式:mo-search-commit-8198fd4d7e-20260908,3 CN、1 DN、3 LogService,通过 Proxy 端口转发连接
    • 测试日期:2026-09-08

    原问题验证

    在目标环境执行原问题的两组场景:

    1. 已有表 id INT AUTO_INCREMENT,当前 session 设置 auto_increment_increment=3、auto_increment_offset=2,批量插入 3 行,返回 ID 2,5,8,该单 session 场景符合预期。

    2. 新建表的 session 设置为 3/2,随后使用三个独立连接:默认 1/1 插入一行、4/3 插入两行、3/2 插入一行。按 ID 排序,3 轮结果均为:

      2     three-two
      10001 default
      20003 four-three-a
      20007 four-three-b
      

      MySQL 兼容语义应为各写入 session 按自身配置生成 1,3,7,11。目标环境仍将表创建时/分配块状态带入后续连接,未按写入 session 的 increment/offset 生成序列。

    Happy Path 覆盖

    1. session 变量可设置并读取为 3/2。
    2. 已有表的单 session 批量插入返回 2,5,8。
    3. 跨连接写入场景连续 3 轮复现上述错误序列。

    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。临时数据库和端口转发已清理。

    测试结论

    测试不通过。

  7. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:4b43f8c99bb22e6a35c389c93bf64c2dc043feaf
    • 部署方式:本地单 CN / TN / LogService,三个独立 MySQL 会话。
    • 测试日期:2026-09-08

    原问题验证

    已有 AUTO_INCREMENT 表在 increment=3、offset=2 的会话中三行 INSERT,3 轮均生成 2,5,8。

    Happy Path 覆盖

    1. 非默认 DDL 会话创建的表,默认 1/1 写入得到 1。
    2. 独立 4/3 会话写入得到 3,7;原 3/2 会话后续写入得到 11。

    Unhappy Path 覆盖

    1. 三会话交替写入后读回 1,3,7,11,无重复或 DDL 会话 offset 泄漏,连接仍可继续使用。

    白盒验证

    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。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions