Skip to content

[Performance]: table stats ignore large DELETEs until ANALYZE runs #31880

Open

Description

@Ariznawlll

Description

Table stats (mo_catalog.mo_table_stats_alpha.table_rows) do not refresh after a massive DELETE — they stay at the pre-DELETE row count for at least 15 seconds, and only ANALYZE TABLE brings them current. INSERTs get incremental updates immediately (verified in the same session), making the stale-on-DELETE behavior asymmetric: the planner reads 5x-large table estimates for queries issued right after batch cleanup.

Controlled measurement (main c6683bd2f5, 2026-10-30), table vx.ja created with exactly 50,000 rows:

step mo_table_stats_alpha.table_rows reality
after INSERT 50k 50,000 ✓ (immediate, no ANALYZE) 50,000
DELETE WHERE id >= 10000 (removes 40k) 50,000 (immediately after) 10,000
+3 s 50,000 10,000
+15 s 50,000 — stale 10,000
ANALYZE TABLE ja + 1 s 50,000 10,000
ANALYZE + 5 s 10,000 ✓ 10,000

So INSERT-side stats are incremental & timely; DELETE-side stats have no trigger other than explicit ANALYZE (which itself lands within ~5s).

Why this matters in production terms: any ETL/sync flow that deletes a large window and immediately issues joins against remaining rows will plan against the pre-delete cardinality for an unbounded window (≥ 15 s measured, no scheduled refresh observed — the count only moved when ANALYZE was issued, not by any background task in the 15s monitored). MySQL behavior: InnoDB refreshes table stats once ~10% of rows change (and that's after ~16% of page-mod threshold heuristics); on a live DB, an 80% reduction should absolutely force a refresh. The insert-side machinery proves the incremental-update hook exists; DELETE needs the same trigger.

Impact: stale-estimate-driven plan choice for the minutes after large cleanup — probes that cannot read plans' row-count estimates (MO EXPLAIN doesn't print them — a separate observability note) cannot even diagnose the cause, because only Analyze-realized rows (EXPLAIN ANALYZE) expose inputRows, which of course matches the real scan by then.

Expected behavior

Same threshold-based refresh semantics as INSERT side (≥ ~10% changed rows triggers refresh, or timestamp-based periodic maintenance — whichever the current INSERT path uses), so queries issued right after a DELETE work with approximately current estimates.

Reproduction

CREATE TABLE ja(id INT PRIMARY KEY, k INT, KEY ik(k)); -- 50k inserts
SELECT table_stats->'$.table_rows' FROM mo_catalog.mo_table_stats_alpha WHERE table_name='ja';
DELETE FROM ja WHERE id >= 10000;
-- immediately and +15s: stats still 50000; reality 10000
ANALYZE TABLE ja;  -- +5s: stats become 10000

main @ c6683bd; temporal sequence above was timed with wall-clock sleeps against mo_table_stats_alpha; INSERT-side timeliness was verified in the same session as positive control.

Activity

  1. added
    kind/bug
    on Oct 30, 2026
  2. added this to the MO-202610 milestone on Oct 30, 2026
  3. added theissue type on Oct 30, 2026
  4. Ariznawlll commented on Nov 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    Update from re-testing on current main (2026-11-02, etc/launch-multi-cn 2-CN setup) — the DELETE-staleness reported here is one facet of a broader estimate-refresh failure, now filed as #31993 with full reproductions.

    Root-cause direction (black-box inferred): planner row estimates derive from flushed block metadata only (blockNum in EXPLAIN VERBOSE tracks the estimate 1:1). DELETE tombstones never decrement block counts, so the estimate can only go down via ANALYZE/TRUNCATE. Symmetrically, memtable (unflushed) inserts are invisible — a freshly loaded 87,654-row table estimates as the default 1,000 until manual mo_ctl('DN','FLUSH',...).

    Also confirmed on main: estimates are pinned per-CN on first read and ANALYZE results do not propagate to peer CNs (still stale after 6 minutes), so in a multi-CN deployment the chosen plan depends on which CN serves the query.

    Note: mo_catalog.mo_table_stats_alpha on main no longer contains rows for user tables (its schema changed to JSON table_stats); the staleness therefore is not about that table's refresh lag but about the block-metadata → per-CN-cache path itself.

  5. changed the title [-][Bug]: table stats ignore large DELETEs until ANALYZE runs[/-] [+][Performance]: table stats ignore large DELETEs until ANALYZE runs[/+] on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions