mirror of
https://github.com/MariaDB/server.git
synced 2025-08-27 04:41:35 +02:00

Problem: ======= InnoDB persistent statistics doesn't take innodb_stats_method variable while calculating n_diff_pfx for the n-prefix index columns. Solution: ========= While calculating the persistent statistics, InnoDB consider all NULLS as different value when innodb_stats_method is set to NULLS_UNEQUAL or NULLS_IGNORED. InnoDB statistics depends on the value of "innodb_stats_method" variable when the statistics were last recalculated. dict_stats_analyze_index_level(), dict_stats_scan_page(), dict_stats_analyze_index_below_cur(), dict_stats_analyze_index_for_n_prefix(): All function accepts the parameter to indicate the innodb_stats_method. It also calculates the number of non-null key value for each level or leaf page dict_stats_index_set_n_diff(): calculates the number of non-null values similar to number of different key values. Append the non-default innodb_stats_method variable name for n_diff_pfx statistics description in mysql.innodb_index_stats. IndexScanStatistics: Structure to store the various statistical metric gathered during index scan fetch operation. This structure is being used in dict_stats_analyze_index_level() to fetch the statistics
27 lines
1.2 KiB
Text
27 lines
1.2 KiB
Text
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
|
|
f3 INT, KEY(f1, f3), key(f3)) STATS_PERSISTENT=1,ENGINE=INNODB;
|
|
INSERT INTO t1 SELECT seq, seq, NULL from seq_1_to_16384;
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status OK
|
|
SELECT stat_name, stat_value, stat_description
|
|
FROM mysql.innodb_index_stats WHERE database_name="test" and table_name="t1";
|
|
stat_name stat_value stat_description
|
|
n_diff_pfx01 16341 DB_ROW_ID NULLS_UNEQUAL
|
|
n_leaf_pages 37 Number of leaf pages in the index
|
|
size 97 Number of pages in the index
|
|
n_diff_pfx01 16384 f1 NULLS_UNEQUAL
|
|
n_diff_pfx02 16384 f1,f3 NULLS_UNEQUAL
|
|
n_diff_pfx03 16384 f1,f3,DB_ROW_ID NULLS_UNEQUAL
|
|
n_leaf_pages 1 Number of leaf pages in the index
|
|
size 19 Number of pages in the index
|
|
n_diff_pfx01 16384 f3 NULLS_UNEQUAL
|
|
n_diff_pfx02 16384 f3,DB_ROW_ID NULLS_UNEQUAL
|
|
n_leaf_pages 1 Number of leaf pages in the index
|
|
size 15 Number of pages in the index
|
|
SHOW KEYS FROM t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 1 f1 1 f1 A 16341 NULL NULL BTREE NO
|
|
t1 1 f1 2 f3 A 16341 NULL NULL YES BTREE NO
|
|
t1 1 f3 1 f3 A 16341 NULL NULL YES BTREE NO
|
|
DROP TABLE t1;
|