Skip to content

[Performance] 长事务逐条 UPDATE 延迟随事务规模增长的 Benchmark #26796

Closed

Description

@gouhongshen

Benchmark 目标

记录 MatrixOne 在同一长事务内连续执行主键等值单行 UPDATE 时,单条延迟随事务内累计修改规模变化的 Benchmark 表现。

本 Issue 只收集可复现的测试条件、原始测量结果和资源观测,不记录根因判断、规避方式或优化方案。

已记录场景

  • 单一长事务、带业务唯一索引的逐条主键 UPDATE 延迟曲线。
  • 相同 SQL 每 5,000 条提交一次的对照。
  • 去除业务唯一索引后的对照。
  • 每批 5,000 行集合 UPDATE 的对照。
  • 长事务不同阶段的 CPU 与 heap profile。
  • 541,241 行生产回填任务的运行观测。

完整测试环境、SQL、数据和 profile 指标见下方 Benchmark 评论。

Activity

  1. added
    ai-heavy
    on Aug 8, 2026
  2. self-assigned this
    on Aug 8, 2026
  3. gouhongshen commented on Aug 8, 2026

    @gouhongshen
    ContributorAuthor

    MatrixOne 长事务逐条 UPDATE Benchmark

    1. 测试环境

    • MatrixOne commit:3639aac46b77fdc28eda80e1698d574b7743f928
    • 部署:单节点 MatrixOne
    • 对象存储:独立本地 MinIO
    • 负载:测试期间无其他业务负载
    • 源码:未修改 MatrixOne 源码
    • 测试数据:预先写入并在独立事务中提交
    • 执行方式:同一连接、同一张静态表、预编译 SQL

    测试表 200,000 行:

    CREATE TABLE volume_files (
      id BIGINT PRIMARY KEY,
      volume_id BIGINT NOT NULL,
      file_id BIGINT NOT NULL,
      sandbox_path VARCHAR(1024),
      path VARCHAR(1024) NOT NULL,
      UNIQUE KEY uk_volume_file (volume_id, file_id),
      UNIQUE KEY uk_volume_sandbox_path (volume_id, sandbox_path)
    );

    逐条更新语句:

    UPDATE volume_files SET sandbox_path = ? WHERE id = ?

    2. Benchmark A:单一长事务,保留两个业务唯一索引

    全部 UPDATE 在一个事务中执行,每 1,000 条统计一个窗口。

    已完成更新数 当前 1,000 条窗口平均延迟
    1,000 0.215 ms/条
    24,000 2.420 ms/条
    34,000 3.354 ms/条
    50,000 4.852 ms/条
    66,000 6.417 ms/条
    80,000 7.703 ms/条
    90,000 8.720 ms/条
    93,000 9.016 ms/条

    93,000 条附近的窗口延迟是最初窗口的约 42 倍。

    前 50,000 条汇总:

    • 总耗时:127.653s
    • 平均延迟:2.553 ms/条

    3. Benchmark B:相同逐条 UPDATE,每 5,000 条提交

    使用全新 200,000 行数据集;SQL、表结构和预编译方式与 Benchmark A 相同,仅改变事务边界。

    5,000 条 chunk 单条平均延迟
    1 0.421 ms
    2 0.405 ms
    3 0.399 ms
    4 0.400 ms
    5 0.405 ms
    6-10 0.399-0.420 ms

    前 50,000 条汇总:

    • 总耗时:20.381s
    • 平均延迟:0.408 ms/条
    • Benchmark A / Benchmark B 总耗时比:约 6.3

    4. Benchmark C:单一长事务,仅保留主键索引

    删除 uk_volume_file 和 uk_volume_sandbox_path,保留 id 主键;其他条件与 Benchmark A 相同。

    已完成更新数 当前窗口平均延迟
    1,000 0.105 ms/条
    10,000 0.367 ms/条
    20,000 0.631 ms/条
    30,000 0.906 ms/条
    34,000 1.004 ms/条
    39,000 1.149 ms/条

    34,000 条附近:

    • 带两个业务唯一索引:3.354 ms/条
    • 仅保留主键:1.004 ms/条
    • 延迟比:约 3.3

    5. Benchmark D:每批 5,000 行集合 UPDATE

    使用全新 200,000 行数据集,每批通过一个 CASE id ... WHERE id IN (...) 语句更新 5,000 行,共更新 50,000 行。

    • 总耗时:5.177s
    • 平均延迟:0.104 ms/行
    • Benchmark A / Benchmark D 总耗时比:约 24.7

    6. Profile 观测

    在 Benchmark A 约 66,000 条附近采集 CPU profile:

    调用点 cumulative samples
    table_scan.(*TableScan).Call 约 9.3%
    LocalDisttaeDataSource.Next -> filterInMemUnCommittedInserts -> iterateInMemData 约 8.7%
    GC gcDrain 约 27.8%

    MemPKFilter.FilterVector 和 readutil.EncodePrimaryKeyVector 同时出现在 CPU 热点中。

    从 66,000 条到 90,000 条的 heap diff 增长 95.76MB:

    调用点 live heap 增量
    lockservice.(*holders).add +34.03MB
    lockservice.newWaiterQueue +5.00MB
    lockservice B-tree insert +4.02MB
    readutil.EncodePrimaryKeyVector +3.26MB
    Transaction.IncrStatementID +1.01MB

    该次 mutex profile 未观察到明显的业务锁等待热点。

    7. 生产运行观测

    一次 541,241 行的 volume_files.sandbox_path 回填任务,在同一事务内逐条执行同类主键 UPDATE:

    • 运行时限:30 分钟
    • 已完成:12,264 条
    • 平均耗时:约 146.8 ms/条
    • 累计读取:约 12.52B 行 / 751GB
    • 折算:约 1.02M 行、61MB/更新
    • 事务在超时后回滚

    8. 测量边界

    • 上述本地数据来自固定 commit、固定表结构和独立测试负载。
    • 不同 Benchmark 使用全新数据集,避免前一组事务状态影响后一组。
    • 本评论只记录测量结果;源码归因、修复设计和实施优先级不在本 Issue 范围内。
  4. changed the title [-][Performance] Disttae 长事务逐条 UPDATE 随 workspace 增长持续恶化[/-] [+][Performance] 长事务逐条 UPDATE 延迟随事务规模增长的 Benchmark[/+] on Aug 9, 2026
  5. gouhongshen commented on Aug 9, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark:ORM Unit of Work(latest main,fresh instance)

    MO 版本

    • Source commit: a4b0ce286d182c24efd5a349620ae37016262301
    • Commit time: 2026-08-09T11:20:09+08:00
    • Commit title: fix(plan): use hash anti join for filtered NOT EXISTS (#26798)
    • Runtime SELECT VERSION(): 8.0.30-MatrixOne-v1.3.0
    • Build Go: go version go1.26.4 darwin/arm64
    • Host: macOS-26.5.2-arm64-arm-64bit

    隔离与执行协议

    • 本场景使用独立启动的全新 MO 进程和全新数据目录;未复用其他 Benchmark 的进程、Catalog 或事务状态。
    • 单客户端、单连接、单个长事务。
    • Setup 阶段预先插入 30,000 行;Setup 不计入测量。
    • 测量阶段按不同主键顺序执行 30,000 次 UPDATE,事务结束后统一 COMMIT。
    • 每 1,000 次操作为一个统计窗口。
    • 表包含主键和两个唯一二级索引:
    CREATE TABLE customer_profile (
        id BIGINT PRIMARY KEY,
        email VARCHAR(120) NOT NULL UNIQUE,
        external_id VARCHAR(80) NOT NULL UNIQUE,
        level INT NOT NULL,
        updated_at BIGINT NOT NULL
    );

    测量 SQL:

    UPDATE customer_profile
    SET level = level + 1, updated_at = ?
    WHERE id = ?;

    测量结果

    已完成 UPDATE avg (ms) p50 (ms) p95 (ms) p99 (ms) max (ms)
    1,000 0.204 0.185 0.266 0.602 3.355
    3,000 0.262 0.240 0.340 0.721 1.330
    5,000 0.328 0.309 0.416 0.791 1.776
    10,000 0.493 0.467 0.591 1.253 2.551
    15,000 0.625 0.595 0.730 0.856 9.058
    20,000 0.776 0.732 0.926 1.645 9.480
    25,000 0.925 0.866 1.074 1.909 12.851
    28,000 1.013 0.952 1.180 2.458 10.334
    29,000 1.130 1.023 1.402 2.509 14.627
    30,000 1.082 1.013 1.215 1.662 14.331
    • 前 3 个窗口 avg 中位数:0.212766 ms
    • 后 3 个窗口 avg 中位数:1.081877 ms
    • 后段 / 前段:5.0848x
    • 30,000 次 UPDATE 的事务执行时间:19,464.535 ms
    • COMMIT:54.242 ms

    该实际 ORM Unit of Work 形态在最新 main 的干净实例中稳定复现了随事务规模增长的单条 UPDATE 延迟恶化。

  6. gouhongshen commented on Aug 9, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark:订单库存扣减 + Order Item + Transactional Outbox(latest main,fresh instance)

    MO 版本

    • Source commit: a4b0ce286d182c24efd5a349620ae37016262301
    • Commit time: 2026-08-09T11:20:09+08:00
    • Commit title: fix(plan): use hash anti join for filtered NOT EXISTS (#26798)
    • Runtime SELECT VERSION(): 8.0.30-MatrixOne-v1.3.0
    • Build Go: go version go1.26.4 darwin/arm64
    • Host: macOS-26.5.2-arm64-arm-64bit

    隔离与执行协议

    • 独立启动的全新 MO 进程和全新数据目录;未复用其他 Benchmark 状态。
    • 单客户端、单连接、单个长事务。
    • Setup 预先插入 15,000 条库存记录,不计入测量。
    • 每个被测业务操作依次执行 1 次库存 UPDATE、1 次订单明细 INSERT、1 次 Outbox INSERT;15,000 个业务操作结束后统一 COMMIT。
    • 每 1,000 个业务操作为一个统计窗口;窗口延迟包含该业务操作的 3 条 DML。

    表结构要点:库存表包含主键和 (warehouse_id, sku_id) 唯一索引;订单明细包含主键和 (order_id, sku_id) 唯一索引;Outbox 包含主键和 event_id 唯一索引。

    每个业务操作的 SQL 形态:

    UPDATE inventory_item
    SET available = available - 1
    WHERE sku_id = ?;
    
    INSERT INTO order_item
    VALUES (?, ?, ?, 1);
    
    INSERT INTO transactional_outbox
    VALUES (?, ?, ?, ?);

    测量结果

    已完成业务操作 avg (ms) p50 (ms) p95 (ms) p99 (ms) max (ms)
    1,000 0.753 0.709 0.915 1.459 17.795
    3,000 1.143 1.076 1.418 1.650 6.761
    5,000 1.445 1.391 1.621 3.578 6.723
    8,000 2.072 1.938 2.420 5.252 15.091
    10,000 2.349 2.245 2.582 5.856 8.439
    12,000 2.761 2.598 3.119 5.946 15.540
    13,000 2.899 2.760 3.136 7.492 17.400
    14,000 3.076 2.936 3.283 8.148 15.548
    15,000 3.252 3.092 3.580 7.625 15.589
    • 前 3 个窗口 avg 中位数:0.928824 ms
    • 后 3 个窗口 avg 中位数:3.076118 ms
    • 后段 / 前段:3.3118x
    • 15,000 个业务操作的事务执行时间:30,478.996 ms
    • COMMIT:125.189 ms

    该订单写入与 Transactional Outbox 组合在最新 main 的干净实例中复现了随事务规模增长的业务操作延迟恶化。

  7. gouhongshen commented on Aug 9, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark:账户余额更新 + 不可重复 Ledger Entry(latest main,fresh instance)

    MO 版本

    • Source commit: a4b0ce286d182c24efd5a349620ae37016262301
    • Commit time: 2026-08-09T11:20:09+08:00
    • Commit title: fix(plan): use hash anti join for filtered NOT EXISTS (#26798)
    • Runtime SELECT VERSION(): 8.0.30-MatrixOne-v1.3.0
    • Build Go: go version go1.26.4 darwin/arm64
    • Host: macOS-26.5.2-arm64-arm-64bit

    隔离与执行协议

    • 独立启动的全新 MO 进程和全新数据目录;未复用其他 Benchmark 状态。
    • 单客户端、单连接、单个长事务。
    • Setup 预先插入 20,000 个账户余额,不计入测量。
    • 每笔记账依次执行账户余额 UPDATE 和 Ledger Entry INSERT;20,000 笔记账结束后统一 COMMIT。
    • Ledger Entry 包含主键及唯一 transaction_id,模拟幂等记账约束。
    • 每 1,000 笔记账为一个统计窗口;窗口延迟包含该笔记账的 2 条 DML。
    CREATE TABLE account_balance (
        account_id BIGINT PRIMARY KEY,
        balance DECIMAL(18,2) NOT NULL
    );
    
    CREATE TABLE ledger_entry (
        id BIGINT PRIMARY KEY,
        transaction_id VARCHAR(80) NOT NULL UNIQUE,
        account_id BIGINT NOT NULL,
        amount DECIMAL(18,2) NOT NULL
    );

    每笔记账的 SQL 形态:

    UPDATE account_balance
    SET balance = balance + 1
    WHERE account_id = ?;
    
    INSERT INTO ledger_entry
    VALUES (?, ?, ?, 1);

    测量结果

    已完成记账 avg (ms) p50 (ms) p95 (ms) p99 (ms) max (ms)
    1,000 0.452 0.431 0.552 0.668 7.874
    3,000 0.696 0.660 0.892 1.033 5.478
    5,000 0.862 0.830 1.004 2.192 3.618
    8,000 1.216 1.153 1.452 3.212 4.316
    10,000 1.383 1.319 1.553 3.497 5.306
    12,000 1.620 1.532 1.858 3.729 11.035
    15,000 1.930 1.834 2.144 4.628 12.288
    18,000 2.229 2.120 2.379 5.027 13.521
    19,000 2.320 2.201 2.542 5.629 14.405
    20,000 2.441 2.307 2.729 5.706 15.042
    • 前 3 个窗口 avg 中位数:0.557536 ms
    • 后 3 个窗口 avg 中位数:2.320058 ms
    • 后段 / 前段:4.1613x
    • 20,000 笔记账的事务执行时间:29,353.876 ms
    • COMMIT:93.728 ms

    该账户余额更新与不可重复 Ledger Entry 组合在最新 main 的干净实例中复现了随事务规模增长的业务操作延迟恶化。

  8. gouhongshen commented on Aug 9, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark:库存更新期间周期性读取事务内结果(latest main,fresh instance)

    MO 版本

    • Source commit: a4b0ce286d182c24efd5a349620ae37016262301
    • Commit time: 2026-08-09T11:20:09+08:00
    • Commit title: fix(plan): use hash anti join for filtered NOT EXISTS (#26798)
    • Runtime SELECT VERSION(): 8.0.30-MatrixOne-v1.3.0
    • Build Go: go version go1.26.4 darwin/arm64
    • Host: macOS-26.5.2-arm64-arm-64bit

    隔离与执行协议

    • 独立启动的全新 MO 进程和全新数据目录;未复用其他 Benchmark 状态。
    • 单客户端、单连接、单个长事务。
    • Setup 预先插入 30,000 行库存,不计入测量。
    • 测量阶段按不同主键执行 30,000 次库存 UPDATE,事务结束后统一 COMMIT。
    • 每执行 100 次 UPDATE,在同一事务中读取一个 warehouse_id 的库存合计,覆盖应用在大事务内交替写入和读取自身变更的常见形态。
    • 每 1,000 次 UPDATE 为一个统计窗口;窗口延迟同时包含其中 10 次周期性读取。
    CREATE TABLE warehouse_stock (
        id BIGINT PRIMARY KEY,
        warehouse_id INT NOT NULL,
        available INT NOT NULL,
        UNIQUE KEY uk_warehouse_item (warehouse_id, id)
    );

    写入 SQL:

    UPDATE warehouse_stock
    SET available = available - 1
    WHERE id = ?;

    周期性读取 SQL:

    SELECT SUM(available)
    FROM warehouse_stock
    WHERE warehouse_id = ?;

    UPDATE + 周期性读取的窗口结果

    已完成 UPDATE avg (ms) p50 (ms) p95 (ms) p99 (ms) max (ms)
    1,000 0.344 0.181 0.296 1.655 23.926
    3,000 0.765 0.257 0.387 1.498 55.092
    5,000 1.046 0.313 0.408 4.074 77.054
    10,000 1.630 0.429 0.563 8.901 126.828
    15,000 2.364 0.580 0.756 13.098 179.462
    20,000 3.120 0.711 0.977 6.011 248.773
    25,000 3.616 0.854 1.145 6.374 276.063
    28,000 4.014 0.944 1.221 13.338 304.064
    29,000 4.108 0.959 1.262 15.548 311.947
    30,000 4.176 0.998 1.271 13.030 321.861
    • 前 3 个窗口 avg 中位数:0.546593 ms
    • 后 3 个窗口 avg 中位数:4.107932 ms
    • 后段 / 前段:7.5155x
    • 30,000 次 UPDATE 和 300 次周期性读取的事务执行时间:72,503.765 ms
    • COMMIT:50.965 ms

    周期性读取自身写入结果的延迟

    已完成 UPDATE 本次 SELECT 延迟 (ms)
    100 5.239
    1,000 23.744
    3,000 54.837
    5,000 76.735
    10,000 126.240
    15,000 178.898
    20,000 239.450
    25,000 275.216
    28,000 302.602
    29,000 307.711
    30,000 318.934

    从第 100 次 UPDATE 到第 30,000 次 UPDATE,事务内同形态 SELECT 的单次延迟由 5.239 ms 增至 318.934 ms,约为 60.88x。与此同时,不含周期性读取尖峰主体的 UPDATE p50 也由首窗口的 0.181 ms 增至末窗口的 0.998 ms。

    该写后读场景在最新 main 的干净实例中同时复现了事务规模增长时的写入延迟恶化,以及读取同一事务内累计写入结果的延迟持续增长。

  9. gouhongshen commented on Aug 9, 2026

    @gouhongshen
    ContributorAuthor

    Cross-database Benchmark:六种长事务业务形态(fresh instance)

    1. 测试目标

    在 MatrixOne、MySQL 和 PostgreSQL 上执行相同业务形态,记录同一长事务内操作延迟随累计操作数变化的表现。本评论仅记录测试条件和测量结果。

    2. 版本与环境

    数据库 版本 镜像 / Commit 默认事务隔离级别
    MatrixOne 8.0.30-MatrixOne-v1.3.0 a4b0ce286d182c24efd5a349620ae37016262301 MatrixOne Benchmark 原始配置
    MySQL 8.4.11 官方 mysql:8.4,image ID sha256:5e7e005a680e75d935984d3d9390990d2a709b3ed67e92708e9e6747f1f754c9 REPEATABLE-READ
    PostgreSQL 18.4 (Debian 18.4-1.pgdg13+1) 官方 postgres:18,image ID sha256:c14be09d80346e5d7716a191b61a60347be1783e177e52da118bcd40bf426f14 read committed
    • 主机:macOS arm64,Darwin 25.5.0。
    • 每个数据库、每个场景均使用全新进程或全新容器、全新数据目录,不复用前一个场景的事务或数据库状态。
    • 单客户端、单连接、单个长事务;Setup 预装数据不计入测量;全部操作完成后统一 COMMIT。
    • 每 1,000 个业务操作统计一个窗口。
    • 退化判据:最后三个窗口平均延迟的中位数 / 最初三个窗口平均延迟的中位数 >= 3x,并且最后三个窗口均不低于初始中位数的 2x。
    • SQL 按各数据库等价语法执行;Upsert 分别使用 MatrixOne/MySQL 的 ON DUPLICATE KEY UPDATE 与 PostgreSQL 的 ON CONFLICT DO UPDATE。

    3. 首尾窗口结果

    单元格格式:初始中位数 → 末尾中位数(末/初),单位为 ms/业务操作。

    场景 操作数 MatrixOne MySQL PostgreSQL
    ORM Unit of Work 30,000 0.212766 → 1.081877(5.0848x) 0.215975 → 0.211606(0.9798x) 0.206706 → 0.197006(0.9531x)
    Order + Inventory + Outbox 15,000 0.928824 → 3.076118(3.3118x) 0.640298 → 0.643266(1.0046x) 0.599778 → 0.599120(0.9989x)
    Ledger Posting 20,000 0.557536 → 2.320058(4.1613x) 0.425864 → 0.427086(1.0029x) 0.397566 → 0.397220(0.9991x)
    Bulk Upsert 30,000 4.962048 → 4.676397(0.9424x) 0.218998 → 0.219692(1.0032x) 0.206528 → 0.200753(0.9720x)
    Cascade-style Delete + Parent Update 20,000 33.453501 → 1.135100(0.0339x) 0.433860 → 0.432316(0.9964x) 0.399384 → 0.388030(0.9716x)
    Write After Read 30,000 0.546593 → 4.107932(7.5155x) 0.219527 → 0.223306(1.0172x) 0.210697 → 0.200035(0.9494x)

    按上述统一判据:MatrixOne 的 ORM Unit of Work、Order + Outbox、Ledger Posting、Write After Read 四个场景触发;MySQL 和 PostgreSQL 的六个场景均未触发。

    4. 单事务总耗时与 COMMIT

    场景 MatrixOne txn / commit MySQL txn / commit PostgreSQL txn / commit
    ORM Unit of Work 19.465s / 54.242ms 6.432s / 7.146ms 6.097s / 0.521ms
    Order + Inventory + Outbox 30.479s / 125.189ms 9.618s / 6.867ms 9.030s / 0.419ms
    Ledger Posting 29.354s / 93.728ms 8.588s / 5.824ms 8.054s / 0.468ms
    Bulk Upsert 289.070s / 131.372ms 6.628s / 5.742ms 6.037s / 0.479ms
    Cascade-style Delete + Parent Update 172.976s / 105.567ms 8.558s / 6.559ms 7.944s / 0.663ms
    Write After Read 72.504s / 50.965ms 6.583s / 4.703ms 6.268s / 0.433ms

    5. Write After Read 的事务内读取

    每完成 100 次不同主键 UPDATE,执行一次同事务内聚合读取。下表比较最初三个和最后三个读取样本的中位数。

    数据库 初始读取 末尾读取 末/初
    MatrixOne 6.8917ms 318.9342ms 46.278x
    MySQL 0.3943ms 0.3946ms 1.001x
    PostgreSQL 0.3763ms 0.8539ms 2.269x

    6. 测量边界

    • 三个数据库使用不同客户端协议、驱动和默认隔离级别,因此绝对延迟不能视为严格的引擎吞吐排名;每个数据库内部的首尾窗口变化是本次主要观测值。
    • 该轮跨数据库对比最大为 30,000 个业务操作,未包含 500,000 次逐行 UPDATE;50 万规模将作为独立 Benchmark 记录。
  10. gouhongshen commented on Aug 9, 2026

    @gouhongshen
    ContributorAuthor

    Cross-database Benchmark:50 万行逐条 UPDATE(30 分钟预算)

    1. 测试目标

    在 MatrixOne、MySQL 和 PostgreSQL 的全新实例中预装 500,000 行数据,然后在一个连接、一个长事务内顺序执行 500,000 次单行 UPDATE:

    UPDATE volume_files SET sandbox_path = ? WHERE id = ?;

    全部 UPDATE 完成后统一 COMMIT。本轮为复现实际升级执行边界,单库预算为 30 分钟;未在预算内完成的数据库终止事务并回滚。

    2. 版本与环境

    数据库 版本 镜像 / Commit 默认事务隔离级别
    MatrixOne 8.0.30-MatrixOne-v1.3.0 a4b0ce286d182c24efd5a349620ae37016262301 MatrixOne Benchmark 原始配置
    MySQL 8.4.11 官方 mysql:8.4,image ID sha256:5e7e005a680e75d935984d3d9390990d2a709b3ed67e92708e9e6747f1f754c9 REPEATABLE-READ
    PostgreSQL 18.4 (Debian 18.4-1.pgdg13+1) 官方 postgres:18,image ID sha256:c14be09d80346e5d7716a191b61a60347be1783e177e52da118bcd40bf426f14 read committed
    • 主机:macOS arm64,Darwin 25.5.0。
    • 每个数据库使用全新进程或全新容器、全新数据目录。
    • Setup 阶段预装 500,000 行,不计入 UPDATE 测量。
    • 单客户端、单连接、单个长事务,逐条发送 UPDATE。
    • MySQL 为满足 InnoDB 3,072-byte 索引键上限,仅将 sandbox_path 定义为 VARCHAR(1024) CHARACTER SET ascii;本 Benchmark 写入的路径均为 ASCII。其余逻辑列、主键、唯一约束、SQL 和操作次序一致。

    逻辑表结构:

    CREATE TABLE volume_files (
        id BIGINT PRIMARY KEY,
        volume_id BIGINT NOT NULL,
        file_id BIGINT NOT NULL,
        sandbox_path VARCHAR(1024),
        path VARCHAR(1024) NOT NULL,
        UNIQUE (volume_id, file_id),
        UNIQUE (volume_id, sandbox_path)
    );

    3. 完成情况

    数据库 30 分钟内完成 UPDATE 完成比例 长事务耗时 COMMIT 结果
    MatrixOne 170,000 / 500,000 34% > 30min 未执行 未在预算内完成,事务回滚
    MySQL 500,000 / 500,000 100% 114.191s 117.693ms 完成
    PostgreSQL 500,000 / 500,000 100% 105.755s 0.822ms 完成

    MatrixOne 在 30m28s 观测时最后一个完整进度点为 170,000。终止信号后的清理过程未立即结束,最终日志在 31m47s 前又记录到 180,000;上表严格按 30 分钟预算采用 170,000。

    4. MySQL / PostgreSQL 窗口延迟

    每 1,000 次 UPDATE 统计一个窗口。下表为指定累计操作数对应窗口的平均延迟,单位 ms/UPDATE。

    累计 UPDATE MySQL PostgreSQL
    1,000 0.247009 0.218064
    10,000 0.233111 0.210944
    50,000 0.211455 0.211015
    100,000 0.216701 0.208983
    200,000 0.232288 0.201863
    300,000 0.226577 0.220355
    400,000 0.217946 0.214500
    500,000 0.228326 0.206204

    首三个窗口与末三个窗口平均延迟的中位数:

    数据库 初始 末尾 末/初
    MySQL 0.243268ms 0.228528ms 0.9394x
    PostgreSQL 0.209097ms 0.206204ms 0.9862x

    5. 测量边界

    • 三个数据库使用不同协议、驱动和默认隔离级别,绝对延迟不能视为严格的引擎吞吐排名。
    • MatrixOne 未完成全部 500,000 次 UPDATE,因此没有末尾窗口和 COMMIT 数据;其结果只表示 30 分钟预算内已完成的进度。
    • MatrixOne 终止后事务已回滚,测试实例已关闭。
  11. gouhongshen commented on Aug 14, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark progress: transaction workspace PR exact 500,000-row UPDATE

    Tested build

    UPDATE volume_files SET sandbox_path = ? WHERE id = ?;

    Completion time

    Run UPDATE phase COMMIT Total / result
    rollback run 1 107.719s — rollback
    rollback run 2 107.555s — rollback
    commit run 106.911s 1.857s 108.768s

    References recorded in this Issue for the same 500,000-row workload:

    Build / database Result
    MatrixOne main baseline 170,000 updates in 30 minutes; did not finish
    Earlier PR measurement about 116.3s
    Earlier current-PR baseline about 120.47s
    MySQL 8.4.11 114.191s
    PostgreSQL 18.4 105.755s

    Latency distribution

    All 500,000 UPDATEs:

    • mean: 215.437us
    • p50: 200.588us
    • p95: 271.100us
    • p99: 284.804us
    • maximum observed 1,000-operation window mean: 439.365us

    Per 50,000-operation window means:

    Completed UPDATEs Mean per UPDATE
    50,000 206.9us
    100,000 211.9us
    150,000 213.3us
    200,000 213.8us
    250,000 216.1us
    300,000 215.0us
    350,000 212.6us
    400,000 216.9us
    450,000 219.3us
    500,000 228.6us

    No monotonic latency growth with accumulated transaction size was observed in these runs.

    Post-commit data validation

    • row count: 500,000
    • distinct sandbox_path: 500,000
    • minimum value: /sandbox/profile/000000001
    • maximum value: /sandbox/profile/000500000
    • rows 1, 250000, and 500000 matched their expected paths

    This comment records only the benchmark result and validation output.

  12. gouhongshen commented on Aug 14, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark progress: transaction workspace PR ORM Unit of Work

    Tested build and protocol

    • PR: refactor(disttae): redesign CN transaction workspace #27013
    • Commit: ae69b2b3c3
    • Each sample used a fresh single-node MatrixOne process and data directory.
    • 30,000 rows were preloaded outside measurement.
    • One client, one connection, and one long transaction executed 30,000 prepared parameterized UPDATEs against different primary keys, followed by one COMMIT.
    • The table contained a primary key and unique indexes on email and external_id.
    UPDATE customer_profile
    SET level = level + 1, updated_at = ?
    WHERE id = ?;

    Results

    Build / database Transaction phase First-to-last window behavior
    MatrixOne main at a4b0ce286d 19.465s 0.212766ms -> 1.081877ms (5.0848x)
    This PR, fresh sample median 3.773s average ratio at most 1.20x; p50 ratio 0.98-1.09x
    MySQL 8.4.11 6.432s 0.9798x
    PostgreSQL 18.4 6.097s 0.9531x

    Three fresh PR samples:

    Sample UPDATE phase COMMIT first-three / last-three avg ratio first-three / last-three p50 ratio
    1 2.783s 71.444ms 1.195x 1.001x
    2 3.773s 80.375ms 1.112x 0.983x
    3 6.644s 99.760ms 1.195x 1.086x

    The three fresh samples did not show monotonic latency growth with accumulated transaction size. Average-window variation was caused by isolated 30-70ms outliers at unrelated transaction positions; p50 remained flat or near-flat.

    This comment records only the benchmark protocol and measured results.

  13. gouhongshen commented on Aug 14, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark update: Inventory + Order Item + Transactional Outbox

    Protocol

    • Fresh MatrixOne instance and fresh data for each sample.
    • Preload 15,000 inventory rows.
    • Execute 15,000 business operations in one transaction.
    • Each operation performs:
      1. UPDATE inventory_item SET available = available - 1 WHERE sku_id = ?
      2. one order_item INSERT
      3. one transactional_outbox INSERT
    • Measure each business operation and summarize every 1,000 operations.
    • Measure COMMIT separately.
    • Validate 15,000 inventory updates, 15,000 distinct orders, and 15,000 distinct outbox events after COMMIT.

    Results

    Build / database Transaction phase COMMIT Last 3 / first 3 window p50
    MatrixOne main baseline 30.479s 125.189ms 3.3118x
    PR #27013, fresh sample 1 5.116s 201.940ms 1.016x
    PR #27013, fresh sample 2 5.220s 431.742ms 0.993x
    PR #27013, fresh sample 3 5.338s 208.670ms 1.012x
    MySQL reference 9.618s 6.867ms 1.0046x
    PostgreSQL reference 9.030s 0.419ms 0.9989x

    Across the three PR samples, first-window p50 values were approximately 0.263-0.293ms and final-window p50 values were approximately 0.271-0.294ms. The first-to-last p50 ratios were 0.993-1.016x. Periodic 100-153ms individual outliers appeared in non-terminal windows and raised some window averages; there was no monotonic increase by transaction position.

    All three PR samples passed post-commit row-count, distinct-key, and inventory-balance validation.

  14. gouhongshen commented on Aug 14, 2026

    @gouhongshen
    ContributorAuthor

    Benchmark update: Ledger Posting

    Protocol

    • Fresh MatrixOne instance and fresh data for each sample.
    • Preload 20,000 account-balance rows.
    • Execute 20,000 postings in one transaction.
    • Each posting performs one account-balance UPDATE and one ledger-entry INSERT.
    • ledger_entry.transaction_id is unique.
    • Measure each posting and summarize every 1,000 postings.
    • Measure COMMIT separately.
    • Validate all balances and unique ledger transactions after COMMIT.

    Results

    Build / database Transaction phase COMMIT Last 3 / first 3 window p50
    MatrixOne main baseline 29.354s 93.728ms 4.1613x
    PR #27013, fresh sample 1 4.191s 158.537ms 0.964x
    PR #27013, fresh sample 2 4.271s 171.149ms 0.991x
    PR #27013, fresh sample 3 4.092s 158.975ms 0.962x
    MySQL reference 8.588s 5.824ms 1.0029x
    PostgreSQL reference 8.054s 0.468ms 0.9991x

    Across the three PR samples, first-window p50 values were approximately 0.174-0.189ms and final-window p50 values were approximately 0.172-0.183ms. The last-to-first p50 ratios were 0.962-0.991x. Periodic 61-84ms individual outliers appeared in non-terminal windows; there was no monotonic increase by transaction position.

    All three PR samples passed post-commit account-balance, row-count, and unique-transaction validation.

  15. 7 remaining items

  16. added
    severity/s0
    ai-easy
    and removed on Oct 15, 2026
  17. gouhongshen commented on Oct 15, 2026

    @gouhongshen
    ContributorAuthor

    Automated revalidation and deferral analysis (issue-fix-loop handler turn, 2026-10-15)

    Verdict: the regression still reproduces on current main. The root cause is the positional CN transaction-workspace architecture, whose replacement is already in active delivery by the issue assignee in draft PR #27013. An independent competing rewrite is not a safe or reviewable path for the automated loop, so this issue is deferred back to human coordination with fresh evidence.

    1. Reproduction on the assigned base

    • Build: 83222fa8371007c7969d3aeca3ab8ced90695f4c (current main at this turn), go1.27.1 darwin/arm64, fresh single-node instance with fresh local-disk data per run.
    • Protocol: the ORM Unit of Work scenario from this issue — 30,000 preloaded rows, one client/connection/long transaction, 30,000 parameterized single-row UPDATE customer_profile SET level = level + 1, updated_at = ? WHERE id = ?, one COMMIT; table has a primary key plus UNIQUE(email) and UNIQUE(external_id). 1,000-update windows. (Client used the text protocol with inlined parameters instead of binary prepared statements; this does not change the workspace cost path.)
    Run First-3 window avg median Last-3 window avg median Last/First Window-1 p50 → Window-30 p50 Update phase COMMIT
    Single long txn, 2 unique indexes 4.250 ms 15.420 ms 3.628x 1.519 ms → 7.663 ms (~5.0x) 260.4 s 71.2 ms
    Same SQL, COMMIT every 5,000 (control) 1.950 ms 2.386 ms 1.224x 1.704 ms → 1.927 ms 90.7 s 0.122 ms (per chunk)
    Single long txn, no unique indexes (control) 2.385 ms 5.251 ms 2.202x 1.901 ms → 4.961 ms 139.7 s 77.6 ms

    The issue's degradation criterion (last-three/first-three window avg median ≥ 3x and each last-three window ≥ 2x the initial median) is met on the assigned base for the two-unique-index long transaction. The controls reproduce the issue's own ablations: committing every 5,000 statements keeps windows flat (1.22x), and dropping the unique indexes reduces but does not remove the growth (2.20x) — matching the issue's Benchmark B and C pattern that the workspace structure is the size-dependent component and the unique-index machinery amplifies through it. Absolute latencies are inflated by concurrent load on this shared build host; the first-to-last trend is the meaningful signal. All three runs passed post-COMMIT validation: rows=30000, count(distinct email)=30000, count(distinct external_id)=30000, sum(level)=30000, and row 1 carries the expected values — the defect is latency growth, not correctness.

    2. Root-cause paths still present on the base

    The profile call sites recorded in this issue map to the same positional workspace code on 83222fa8:

    • In-transaction reads iterate the positional write prefix: LocalDisttaeDataSource.filterInMemUnCommittedInserts walks txn.writes[wsCursor, txnOffset) per table scan and runs the PK filter on every same-table entry (pkg/vm/engine/disttae/local_disttae_datasource.go:637, :573), matching the reported TableScan -> iterateInMemData -> filterInMemUnCommittedInserts hot path (~18% cumulative).
    • Statement boundaries do full-history maintenance: Transaction.IncrStatementID → mergeTxnWorkspaceLocked sweeps all txn.writes entries (batch-shrink, tables-in-vain, insert/delete bitmap passes) and then dumpBatchLocked(ctx, 0) (pkg/vm/engine/disttae/types.go:858, pkg/vm/engine/disttae/txn.go:2056), matching the IncrStatementID heap growth in the issue profile.
    • The representation itself is positional: writes []Entry, snapshotWriteOffset, adjustWriteOffset, offsets []int, batchSelectList (pkg/vm/engine/disttae/types.go:396-430). Each single-row UPDATE contributes ~2 same-table entries, so both the read path and statement-end maintenance cost grow linearly with accumulated transaction history, giving the observed super-linear statement latency.

    Existing workspace UTs cover accounting/rollback invariants (e.g. TestIssue25589*, TestMergeTxnWorkspace*) but no size-scaling behavior, so they provide no closure artifact for this curve.

    3. Fix delivery state

    • PR refactor(disttae): redesign CN transaction workspace #27013 (codex/txn-workspace-access-index, head 466b74de6d27b1ac3b106012d908313fa6edfc7c, 30 commits) replaces the positional workspace with StatementJournal/TableOverlay/PayloadStore and ordered active indexes — architecturally the correct root-cause fix for the workspace-size degradation recorded here.
    • As of this turn the PR is OPEN, DRAFT, CHANGES_REQUESTED, merge-conflicting with main, and its head revision fails CI (CI Required / SCA / UT on the head run). The benchmark numbers posted in this issue (e.g. ae69b2b3c3) predate the current head and do not establish a merged fix.
    • The residual cost already isolated by the assignee — per-statement hidden unique-index point-DELETE maintenance (~2.85 ms/statement, flat first-to-last windows, see the 2026-08-14 ablation comment) — is an absolute-cost problem in pkg/sql/plan/build_dml_util.go (buildDeleteIndexPlans) and its execution operators, is out of scope for refactor(disttae): redesign CN transaction workspace #27013 by the owner's own statement, and does not produce a size-dependent curve. It needs a separately owned issue before the automated loop can act on it.

    4. Why the loop did not produce an independent fix

    The defect that produces every size-dependent curve recorded in this issue is the workspace's positional representation. The only root-cause fix is the workspace re-architecture already being delivered in #27013 by the human assignee. Reimplementing active workspace indexes inside this loop would duplicate a 100+ file draft across the same positional invariants the owner is still iterating (statement rollback truncation, RC visibility advancement, CN transfer state, spill/compaction, payload reclamation), could not be proven against that same correctness matrix in one session, and would land as an unmergeable conflict with the owner's active PR. This matches the ai-heavy label ("AI assists; core logic by humans") and the 2026-09-04 triage deferral.

    Requested human action: the transaction/performance owner drives #27013 to a mergeable, CI-green state and re-runs this issue's benchmark matrix on its final revision; once it merges, this issue can be closed by re-measurement. Separately, spin off the hidden-unique-index DELETE maintenance cost into its own issue with an owner. Removing the deferred label returns the issue to the AI candidate pool.

  18. added
    severity/s0
    and removed
    severity/s0
    on Oct 15, 2026
  19. gouhongshen commented on Oct 20, 2026

    @gouhongshen
    ContributorAuthor

    PR #30685 is trying to fix this issue.

  20. gouhongshen commented on Oct 21, 2026

    @gouhongshen
    ContributorAuthor

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

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

Metadata

Metadata

Assignees

Labels

ai-easyai-heavyseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions