Skip to content

[Bug]: TABLE_ROWS and CARDINALITY are stuck at zero #31752

Closed as duplicate
Closed as duplicate

Description

@Ariznawlll

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).

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    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.

  5. XuPeng-SH commented on Oct 31, 2026

    @XuPeng-SH
    Contributor

    已并入 #30910(公开表/索引统计投影)。本项的完整复现、版本、证据和独立验收要求已保留在主 issue,后续统一在主项跟踪,唯一负责人为 @gouhongshen。

    本次关闭仅为问题整理/合并,不代表缺陷已修复、测试通过或所有来源具有同一根因;各独立验收仍须完成。

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