The cardinality is placed on the MySQL storage engine layer. The sampling value is taken.
In the InnoDB storage engine, updates to cardinality statistics occur in two operations: Insert and update
The update policy is:
-1/16 of the data in the table has changed
-stat_modified_counter>2000 (Stat_modified_counter is a counter in the InnoDB storage engine)
The default InnoDB storage engine samples 8 leaf nodes. Affected by the parameter innodb_stats_sample_pages.
When executing a statement analyze table, Show table status, show index, Access information_schema.tables, Access Information_ Schema.statistics will cause the InnoDB storage engine to recalculate the value of the cardinality (consult the documentation for the corresponding parameters). These operations can be slow if the data in the table is large and there are multiple secondary indexes.
How cardinality is counted in MySQL-InnoDB