Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- innodb_stats_method.result 2025-07-11 20:02:18.854016407 +0530
+++ innodb_stats_method.reject 2025-07-11 20:02:41.077627513 +0530
@@ -8,5 +8,5 @@
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
+t1 1 f3 1 f3 A 2 NULL NULL YES BTREE NO
DROP TABLE t1;
12 changes: 12 additions & 0 deletions mysql-test/suite/innodb/r/innodb_stats_method.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
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;
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/t/innodb_stats_method.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--source include/have_innodb.inc
--source include/have_sequence.inc

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;
SHOW KEYS FROM t1;
DROP TABLE t1;
12 changes: 8 additions & 4 deletions storage/innobase/dict/dict0stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1571,9 +1571,11 @@ dict_stats_analyze_index_level(
level ? 0 : index->n_core_fields,
n_uniq, &heap);

cmp_rec_rec(prev_rec, rec,
prev_rec_offsets, rec_offsets, index,
false, &matched_fields);
cmp_rec_rec(prev_rec, rec, prev_rec_offsets,
rec_offsets, index,
(srv_innodb_stats_method
> SRV_STATS_NULLS_EQUAL),
Comment on lines +1576 to +1577

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking the value of the global variable in each iteration, I think that it would be better to evaluate this condition only once and pass it in a bool parameter to the affected functions.

&matched_fields);

for (i = matched_fields; i < n_uniq; i++) {

Expand Down Expand Up @@ -1812,7 +1814,9 @@ dict_stats_scan_page(
/* check whether rec != next_rec when looking at
the first n_prefix fields */
cmp_rec_rec(rec, next_rec, offsets_rec, offsets_next_rec,
index, false, &matched_fields);
index, (srv_innodb_stats_method
> SRV_STATS_NULLS_EQUAL),
&matched_fields);

if (matched_fields < n_prefix) {
/* rec != next_rec, => rec is non-boring */
Expand Down