Skip to content

[Stability test Perf] Dump/monitor Top-N slow SQL: system.statement_info self-scan + mo_cloud.storage getSumStorage #26741

Closed

Description

Summary

On soak fa6c57c (4.2-dev), global Top-N from system.statement_info is dominated by dump/monitor traffic, not business TPCC/sysbench/TPCH:

  1. dump slow-query monitor — SELECT … FROM system.statement_info WHERE duration > 1s AND request_at > NOW()-1m runs ~every 3 minutes, routinely 2–4 minutes, spikes to 10–20 minutes, while scanning ~27–32M rows / ~15–18 GB (near full table).
  2. dump getSumStorage — per-account aggregate on mo_cloud.storage (600M rows / 1000 accounts): avg ~133s, max ~573s, ~700–850 queries/hour.

Business workloads in the same window did not show progressive slowdown; these two fingerprints explain why “global slowest” looks pathological.

Environment

Field Value
Cluster / namespace mo-stb-4-2-dev-fa6c57c-202608041202
Deploy / image fa6c57c → rolled to matrixone:commit-c8dae1d45 (~2026-08-06 10:19–10:25 CST)
Endpoint 10.222.6.255:6001
Artifact /data1/stability-test/30876385810_fa6c57c
Analysis window 2026-08-05 18:30 CST → 2026-08-06 ~03:00 CST
User dump

Table sizes (live COUNT)

Table Rows Span Notes
system.statement_info 31,643,154 2026-08-04 04:07 → 08-06 02:59 ~2-day retention; ~14–16M rows/day
mo_cloud.storage 600,000,000 2025-10-13 → 2026-05-19 1000 accounts × 600k rows; stale vs wall clock (no Aug data)

mo_cloud.storage monthly (all 1000 accounts):

Month Rows
2025-10 52.0M
2025-11 82.5M
2025-12 85.2M
2026-01 85.2M
2026-02 77.0M
2026-03 85.2M
2026-04 82.5M
2026-05 50.5M (truncated at 05-19)

Dump’s hot window May 1–May 19: 49,472,000 rows total (49,472 / account).


Issue A — statement_info self-scan

SQL

SELECT statement, duration / 1000000000 as duration_sec
FROM system.statement_info
WHERE duration > 1000000000
  AND request_at > DATE_SUB(NOW(), INTERVAL 1 MINUTE)
ORDER BY duration DESC
LIMIT 10

Latency & frequency (user=dump)

Metric Value
Samples (duration > 5s) 141
min / avg / max 23s / 195s / 1204s
Duration buckets <60s:19 · 60–180s:76 · 180–300s:43 · 300–600s:9 · ≥600s:4
Hourly rate mostly 17–20 / hour
Inter-arrival avg ~209s (serial: each run takes minutes)
Spike hour 2026-08-06 01:00 — 4 runs, avg 831s, max 1204s (01:16 / 01:34)
rows_read / bytes_scan avg ~27.4M / ~15 GB, max ~31.7M / ~18 GB

Filter claims “last 1 minute + duration>1s”, but each invocation still reads near the entire retained statement_info.

Expected vs actual

Expected Actual
Last-1-minute filter → small range / index scan Near full-table read (tens of millions of rows, tens of GB)
Monitor finishes in seconds Steady minutes; spikes >10–20 min
Monitor does not become the global Top-N Dominates global slowest list

Likely mechanism

  1. Predicate on duration + request_at / DATE_SUB(NOW(), …) may not prune objects (cast / non-sargable / missing suitable index).
  2. Table is wide (statement TEXT + exec_plan TEXT) → high bytes_scan even when row filter should be selective.
  3. Harness runs this on a growing ~30M-row table every few minutes → self-amplifying load.

Proposed fixes

MO / schema

  • Ensure range-friendly access for request_at (consider (request_at, duration) or covering path for this monitor shape).
  • Avoid plans that cast request_at / NOW() in a way that blocks time pruning.

Harness / ops

  • Stop scanning full statement_info for Top-N; use metrics / sampled / pre-aggregated path, or bound request_at with literal timestamps (no NOW() in SQL).
  • Raise interval / add timeout; never run overlapping monitors.
  • Exclude user='dump' from “global business slowest” dashboards.

Issue B — mo_cloud.storage getSumStorage

SQL

SELECT sum(`value`*`interval`) as storage,
       sum(`snapshot_value`*`interval`) as snapshot_storage
FROM `mo_cloud`.`storage`
WHERE collecttime > ?
  AND collecttime <= ?
  AND account = ?
-- example binds: 2026-05-01 08:55:23 ; 2026-05-19 08:55:23 ; <uuid>

Latency & frequency

Metric Value
Samples (duration > 5s) ~3100
min / avg / max 27s / 133s / 573s
Duration buckets <30s:3123 · 30–60s:117 · 60–120s:1315 · 120–300s:1647 · ≥300s:9
Rate ~700–850 / hour (batch of accounts ~every 60s; inter-arrival avg ~4.8s)
rows_read / bytes_scan avg ~24.4M / ~2 GB, max ~49.5M / ~10.5 GB

Likely mechanism

  1. 600M-row table; PK shape (collecttime, account) is suboptimal for hot path account = ? + time range.
  2. Planner often chooses large Table Scan / over-reads (tens of millions of rows) for an ~50k-row/account May window.
  3. High QPS under soak amplifies CN IO/CPU pressure.

Proposed fixes

CREATE INDEX idx_storage_account_collecttime
  ON mo_cloud.storage(account, collecttime);
  • Verify EXPLAIN uses account + time range (not multi-million-row Table Scan).
  • Target: <5s / account after index.

Out of scope

  • Progressive slowdown of TPCC / sysbench / TPCH business SQL (not the Top-N drivers in this window).
  • Leak-txn / wait-active (separate).

Reproduce / verify

EP=10.222.6.255
mysql -h$EP -P6001 -udump -p111 -e "
SELECT COUNT(*) FROM system.statement_info;
SELECT COUNT(*), MIN(collecttime), MAX(collecttime), COUNT(DISTINCT account)
FROM mo_cloud.storage;"

mysql -h$EP -P6001 -udump -p111 -e "
SELECT ROUND(duration/1e9,1) sec, rows_read, ROUND(bytes_scan/1024/1024,1) mb,
       LEFT(statement,120) stmt
FROM system.statement_info
WHERE user='dump' AND request_at >= DATE_SUB(NOW(), INTERVAL 6 HOUR)
ORDER BY duration DESC LIMIT 20;"

EXPLAIN /* statement_info monitor + storage getSumStorage */;
SHOW INDEX FROM mo_cloud.storage;

Activity

  1. ghost added this to the MO-202608 milestone on Aug 6, 2026
  2. ghost added
    kind/bug
    on Aug 6, 2026
  3. ghost added
    severity/s0
    on Aug 6, 2026
  4. ghost added theissue type on Aug 6, 2026
  5. aptend commented on Aug 6, 2026

    @aptend
    Contributor

    We investigated the two slow-query patterns separately.

    1. system.statement_info

    This is an MO optimizer issue.

    request_at is DATETIME(6), while DATE_SUB(NOW(), ...) is resolved as TIMESTAMP. The binder was casting request_at to TIMESTAMP, hiding the storage column behind a cast and preventing effective object/block pruning.

    PR #26755 changes the safe column-vs-statement-constant case to cast the value side to DATETIME instead. Lossy precision conversions, volatile expressions, and column-dependent expressions retain the existing behavior.

    A local EXPLAIN ANALYZE comparison on the final PR commit showed:

    • fixed natural predicate: 1 block / 778 input rows / 6.08 KiB
    • explicit old column-side cast: 11 blocks / 50,342 input rows / 393.30 KiB

    2. mo_cloud.storage

    This has a different cause and is expected under the current detail-table design.

    The storage recorder periodically writes one record for every account. Organizing the table by (collecttime, account) makes these writes monotonic and append-friendly, reducing object-range overlap and LSM merge/write amplification. Changing the ordering to account-first for this one query, or adding a large secondary index, would trade the read improvement for additional write, storage, and compaction cost.

    getSumStorage recalculates daily/month-to-date totals from the detail table. Its scan cost is therefore expected to grow roughly in proportion to the time-window length. If that growth is unacceptable, the appropriate optimization is in mocloud-services: retain the time-first detail table, add coarser hourly/daily rollups, reuse completed-window totals, and scan only the latest incomplete raw window.

    The 600 million rows in this soak were explicitly preloaded from storage_6b.csv by the stability workflow; they were not generated during this soak. They are still useful for exposing the scaling behavior, but the linear scan growth itself is not evidence of an MO storage-engine defect.

    In summary, PR #26755 addresses the statement_info problem. The storage path should be followed up as a rollup/caching optimization in mocloud-services rather than by changing MO pruning semantics.

  6. aptend commented on Aug 10, 2026

    @aptend
    Contributor

    Follow-up on the system.statement_info part: after further cross-database and DST review, we are replacing the value-side cast approach from #26755. Casting a TIMESTAMP boundary to DATETIME is not semantics-preserving across time-zone folds, so that is not the final design.

    PR #26918 instead adds direct DATETIME/TIMESTAMP comparison support while keeping the existing public function result types and instant semantics. The raw request_at column remains visible to storage pruning. Zonemap conversion is applied only when the DATETIME range is order-preserving in the session time zone; a range intersecting a DST fold or gap is conservatively retained for residual evaluation. Fractional TIMESTAMP precision is also preserved.

    On a local two-object reproduction, the natural predicate

    request_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)

    produced a direct block filter and reduced the table scan from two blocks to one. The mo_cloud.storage conclusion in the previous comment is unchanged.

  7. aptend commented on Aug 10, 2026

    @aptend
    Contributor

    Final update: PR #26918 has been merged as dcef98c269 and supersedes #26755. The system.statement_info pruning problem is now fixed in main using direct DATETIME/TIMESTAMP comparison support without changing public temporal-function result types. The mo_cloud.storage analysis and rollup/caching recommendation above remain unchanged.

  8. assigned and unassigned on Aug 11, 2026
  9. assigned and unassigned on Aug 12, 2026
  10. Ariznawlll commented on Aug 13, 2026

    @Ariznawlll
    Collaborator

    验证结果:已不复现

    在 4.2-dev 稳定性测试集群(mo-stb-4-2-dev-b83878b-202608102354,commit b83878b)上检查了最近 48 小时的慢查询:

    Exec.Run 慢查询统计

    • 共 50 条 Exec.Run 记录
    • 耗时范围:1.0s ~ 11.3s
    • 超过 60s:0 条
    • 超过 120s:0 条

    对比原始问题

    查询类型 原始耗时 当前状态
    statement_info 自扫描 2-4 分钟,峰值 10-20 分钟 ❌ 未复现
    getSumStorage (mo_cloud.storage) avg ~133s, max ~573s ❌ 未复现
    最慢 Exec.Run — 11.3s

    slow event

    仅有 S3FS.Read 文件系统 I/O 事件,无 SQL 层面的慢查询。

    结论

    statement_info 自扫描和 getSumStorage 的分钟级慢查询在当前 4.2-dev 稳定性测试中已不复现,最慢查询仅 11.3 秒。

  11. Ariznawlll commented on Aug 14, 2026

    @Ariznawlll
    Collaborator

    补充核查与结论更正

    进一步核对了 #26741 的修复和当前运行镜像,结论如下。

    1. system.statement_info 修复已进入当前 4.2-dev 环境

    当前 SHA 已包含 #27097,因此 request_at > DATE_SUB(NOW(), ...) 的 DATETIME/TIMESTAMP zonemap pruning 修复已经部署。

    2. mo_cloud.storage getSumStorage 仍然慢

    更正上一条“最慢 Exec.Run 11.3s / getSumStorage 未复现”的结论。补充按 account sys:dump 过滤后,同一批 20 条查询的服务端 Exec.Run 为:

    • q2hlb:55.9–66.3s
    • xtwd7:32.3–34.8s

    每条查询仍枚举约 6042 个 blocks;profile 热点在 Group -> TableScan -> BlockDataRead -> S3FS/DiskCache -> LZ4 decode。因此 storage 性能问题仍存在。

    3. Issue scope / follow-up

    #27097 只修复 system.statement_info pruning,不涉及 getSumStorage。根据研发上面的结论,剩余 storage 延迟来自当前 (collecttime, account) 明细表设计,应在 mocloud-services 中通过小时/天级汇总、复用已完成时间窗口的结果、仅扫描最新未完成 raw window 来继续跟踪和优化。

    建议先关联对应的 mocloud-services 跟踪单,避免剩余性能问题丢失;关联后,本 issue 的 MO engine 修复范围可以视为完成。

  12. Ariznawlll commented on Aug 26, 2026

    @Ariznawlll
    Collaborator

    Scope resolution and migration

    This issue originally contained two independent performance problems observed by the 4.2-dev stability test.

    1. system.statement_info self-scan — fixed

    2. mo_cloud.storage / getSumStorage — moved to MatrixFlow

    getSumStorage is a MOC service operation rather than a MatrixOne kernel function. The remaining problem is now tracked in:

    The new tracking issue includes the complete call path, previous MatrixFlow/mocloud-services history, and current 4.2-dev evidence. Current observations still show minute-scale latency: the latest 20 samples average approximately 154s, with a maximum of approximately 215s.

    Closing this MatrixOne issue because the MatrixOne pruning defect is fixed and the remaining service-side work has been migrated. This closure does not mean that getSumStorage has been fixed.

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