Skip to content

[Bug]: big data regression: ADD composite primary key and update table on 100 million rows table oom #24658

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

4.0-dev

Commit ID

83cc163

Other Environment Information

Actual Behavior

alter table ... add PRIMARY KEY (col3,col4) on big_data_test.table_basic_for_alter_100M failed with MySQL error 2013:

2026-05-28 08:50:02,695 [INFO] alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col3,col4)
2026-05-28 08:52:18,834 [ERROR] (2013, 'Lost connection to MySQL server during query')
2026-05-28 08:52:18,834 [ERROR] SQL execution failed: alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col3,col4)
Actual Result:
  (2013, 'Lost connection to MySQL server during query')
Expect Result:
  empty set

The following cleanup step also failed because the composite primary key was not created:

alter table big_data_test.table_basic_for_alter_100M drop PRIMARY KEY
Actual Result:
  (1091, "Can't DROP 'PRIMARY'; check that column/key exists")
Expect Result:
  empty set

The same DDL test continued afterward and ended with execute_failed, compare_failed.

Expected Behavior

alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col3,col4) should complete successfully and return an empty result, the same as the single-column primary key case in the same test.

Steps to Reproduce

Run the big-data DDL query case against MatrixOne 4.0-dev commit 83cc1630b37a7a790420edc5aef2f97fb7cf3ba5:

-- single-column PK succeeds first
alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col4);
select count(*) from big_data_test.table_basic_for_alter_100M;
alter table big_data_test.table_basic_for_alter_100M drop PRIMARY KEY;
select count(*) from big_data_test.table_basic_for_alter_100M;

-- composite PK fails with error 2013
alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col3,col4);
select count(*) from big_data_test.table_basic_for_alter_100M;
alter table big_data_test.table_basic_for_alter_100M drop PRIMARY KEY;

Source test case:

tools/mo-regression-test/cases/big_data_test/04_QUERIES/15_write_ddl_100M.sql

Additional information

Before the failing statement, the same job successfully completed:

alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col4)       -- cost: 196257.69ms
alter table big_data_test.table_basic_for_alter_100M drop PRIMARY KEY            -- cost: 298035.12ms

The failing composite primary key statement disconnected after about 136 seconds, which is below the configured 1800s SQL timeout.

Activity

  1. added
    kind/bug
    on May 28, 2026
  2. changed the title [-][Bug]: ADD composite primary key on 100M table loses MySQL connection[/-] [+][Bug]: big data regression: ADD composite primary key on 100 million rows table oom[/+] on May 28, 2026
  3. Ariznawlll commented on May 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional memory / metrics notes from the failed run:

    What we can confirm from Actions logs

    • Failure window for Query 1Y / 07 DDL: around 2026-05-28 08:50:02 ~ 08:52:18 CST.
    • The failing SQL ran for about 136s and then returned MySQL error 2013:
    2026-05-28 08:50:02,695 [INFO] alter table big_data_test.table_basic_for_alter_100M add PRIMARY KEY (col3,col4)
    2026-05-28 08:52:18,834 [ERROR] (2013, 'Lost connection to MySQL server during query')
    
    • I did not find direct OOM / process crash evidence in the GitHub Actions job log. Searched for keywords like OOMKilled, out of memory, signal: killed, panic, and fatal error; none appeared in the DDL job log.
    • The same DDL job continued to execute later statements after this error, so this does not look like a full cluster outage from the client-side log alone.
    • Similar error 2013 appeared in several later jobs in the same run, which suggests this may be related to broader CN/proxy/resource pressure rather than only this one DDL statement:
      • Query 1Y / 08 DML at about 2026-05-28 09:11:27 CST
      • Insert 10Y / 03 PK Index Insert at about 2026-05-28 09:49:00 CST
      • Insert 10Y / 04 Com PK Index Insert at about 2026-05-28 09:54:56 CST
      • Insert 10Y / 07 Write Insert at about 2026-05-28 10:22:46 CST

    Relevant resource / profiling config

    From big-data-tke.yaml in this run:

    • CN / tp:
      • replicas: 3
      • memory limit: 55Gi each
      • GOMEMLIMIT=25000MiB
      • shared storage memory cache: 12Gi
      • GOGC=200
    • DN:
      • replicas: 1
      • memory limit: 55Gi
      • GOMEMLIMIT=35000MiB
      • shared storage memory cache: 5Gi
      • GOGC=200
    • Proxy:
      • replicas: 2
      • memory limit: 6Gi each

    Profiling / metrics were enabled on DN and CN:

    profiles.grafana.com/memory.scrape: "true"
    profiles.grafana.com/memory.port: "6060"
    profiles.grafana.com/malloc.scrape: "true"
    profiles.grafana.com/malloc.port: "6060"
    profiles.grafana.com/malloc.path: "/debug/malloc"
    -profile-interval=30s
    [malloc]
    enable-metrics = true
    

    Suggested metrics to check

    Please check the following time window first:

    • 2026-05-28 08:45:00 ~ 09:00:00 CST for the DDL failure
    • then expand to 2026-05-28 08:40:00 ~ 10:25:00 CST to compare with the later error-2013 jobs

    PromQL examples:

    container_memory_working_set_bytes{
      namespace="mo-big-data-commit-83cc163-20260527",
      pod=~"nightly-regression-dis-.*"
    }
    
    container_memory_working_set_bytes{
      namespace="mo-big-data-commit-83cc163-20260527",
      pod=~"nightly-regression-dis-.*"
    }
    /
    container_spec_memory_limit_bytes{
      namespace="mo-big-data-commit-83cc163-20260527",
      pod=~"nightly-regression-dis-.*"
    }
    
    increase(kube_pod_container_status_restarts_total{
      namespace="mo-big-data-commit-83cc163-20260527",
      pod=~"nightly-regression-dis-.*"
    }[30m])
    
    kube_pod_container_status_last_terminated_reason{
      namespace="mo-big-data-commit-83cc163-20260527",
      pod=~"nightly-regression-dis-.*",
      reason=~"OOMKilled|Error"
    }
    

    Current hypothesis

    There is no direct OOMKilled evidence in Actions logs, but multiple jobs in the same run hit error 2013. If Grafana shows CN/proxy memory close to limit or pod restarts around the listed timestamps, this issue is likely related to resource pressure / process restart / connection reset. If there are no restarts but RSS or malloc metrics spike heavily, it may be a memory pressure path inside CN/DN during heavy DDL/write workloads.

  4. added theissue type on May 28, 2026
  5. added this to the MO-202605 milestone on May 28, 2026
  6. changed the title [-][Bug]: big data regression: ADD composite primary key on 100 million rows table oom[/-] [+][Bug]: big data regression: ADD composite primary key and update table on 100 million rows table oom[/+] on May 28, 2026
  7. Ariznawlll commented on May 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional note for the UPDATE OOM / connection-loss case in the same nightly run:

    Failed job

    The failing statement is the 10M-row update on a cloned 100M-row table with PK/index:

    -- @update_10M_100M
    update big_data_test.table_with_pk_index_for_write_100M_copy
    set col3 = col3 + 1
    where id <= 10000000;

    Log evidence

    The previous 1M-row update finished successfully, then this 10M-row update ran for about 90s and the client got MySQL error 2013:

    2026-05-28 09:09:57,450 update big_data_test.table_with_pk_index_for_write_100M_copy set col3 = col3 + 1 where id <= 10000000
    2026-05-28 09:11:27,064 (2013, 'Lost connection to MySQL server during query')
    

    After the connection loss, the following check query returned a sum lower than expected by 10000000, which is consistent with the 10M-row update not being committed/applied successfully:

    Actual:   1967280323713
    Expected: 1967290323713
    

    Why this is relevant to the DDL OOM issue

    This is not the same SQL path as ALTER TABLE ... ADD PRIMARY KEY or CREATE INDEX, but it is another large write path against a PK/indexed table. It likely exercises heavy update/delete+insert/index maintenance memory usage. From the Actions log alone we still only see client-side Lost connection to MySQL server during query; the log does not directly show OOMKilled or a Go panic. To confirm whether this is really OOM, please correlate CN/proxy/DN pod memory and restart events around 2026-05-28 09:09:57 ~ 09:11:27 CST.

    Suggested focus window:

    2026-05-28 09:05:00 ~ 09:15:00 CST
    

    If pod metrics show CN/proxy memory hitting the limit or container restart/OOMKilled at that time, then the update case should be treated as another reproducible large-write OOM symptom in addition to the DDL failure.

  8. Ariznawlll commented on May 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    Follow-up code-path analysis for the UPDATE failure:

    The failed table is created with both a primary key and indexes:

    create table big_data_test.table_with_pk_index_for_write_100M(
      id bigint primary key,
      ...
      col3 int,
      col4 bigint,
      ...
      key(col3),
      unique key(col4)
    );

    The failed SQL updates col3, which is the secondary-index column:

    update big_data_test.table_with_pk_index_for_write_100M_copy
    set col3 = col3 + 1
    where id <= 10000000;

    So this is not a simple in-place column update. In the planner/executor it becomes a multi-step DML pipeline:

    1. buildTableUpdate() builds a SELECT over the target rows, adds the updated expression, then appends a sink.
    2. buildUpdatePlans() first builds delete-side plans, then builds insert-side plans for the new row image.
    3. Because col3 is indexed, buildDeleteIndexPlans() detects that the secondary key is updated and builds hidden index-table maintenance through buildDeleteRegularIndex().
    4. For update mode, buildDeleteRegularIndex() does both:
      • delete old hidden-index entries
      • insert new hidden-index entries via appendPreInsertPlan() + makeOneInsertPlan()
    5. The main table is also deleted/inserted through MultiUpdate.
    6. For large output, compileMultiUpdate() may use UpdateWriteS3 first, then UpdateFlushS3Info to apply the buffered delete/insert actions.

    Relevant code locations:

    • pkg/sql/plan/build_update.go: buildTableUpdate() / selectUpdateTables()
    • pkg/sql/plan/build_dml_util.go: buildUpdatePlans()
    • pkg/sql/plan/build_dml_util.go: buildDeleteIndexPlans() skips unaffected indexes, but will process this one because col3 is updated
    • pkg/sql/plan/build_dml_util.go: buildDeleteRegularIndex() handles delete + insert for the hidden index table in update mode
    • pkg/sql/compile/compile.go: compileMultiUpdate() chooses UpdateWriteS3 for large results
    • pkg/sql/colexec/multi_update/multi_update.go: update_s3() / updateFlushS3Info() / updateOneBatch() apply the buffered actions

    Current hypothesis:

    The update failure is probably related to the large update + secondary-index maintenance path rather than only the base table update. Updating 10M rows on a table with key(col3) means MO needs to rewrite the affected main rows and maintain the hidden secondary index rows. This has a similar memory-pressure shape to the DDL/index cases because both paths create large derived write streams into hidden/index tables, but the exact entry path is DML MultiUpdate, not DDL CREATE INDEX / ALTER TABLE.

    The Actions log still only proves client-side error 2013. It does not directly show OOMKilled. The key confirmation remains pod/container metrics around 2026-05-28 09:09:57 ~ 09:11:27 CST, especially CN/proxy memory, restarts, and OOMKilled termination reason.

  9. Ariznawlll commented on Jun 4, 2026

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions