Skip to content

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

Closed as not planned

Description

@Ariznawlll

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.

Activity

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

    @XuPeng-SH
    Contributor

    Tracking consolidated into #30910. The canonical issue retains this report’s full reproduction/discussion and independent acceptance requirements. This is administrative consolidation, not a claim that the defect is fixed. Original evidence remains preserved here.

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