Repository navigation
Description
Environment
- MatrixOne main@HEAD (c6683bd), 3-CN local cluster
- Table:
stale_t (k INT PRIMARY KEY, g INT NOT NULL, v INT, KEY idx_g(g))
Reproduction
-- 100k rows, then ANALYZE
INSERT INTO stale_t SELECT ... ; -- 100,000 rows
ANALYZE TABLE stale_t;
EXPLAIN VERBOSE SELECT COUNT(*) FROM stale_t WHERE g = 7;
-- outcnt=1000 (100k rows / 100 groups — precise ✓)
-- now grow the table 10x with identical distribution
INSERT INTO stale_t SELECT ... ; -- +900,000 rows (same k % 100 pattern)
EXPLAIN VERBOSE SELECT COUNT(*) FROM stale_t WHERE g = 7;
-- TableCnt is refreshed (selectivity recomputed) but outcnt stays pinned:
-- outcnt=1000 ← actual is 10,001 — a 10x underestimateThe estimate does not recover after 75 seconds, hours, or ever — only a manual ANALYZE fixes it.
Root cause (code)
pkg/vm/engine/disttae/txn_table.go:290 (transientTableStats): on every query the engine recomputes the live row count (getLatestPartitionState + partitionRowEstimate) and refreshes only TableCnt and SizeMap. NdvMap, MinValMap, MaxValMap, NullCntMap are copied unchanged from the last ANALYZE snapshot:
func transientTableStats(published *pb.StatsInfo, rows float64) *pb.StatsInfo {
var stats pb.StatsInfo
if published != nil {
stats = *published // NDV/Min/Max/NullCnt frozen at last ANALYZE
...
stats.TableCnt = rows // only this is refreshedConsequences:
- The visible cost model is internally inconsistent:
selectivityshrinks as TableCnt grows while NDV stays stale, sooutcnt = TableCnt × selectivitylands on arbitrary values (here 1000). - There is no background re-ANALYZE (no daemon, no staleness detection;
StatsInfohas no timestamp field) andPatchStatsis only invoked manually from a table function.
Impact
Any INSERT/DELETE-heavy table (orders, logs, events — the tables where stats matter most) silently degrades to stale-NDV estimates between ANALYZEs. Join build/probe sizing, join order, dop and index selection all inherit the error, compounding with the join-NDV issues (#32122 family). Operators get "the plan was good yesterday, slow today" with no tool to notice except manually re-running ANALYZE.
Suggested fix direction
- Track per-table DML delta since last ANALYZE and trigger async re-ANALYZE past a ratio threshold (like MySQL's
innodb_auto_recalc), or - At minimum, expose staleness (rows-since-analyze) in
mo_table_stats_alphaso the inconsistency is observable.
Activity
XuPeng-SH commentedon Nov 9, 2026
This issue is being consolidated into #31993, the broader planner-statistics freshness issue. Preserve the distinct stale NDV/min/max/null-count-after-bulk-DML reproduction and ANALYZE control as acceptance coverage in #31993.