Skip to content

[Bug]: Public table and index statistics report zero for populated analyzed objects #30910

Open

Description

@Ariznawlll

Consolidated tracking scope: Public table/index statistics reflect observed populated state

Consolidate the statistics-publication work item across information_schema.TABLES row/size fields and STATISTICS index cardinality. The two view projections and their data sources are distinct acceptance paths; no one-field fix is claimed to resolve the other.

Administrative consolidation does not mean these defects are fixed. Each distinct path below remains independently required; original bodies and discussions remain preserved.

Included reports

  • #31164 — [Bug]: information_schema.STATISTICS reports zero cardinality after ANALYZE on populated indexes

Acceptance checklist

  • information_schema.TABLES and corresponding status consumers expose meaningful row/data/index-size observations for populated tables; retain working mo_table_size controls and empty-table controls.
  • After ANALYZE on a small populated table, primary and secondary index cardinalities are nonzero estimates consistent with observed distinct-key populations; preserve empty and low/high-NDV controls.
  • Distinguish an unavailable estimate from a known zero; do not assert exact counts where the metadata contract allows approximate statistics.
  • Preserve actual query rows and statistics status, including failed ANALYZE of a missing table and subsequent reuse. Row/size and index-NDV publication each need explicit regression coverage.

Preserved additional reports

#31164: [Bug]: information_schema.STATISTICS reports zero cardinality after ANALYZE on populated indexes

Source: #31164

Original issue body

Description

information_schema.STATISTICS.CARDINALITY reports 0 for populated primary and secondary indexes even after a successful ANALYZE TABLE. This falsely presents each populated index as having no distinct keys.

Environment

  • Branch: official main
  • Commit: 5fe08a3307e246e1ab9951ab690b50557af0f509
  • Deployment: fresh isolated LOG/TN/CN cluster, SQL port 36601, 2026-10-26
  • Reference: isolated MySQL 8.3.0, local socket only

Steps to reproduce

CREATE DATABASE qa_indexcard_repro;
CREATE TABLE qa_indexcard_repro.t (
  id INT PRIMARY KEY, v INT, KEY ix_v(v)
);
INSERT INTO qa_indexcard_repro.t VALUES
  (1,10),(2,20),(3,30),(4,40),(5,50),(6,60),(7,70),(8,80);
ANALYZE TABLE qa_indexcard_repro.t;
SELECT index_name,cardinality FROM information_schema.statistics
WHERE table_schema='qa_indexcard_repro' AND table_name='t'
ORDER BY index_name;
SELECT COUNT(*),COUNT(DISTINCT v) FROM qa_indexcard_repro.t;

Actual behavior

MatrixOne ANALYZE TABLE reports population_rows=8, population_exact=1, sample_rows=8, status OK, while both PRIMARY and ix_v cardinality remain 0. This occurred in three independent fresh databases (3/3).

Expected behavior

The metadata should report a nonzero estimate after analyzing indexes with eight distinct keys. MySQL 8.3.0 reports 8 for both indexes in each of the same three fixtures. If the index cardinality is unavailable, it should not be falsely represented as known zero.

Stability and controls

  • Reproducer: 3/3 fresh databases qa_indexcard_1, _2, _3.
  • Happy control: an analyzed empty table's PRIMARY and ix_v cardinality are 0 in both engines.
  • Unhappy/continuation check: ANALYZE TABLE qa_indexcard_3.missing returns table-not-found; the populated table remains readable with COUNT(*)=8 and COUNT(DISTINCT v)=8.

Evidence

Each of the three rounds:

                 populated PRIMARY  populated ix_v  empty PRIMARY  empty ix_v
MatrixOne        0                  0               0              0
MySQL 8.3        8                  8               0              0

Code analysis

pkg/util/sysview/predefined.go InformationSchemaStatisticsDDL emits the literal 0 AS CARDINALITY for every index. The index-statistics view does not use the populated table/index statistics even after ANALYZE. This is distinct from #30910, which tracks information_schema.TABLES row/size fields, not index cardinality.

Regression coverage

Assert primary and secondary index cardinality metadata for empty, low-NDV and high-NDV tables before/after ANALYZE, with query results and statistics status as controls.


Original canonical report (preserved verbatim)

Description

information_schema.tables reports TABLE_ROWS, DATA_LENGTH, and INDEX_LENGTH as 0 for every user table, even for tables with hundreds of thousands of rows. MySQL reports real (approximate) row counts and byte sizes, so any tooling that relies on these columns — ORM pagination estimates, capacity/usage dashboards, backup-size planning, migration dry-runs — sees every MatrixOne table as empty.

Environment

  • MatrixOne dev build 3a1e42b430, server reports 8.0.30-MatrixOne-v1.3.0
  • MySQL comparison: 8.0.45 (localhost)

Reproduction

CREATE DATABASE d;
CREATE TABLE d.f (id INT PRIMARY KEY AUTO_INCREMENT, v INT, pad VARCHAR(20));
INSERT INTO d.f (v, pad) SELECT result, 'x' FROM generate_series(1, 200000);  -- 200,000 rows

SELECT table_name, table_rows, data_length, index_length
FROM information_schema.tables WHERE table_schema = 'd';

MatrixOne:

table_name  table_rows  data_length  index_length
f           0           0            0

MySQL (same shape, e.g. a populated InnoDB table):

TABLE_NAME  TABLE_ROWS  DATA_LENGTH
f           200000      5783552

Impact

  • Table-size/row-count monitoring and capacity planning report all tables as empty.
  • Migration/ETL tools that size their batches or progress from TABLE_ROWS will misbehave.
  • SHOW TABLE STATUS and any client-side "row estimate" feature degrade to zero.

Notes

  • This is independent of mo_table_size('db','table'), which does return a size; the gap is specifically the information_schema.tables statistics columns never being populated.
  • The behavior is uniform across all engines/tables in this build (all return 0), suggesting the statistics are simply not wired into the information_schema projection rather than a per-table issue.

合并跟踪:公开表/索引统计投影

本项统一跟踪 #30910、#31752、#31878,唯一负责人:@gouhongshen。这是问题整理,不代表修复完成或验收通过;各来源的独立复现与验收仍须分别完成。以下证据为原报告/评论的记录,不是本轮重新实测。

独立验收与边界

范围边界:不并#31880底层DELETE后stats失效:来源过期与视图未接线不同。

来源 #31752:原始报告完整保留

来源:https://github.com/matrixorigin/matrixone/issues/31752,作者:Ariznawlll,创建时间:2026-10-29T10:28:24Z。

#31752 完整复现、版本、证据和预期

Description

information_schema.TABLES.TABLE_ROWS and information_schema.STATISTICS.CARDINALITY are permanently 0 for every table, while the engine's own statistics backend holds accurate, fresh counts — the wiring between them is missing.

Reproduced on main c6683bd2f5 (2026-10-29, dual-CN launch; identical on both CNs):

CREATE TABLE sgx.t(id INT PRIMARY KEY, a INT, b INT, s VARCHAR(30));
CREATE INDEX i1 ON sgx.t(a); CREATE UNIQUE INDEX i2 ON sgx.t(b); CREATE INDEX i3 ON sgx.t(a,b);
INSERT INTO sgx.t ... (100 rows);           -- verified COUNT(*) = 100

SELECT TABLE_ROWS FROM information_schema.TABLES
 WHERE TABLE_SCHEMA='sgx' AND TABLE_NAME='t';
-- 0    (real: 100)

SELECT INDEX_NAME, CARDINALITY FROM information_schema.STATISTICS
 WHERE TABLE_SCHEMA='sgx' AND TABLE_NAME='t';
-- PRIMARY 0, i1 0, i2 0, i3 0, i3 0   (all five zero)

SELECT mo_ctl('dn','flush','sgx.t');        -- force a flush, wait
-- TABLE_ROWS still 0

The engine's stats store is alive and accurate — the catalog table backing the feature holds exact per-table row counts that track writes in near-real-time (verified by direct query):

SELECT table_name, table_stats, update_time FROM mo_catalog.mo_table_stats_alpha;
-- ('t', '{"dblock_cnt": 1, ..., "table_rows": 100, "table_size": 3952, ...}',
--        2026-10-29 10:28:00)   ← correct count, fresh timestamp

So the defect is the information_schema projection layer: TABLES.TABLE_ROWS and STATISTICS.CARDINALITY are rendered as constants (0) instead of joining mo_table_stats_alpha (or asking the CN stats cache). The data to serve these columns exists; the two views simply never consult it.

Adjacent surface verified healthy: STATISTICS structure is perfect (PRIMARY/i1/i2/i3 with correct COLUMN_NAME, SEQ_IN_INDEX, NON_UNIQUE per column of the composite, BTREE type, 4 distinct indexes in SHOW INDEX matching CREATE INDEX statements), and columns' COLUMN_KEY (PRI/UNI/MUL) is correct — this is strictly about the numeric statistics columns.

Impact

  • Every capacity/dashboards/DBA tool reading TABLE_ROWS for sizing or growth graphs (Grafana SQL datasource, phpMyAdmin-style UIs, catalog extractors) sees a fleet of empty tables; drift Мониторing and growth alerting are impossible off these views.
  • Optimizer-introspection tooling that estimates index selectivity via CARDINALITY concludes every index is fully degenerate.
  • Related regression context: FOUND_ROWS()/SQL_CALC_FOUND_ROWS regression reported on [Bug] FOUND_ROWS() returns incorrect row count after SELECT and SQL_CALC_FOUND_ROWS #27304 shows the same "statistics-backed number served instead of the accurate count" signature on the current main — if these estimates leak into FOUND_ROWS, this wiring gap may be a shared root.

Expected behavior

TABLE_ROWS and CARDINALITY should surface the mo_table_stats_alpha values (or a live count for fresh small tables) per MySQL semantics (approximate is fine — MySQL itself reports estimates — but 0-for-everything is not an estimate).

Reproduction

Create table + 2 INSERTs + the two information_schema queries; deterministic zero on any table at any time. main @ c6683bd, pymysql. mo_table_stats_alpha sampled in the same session showing correct data (100).

来源 #31752 的补充证据(2026-10-29T10:33:12Z,Ariznawlll)

原评论:#31752 (comment)

原评论完整保留(原作者记录,非本轮实测)

Symptom-scope completion for the filed report: the zero-constant renders cover the whole size statistics family, and the boundary to working columns is sharp — verified on the same build (main c6683bd2f5, 2026-10-29):

SELECT TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH, AVG_ROW_LENGTH, DATA_FREE
FROM information_schema.TABLES WHERE TABLE_SCHEMA='sgx' AND TABLE_NAME='t';
-- (0, 0, 0, 0, 0)   ← all zero for a 100-row/3952-byte table (mo_table_stats_alpha has: table_rows=100, table_size=3952)

SELECT TABLE_NAME, AUTO_INCREMENT FROM information_schema.TABLES ...  -- for a true AUTO_INCREMENT table with 3 rows:
-- ('ai_meta', 4)    ← WORKS correctly! counter metadata is wired, unlike size/rows

AUTO_INCREMENT returning accurate state 4 after 3 inserts proves information_schema CAN render live per-table engine state — the zeros are specific to the stats-derived columns (TABLE_ROWS / DATA_LENGTH / INDEX_LENGTH / AVG_ROW_LENGTH / DATA_FREE), all of which have ready values in mo_table_stats_alpha (table_rows AND table_size). So this is one projection-layer wiring fix covering the entire column family, adjacent to a column that is already wired — a tight scope for whoever picks this up.

来源 #31878:原始报告完整保留

来源:https://github.com/matrixorigin/matrixone/issues/31878,作者:Ariznawlll,创建时间:2026-10-30T08:01:03Z。

#31878 完整复现、版本、证据和预期

Description

information_schema.TABLES.TABLE_ROWS reports 0 for every user table even when the catalog stats table (mo_catalog.mo_table_stats_alpha) contains accurate row counts for the same tables — a metadata presentation-layer disconnect that makes the information-schema surface useless for anything that inspects size (SHOW TABLE STATUS and maturity dashboards built on it).

Fresh proof on main c6683bd2f5 (2026-10-30):

table real count (COUNT(*)) mo_table_stats_alpha.table_rows information_schema.TABLE_ROWS
vx.sx 50,000 50,000 ✓ 0
vx.roll 6 6 ✓ 0
sex.f 200,000 200,000 ✓ 0
perf.big 500,000 100,000 (stale) 0

ANALYZE TABLE also fails to recover the value (checked with two waits after ANALYZE at 0.4s and 1.2s — still 0). SHOW TABLE STATUS inherits the same null/0 fields (row_format/data_length/avg_row_length also 0 for the row shown).

MySQL pivots: TABLE_ROWS powered by InnoDB's statistics cache is a cached estimate, which is close to actual under vacuum periods; MO documents compatibility-driven expectations: when stats exist respond+them, like the currently live catalog table; when stats are missing respond with 0/disregard. The decision would be consistent with actual behavior either way, but currently: stats exist, are accurate, and the surface still shows 0.

Impact

  • SHOW TABLE STATUS/monitoring query (information_schema.TABLES WHERE TABLE_ROWS > N) shows every table empty — observability tooling that relies on size to fairly distribute work (partition sizing, threshold-based compaction triggers, free-space estimate dashboards) sees everything as zero-row no matter what.
  • EXPLAIN cost estimation (which may be affected, if driven from the same presentation path) — to confirm separately; the STATISTICS.CARDINALITY=0 result observed in the same session suggests the estimate path is also seeing these zeros.

Expected behavior

When per-table stats exist in mo_table_stats_alpha, surface the stored table_rows (+size) into information_schema.TABLES rows. Optionally STAY_0 as a documented flag when stats are missing entirely, with a computed fallback to block-count backup for early days after creation.

Reproduction

CREATE TABLE sx(id INT PRIMARY KEY, v INT); -- 50k rows
SELECT TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_NAME='sx';    -- 0
SELECT JSON_EXTRACT(table_stats, '$.table_rows') FROM mo_catalog.mo_table_stats_alpha WHERE table_name='sx';  -- 50000

main @ c6683bd; counts cross-verified to source of truth in the same session.

Activity

  1. added this to the MO-202610 milestone on Oct 23, 2026
  2. added theissue type on Oct 23, 2026
  3. changed the title [-][Bug]: information_schema.tables reports 0 rows/size for all tables[/-] [+][Bug]: Public table and index statistics report zero for populated analyzed objects[/+] on Oct 26, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Oct 28, 2026
  5. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充一个与本 issue 同范围但独立的输出路径:SHOW INDEX 的 Cardinality 在当前 main d39d8a40343ccd40bf665036388df7a40ee867f8 的 pkg/sql/plan/build_show.go 中直接生成 0 as Cardinality,不读取 ANALYZE TABLE 结果。这不同于原 #31164 的 information_schema.STATISTICS 视图投影,但用户可见症状相同,建议作为本 issue 的单独验收点。

    隔离集群中 3 张独立新表均为 1000 行、COUNT(DISTINCT token)=1000、隐藏唯一索引实际 1000 键;每张执行 ANALYZE TABLE 成功后,SHOW INDEX 的主键、唯一键和二级索引 Cardinality 仍全部为 0(3/3)。这只是元数据错误,不表示物理唯一索引缺失;上述三张表的主表与隐藏索引完整键集合逐键一致。请保留“真实物理索引行数”与“统计估计值”两种检查,避免排查 #31853 时误判。

  6. XuPeng-SH commented on Nov 9, 2026

    @XuPeng-SH
    Contributor

    Consolidating #32309 here as another reproduction of the existing information_schema.TABLES row/size publication gap. Preserve its 9M-row example and the comparison against accurate mo_table_stats_alpha values. Keep TABLES row/size publication separate from STATISTICS cardinality estimation already tracked here; a zero-row/zero-size projection and an index-NDV estimate are distinct acceptance paths.

  7. added and removed
    severity/s0
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions