Bug #103197 | INFORMATION_SCHEMA.STATISTICS/mysql.index_stats not updated by autostats recalc | ||
---|---|---|---|
Submitted: | 2 Apr 2021 22:24 | Modified: | 5 Apr 2021 16:13 |
Reporter: | Marc Reilly | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Information schema | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[2 Apr 2021 22:24]
Marc Reilly
[3 Apr 2021 6:19]
Øystein Grøvlen
I think this is expected behavior in 8.0. See description of information_schema_stats_expiry variable: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_information_sc...
[5 Apr 2021 5:57]
MySQL Verification Team
Thank you, Øystein Grøvlen. Hi Mark, Thank you for the report and feedback. Imho this is an expected behavior in 8.0because the default setting for information_schema_stats_expiry=86400 secs (= 1 day). This is introduced in 8.0 and not present in 5.7. - 8.0.23 Workaround is to set information_schema_stats_expiry=0 which will enable I_S to stop using the cached statistics value and always get latest statistics: mysql> show variables like 'information_schema_stats_expiry'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | information_schema_stats_expiry | 86400 | +---------------------------------+-------+ 1 row in set (0.01 sec) mysql> show global variables like 'information_schema_stats_expiry'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | information_schema_stats_expiry | 86400 | +---------------------------------+-------+ 1 row in set (0.00 sec) - mysql> # 1024 values mysql> SELECT COUNT(*) FROM t3; +----------+ | COUNT(*) | +----------+ | 1024 | +----------+ 1 row in set (0.00 sec) mysql> SHOW INDEX IN t3; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | t3 | 0 | PRIMARY | 1 | i | A | 1 | NULL | NULL | | BTREE | | | YES | NULL | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 1 row in set (0.00 sec) mysql> select * from INFORMATION_SCHEMA.STATISTICS where TABLE_SCHEMA='mysqltest-db1'; +---------------+---------------+------------+------------+---------------+------------+--------------+-------------+-----------+-------------+----------+--------+----------+------------+---------+---------------+------------+------------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | NON_UNIQUE | INDEX_SCHEMA | INDEX_NAME | SEQ_IN_INDEX | COLUMN_NAME | COLLATION | CARDINALITY | SUB_PART | PACKED | NULLABLE | INDEX_TYPE | COMMENT | INDEX_COMMENT | IS_VISIBLE | EXPRESSION | +---------------+---------------+------------+------------+---------------+------------+--------------+-------------+-----------+-------------+----------+--------+----------+------------+---------+---------------+------------+------------+ | def | mysqltest-db1 | t3 | 0 | mysqltest-db1 | PRIMARY | 1 | i | A | 1 | NULL | NULL | | BTREE | | | YES | NULL | +---------------+---------------+------------+------------+---------------+------------+--------------+-------------+-----------+-------------+----------+--------+----------+------------+---------+---------------+------------+------------+ 1 row in set (0.00 sec) mysql> set information_schema_stats_expiry=0; Query OK, 0 rows affected (0.00 sec) mysql> SHOW INDEX IN t3; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | t3 | 0 | PRIMARY | 1 | i | A | 1024 | NULL | NULL | | BTREE | | | YES | NULL | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 1 row in set (0.00 sec) mysql> select * from INFORMATION_SCHEMA.STATISTICS where TABLE_SCHEMA='mysqltest-db1'; +---------------+---------------+------------+------------+---------------+------------+--------------+-------------+-----------+-------------+----------+--------+----------+------------+---------+---------------+------------+------------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | NON_UNIQUE | INDEX_SCHEMA | INDEX_NAME | SEQ_IN_INDEX | COLUMN_NAME | COLLATION | CARDINALITY | SUB_PART | PACKED | NULLABLE | INDEX_TYPE | COMMENT | INDEX_COMMENT | IS_VISIBLE | EXPRESSION | +---------------+---------------+------------+------------+---------------+------------+--------------+-------------+-----------+-------------+----------+--------+----------+------------+---------+---------------+------------+------------+ | def | mysqltest-db1 | t3 | 0 | mysqltest-db1 | PRIMARY | 1 | i | A | 1024 | NULL | NULL | | BTREE | | | YES | NULL | +---------------+---------------+------------+------------+---------------+------------+--------------+-------------+-----------+-------------+----------+--------+----------+------------+---------+---------------+------------+------------+ 1 row in set (0.00 sec) regards, Umesh
[5 Apr 2021 16:13]
Marc Reilly
Ah yes, of course! Thanks for checking Øystein and Umesh.