Bug #109334 | Incorrect index cardinality when innodb_stats_method=nulls_ignored | ||
---|---|---|---|
Submitted: | 12 Dec 2022 0:33 | Modified: | 13 Dec 2022 18:54 |
Reporter: | Manuel Ung | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S3 (Non-critical) |
Version: | 8.0.31 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[12 Dec 2022 0:33]
Manuel Ung
[12 Dec 2022 0:33]
Manuel Ung
As a side note, https://bugs.mysql.com/bug.php?id=95507 describes a bug where innodb_stats_method=nulls_unequal doesn't work, because it behaves exactly the same as nulls_equal. This can be easily verified by reading the code. This means that of all 3 settings (nulls_equal, nulls_unequal, nulls_ignored), there's only one setting (the default nulls_equal) that isn't broken for persistent stats.
[12 Dec 2022 8:35]
MySQL Verification Team
Hello Manuel Ung, Thank you for the report and feedback. regards, Umesh
[13 Dec 2022 9:02]
huahua xu
Hi Manuel Ung: For the table and index statistics collection in InnoDB, you need to known that the approximate number of non-null key values will not calculated, If persistent statistics is enabled. 1. set innodb_stats_persistent = on. mysql> set global innodb_stats_persistent = on; mysql> analyze table t; mysql> show index from t; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | t | 0 | PRIMARY | 1 | i | A | 110157 | NULL | NULL | | BTREE | | | YES | NULL | | t | 0 | PRIMARY | 2 | j | A | 110157 | NULL | NULL | | BTREE | | | YES | NULL | | t | 1 | k | 1 | k | A | 110157 | NULL | NULL | YES | BTREE | | | YES | NULL | | t | 1 | k | 2 | j | A | 110157 | NULL | NULL | | BTREE | | | YES | NULL | | t | 1 | k | 3 | i | A | 110157 | NULL | NULL | | BTREE | | | YES | NULL | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 1. set innodb_stats_persistent = off. mysql> set global innodb_stats_persistent = off; mysql> analyze table t; mysql> show index from t; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | t | 0 | PRIMARY | 1 | i | A | 1 | NULL | NULL | | BTREE | | | YES | NULL | | t | 0 | PRIMARY | 2 | j | A | 112262 | NULL | NULL | | BTREE | | | YES | NULL | | t | 1 | k | 1 | k | A | 100148 | NULL | NULL | YES | BTREE | | | YES | NULL | | t | 1 | k | 2 | j | A | 100148 | NULL | NULL | | BTREE | | | YES | NULL | | t | 1 | k | 3 | i | A | 101171 | NULL | NULL | | BTREE | | | YES | NULL | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
[13 Dec 2022 18:54]
Manuel Ung
Yes, I understand that non-null key values are not calculated for persistent stats. That is the bug I am reporting.