Skip to content

Commit ab6c670

Browse files
MDEV-19574 innodb_stats_method is not honored when innodb_stats_persistent=ON
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
1 parent 55e0c34 commit ab6c670

File tree

11 files changed

+377
-108
lines changed

11 files changed

+377
-108
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--- innodb_stats_method.result
2+
+++ innodb_stats_method,NULLS_EQUAL.result
3+
@@ -7,21 +7,21 @@
4+
SELECT stat_name, stat_value, stat_description
5+
FROM mysql.innodb_index_stats WHERE database_name="test" and table_name="t1";
6+
stat_name stat_value stat_description
7+
-n_diff_pfx01 16341 DB_ROW_ID NULLS_UNEQUAL
8+
+n_diff_pfx01 16341 DB_ROW_ID
9+
n_leaf_pages 37 Number of leaf pages in the index
10+
size 97 Number of pages in the index
11+
-n_diff_pfx01 16384 f1 NULLS_UNEQUAL
12+
-n_diff_pfx02 16384 f1,f3 NULLS_UNEQUAL
13+
-n_diff_pfx03 16384 f1,f3,DB_ROW_ID NULLS_UNEQUAL
14+
+n_diff_pfx01 16384 f1
15+
+n_diff_pfx02 16384 f1,f3
16+
+n_diff_pfx03 16384 f1,f3,DB_ROW_ID
17+
n_leaf_pages 1 Number of leaf pages in the index
18+
size 19 Number of pages in the index
19+
-n_diff_pfx01 16384 f3 NULLS_UNEQUAL
20+
-n_diff_pfx02 16384 f3,DB_ROW_ID NULLS_UNEQUAL
21+
+n_diff_pfx01 1 f3
22+
+n_diff_pfx02 16384 f3,DB_ROW_ID
23+
n_leaf_pages 1 Number of leaf pages in the index
24+
size 15 Number of pages in the index
25+
SHOW KEYS FROM t1;
26+
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
27+
t1 1 f1 1 f1 A 16341 NULL NULL BTREE NO
28+
t1 1 f1 2 f3 A 16341 NULL NULL YES BTREE NO
29+
-t1 1 f3 1 f3 A 16341 NULL NULL YES BTREE NO
30+
+t1 1 f3 1 f3 A 2 NULL NULL YES BTREE NO
31+
DROP TABLE t1;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--- innodb_stats_method.result
2+
+++ innodb_stats_method,NULLS_IGNORED.result
3+
@@ -7,16 +7,16 @@
4+
SELECT stat_name, stat_value, stat_description
5+
FROM mysql.innodb_index_stats WHERE database_name="test" and table_name="t1";
6+
stat_name stat_value stat_description
7+
-n_diff_pfx01 16341 DB_ROW_ID NULLS_UNEQUAL
8+
+n_diff_pfx01 16341 DB_ROW_ID NULLS_IGNORED
9+
n_leaf_pages 37 Number of leaf pages in the index
10+
size 97 Number of pages in the index
11+
-n_diff_pfx01 16384 f1 NULLS_UNEQUAL
12+
-n_diff_pfx02 16384 f1,f3 NULLS_UNEQUAL
13+
-n_diff_pfx03 16384 f1,f3,DB_ROW_ID NULLS_UNEQUAL
14+
+n_diff_pfx01 16384 f1 NULLS_IGNORED
15+
+n_diff_pfx02 16384 f1,f3 NULLS_IGNORED
16+
+n_diff_pfx03 16384 f1,f3,DB_ROW_ID NULLS_IGNORED
17+
n_leaf_pages 1 Number of leaf pages in the index
18+
size 19 Number of pages in the index
19+
-n_diff_pfx01 16384 f3 NULLS_UNEQUAL
20+
-n_diff_pfx02 16384 f3,DB_ROW_ID NULLS_UNEQUAL
21+
+n_diff_pfx01 16384 f3 NULLS_IGNORED
22+
+n_diff_pfx02 16384 f3,DB_ROW_ID NULLS_IGNORED
23+
n_leaf_pages 1 Number of leaf pages in the index
24+
size 15 Number of pages in the index
25+
SHOW KEYS FROM t1;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
2+
f3 INT, KEY(f1, f3), key(f3)) STATS_PERSISTENT=1,ENGINE=INNODB;
3+
INSERT INTO t1 SELECT seq, seq, NULL from seq_1_to_16384;
4+
ANALYZE TABLE t1;
5+
Table Op Msg_type Msg_text
6+
test.t1 analyze status OK
7+
SELECT stat_name, stat_value, stat_description
8+
FROM mysql.innodb_index_stats WHERE database_name="test" and table_name="t1";
9+
stat_name stat_value stat_description
10+
n_diff_pfx01 16341 DB_ROW_ID NULLS_UNEQUAL
11+
n_leaf_pages 37 Number of leaf pages in the index
12+
size 97 Number of pages in the index
13+
n_diff_pfx01 16384 f1 NULLS_UNEQUAL
14+
n_diff_pfx02 16384 f1,f3 NULLS_UNEQUAL
15+
n_diff_pfx03 16384 f1,f3,DB_ROW_ID NULLS_UNEQUAL
16+
n_leaf_pages 1 Number of leaf pages in the index
17+
size 19 Number of pages in the index
18+
n_diff_pfx01 16384 f3 NULLS_UNEQUAL
19+
n_diff_pfx02 16384 f3,DB_ROW_ID NULLS_UNEQUAL
20+
n_leaf_pages 1 Number of leaf pages in the index
21+
size 15 Number of pages in the index
22+
SHOW KEYS FROM t1;
23+
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
24+
t1 1 f1 1 f1 A 16341 NULL NULL BTREE NO
25+
t1 1 f1 2 f3 A 16341 NULL NULL YES BTREE NO
26+
t1 1 f3 1 f3 A 16341 NULL NULL YES BTREE NO
27+
DROP TABLE t1;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[NULLS_EQUAL]
2+
--innodb_stats_method=nulls_equal
3+
--use_stat_tables=never
4+
5+
[NULLS_UNEQUAL]
6+
--innodb_stats_method=nulls_unequal
7+
--use_stat_tables=never
8+
9+
[NULLS_IGNORED]
10+
--innodb_stats_method=nulls_ignored
11+
--use_stat_tables=never
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--source include/have_innodb.inc
2+
--source include/have_sequence.inc
3+
4+
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
5+
f3 INT, KEY(f1, f3), key(f3)) STATS_PERSISTENT=1,ENGINE=INNODB;
6+
INSERT INTO t1 SELECT seq, seq, NULL from seq_1_to_16384;
7+
ANALYZE TABLE t1;
8+
SELECT stat_name, stat_value, stat_description
9+
FROM mysql.innodb_index_stats WHERE database_name="test" and table_name="t1";
10+
SHOW KEYS FROM t1;
11+
DROP TABLE t1;

0 commit comments

Comments
 (0)