Skip to content

[Bug]: CLONE does not preserve AUTO_INCREMENT state #27092

Closed

Description

@Ariznawlll

Environment

  • Branch: main
  • Commit: 1d7b6311ce91df0968da435bb405f3d68137c595
  • Fresh standalone MatrixOne on macOS arm64

Reproducer

DROP DATABASE IF EXISTS clone_ai;
CREATE DATABASE clone_ai;
CREATE TABLE clone_ai.src (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  v INT
);
INSERT INTO clone_ai.src(v) VALUES (10), (20), (30);

-- Table clone variant
CREATE TABLE clone_ai.dst CLONE clone_ai.src;
INSERT INTO clone_ai.dst(v) VALUES (40);

SELECT
  (SELECT AUTO_INCREMENT FROM information_schema.tables
    WHERE table_schema = 'clone_ai' AND table_name = 'src') AS source_next,
  (SELECT AUTO_INCREMENT FROM information_schema.tables
    WHERE table_schema = 'clone_ai' AND table_name = 'dst') AS clone_next,
  (SELECT MAX(id) FROM clone_ai.dst) AS clone_inserted_id;

Actual result

The table-clone reproduction was run with three independent databases. Every run produced:

source_next | clone_next | clone_inserted_id
4           | 10002      | 10001

The same result occurs through CREATE DATABASE clone_ai_dst CLONE clone_ai_src: each of three independent runs retained IDs 1,2,3, but the destination's first inserted row received ID 10001.

A non-clone control with the same table and initial three inserts assigns ID 4 to the next row.

Expected result

The clone should preserve the source table's auto-increment continuation state. With source metadata reporting AUTO_INCREMENT = 4, the first subsequent insert in the cloned table should receive ID 4, as it does in the non-clone control.

Impact

Every cloned auto-increment table deterministically creates a 9,997-value gap for the first post-clone insert. This changes application-visible identifiers and breaks workflows that expect clone data plus its subsequent write behavior to match the source state.

Activity

  1. added
    kind/bug
    on Aug 13, 2026
  2. Ariznawlll commented on Aug 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional confirmation: the defect is independent of copied data volume.

    For three independent empty-source table clones:

    source_next | clone_next | clone_inserted_id
    1           | 10002      | 10001
    

    Each source table was only id BIGINT AUTO_INCREMENT PRIMARY KEY, with no inserted rows before CREATE TABLE dst CLONE src. This rules out a collision-avoidance explanation based on copied IDs: cloning even an empty table skips the initial 10,000-value allocation range.

  3. Ariznawlll commented on Aug 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    The same state loss affects table-level Data Branch creation.

    For three independent runs:

    CREATE TABLE src(id BIGINT AUTO_INCREMENT PRIMARY KEY, v INT);
    INSERT INTO src(v) VALUES (1), (2), (3);
    DATA BRANCH CREATE TABLE dst FROM src;
    INSERT INTO dst(v) VALUES (4);

    Every run produced:

    source_next | branch_next | branch_inserted_id
    4           | 10002       | 10001
    

    Thus the defect is shared by ordinary table CLONE, database CLONE, and DATA BRANCH CREATE TABLE; a fix should cover the common clone path rather than only the SQL spelling.

  4. added theissue type on Aug 13, 2026
  5. added this to the MO-202608 milestone on Aug 13, 2026
  6. added
    severity/s0
    ai-easy
    and removed on Aug 14, 2026
  7. gouhongshen commented on Aug 17, 2026

    @gouhongshen
    Contributor

    PR #27154 is trying to fix this issue.

  8. gouhongshen commented on Aug 30, 2026

    @gouhongshen
    Contributor

    PR #27154 has merged and is awaiting manual validation. The issue remains open.

  9. added and removed
    severity/s0
    on Aug 30, 2026
  10. slyunnn commented on Aug 31, 2026

    @slyunnn

    Regression and extended verification for #27092 (2026-08-31)

    Verification Environment

    • MatrixOne source: local latest origin/main at 89740fae15dbba2cbe104348659694283cb160a6 — fix(plan): support MySQL JSON defaults and coalesce (#27874).
    • Related fix: PR #27154, merged as c692afc2799f473c297f38f431810a254fd95981 — fix: preserve clone auto-increment continuation.
    • Topology: one Log service, one TN service, two CN services, and one Proxy, launched from etc/launch-with-proxy/launch.toml with a fresh, test-owned data directory in an isolated local Docker environment.
    • Endpoints: Proxy 127.0.0.1:27092, CN-1 127.0.0.1:27093, and CN-2 127.0.0.1:27094.
    • Client/protocol: MySQL CLI over direct MySQL wire-protocol TCP for the original witness; mo-tester with MySQL Connector/J over the MySQL wire protocol through Proxy for BVT replay.

    What Was Covered

    • OK Original table-clone witness: the exact three-row fixture was run 3 times at each of Proxy, CN-1, and CN-2. Every run returned source_next=4, clone_next=5, and clone_inserted_id=4, rather than the faulty 10001 allocation.
    • OK Happy path: clone_auto_increment_state.sql passed 65/65; table clone preserves copied rows and the next visible AUTO_INCREMENT value.
    • OK Alternate clone entry points: database clone, DATA BRANCH CREATE TABLE, and DATA BRANCH CREATE DATABASE all returned the expected continuation state in the dedicated BVT.
    • OK Boundary scenarios: empty source starts at 1; a source with deleted maximum ID seeds the clone from copied rows; explicit ALTER TABLE ... AUTO_INCREMENT = 100 remains a schema lower bound; transaction and snapshot clone paths passed.
    • OK Compatibility: standard table clone passed 74/74; permanent-to-temporary destination clone passed 163/163, including the revised contiguous AUTO_INCREMENT expectation.
    • OK Unhappy-path ownership controls: focused CGo tests passed for fresh-clone allocator reconstruction, ALTER COPY allocator handoff, hidden index allocators, schema rename/reorder mapping, cancellation, and result-error cleanup.
    • Not covered A concurrent source write racing with clone creation was not separately exercised; the reported deterministic defect concerns fresh-clone allocator initialization, and the fix deliberately does not transfer source CN allocator caches.

    Findings

    Fresh clones previously copied the source allocator's reserved batch upper bound from mo_catalog.mo_increment_columns. That value was 10000 in the minimal reproduction, although the visible next ID was 4; the fresh destination consequently started at 10001. PR #27154 reconstructs fresh visible allocator state from copied-row maxima and schema lower bounds, while retaining raw allocator transfer where the column-ID ownership model requires it, such as ALTER COPY and hidden internal columns.

    MOTR / BVT Coverage

    No new MOTR case was added because the merged fix already introduced the dedicated public BVT test/distributed/cases/git4data/clone/clone_auto_increment_state.sql. This verification replayed it (65/65) together with table_clone.sql (74/74) and temporary_table_clone.sql (163/163), without modifying MatrixOne service source or MOTR files.

    Final Conclusion

    Fixed. Large-data regression is not required: the defect is independent of copied row count and is caused by allocator-state ownership during clone initialization. The deterministic empty/three-row/deleted-maximum/schema-floor fixtures exercise the relevant continuation boundaries; increasing rows would not cover another affected execution state and would add unrelated CI cost.

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions