Skip to content

Commit ee56bd7

Browse files
shlomi-noachdbussink
authored andcommitted
@@fast_analyze_table: make sure not to clear secondary index stats (mysql#104)
Signed-off-by: Shlomi Noach <[email protected]>
1 parent 789665d commit ee56bd7

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

mysql-test/r/fast_analyze_table.result

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
drop table if exists t0;
1+
drop table if exists t0, tleft, tright;
22
create table t0 (id int primary key);
33
show global variables like 'fast_analyze_table';
44
Variable_name Value
@@ -24,3 +24,34 @@ Table Op Msg_type Msg_text
2424
test.t0 analyze status OK
2525
set @@fast_analyze_table=0;
2626
drop table if exists t0;
27+
create table tright (id int auto_increment primary key, i int unsigned not null, sha varchar(40) not null, key i_idx (i));
28+
insert into tright values (null, floor(rand()*4294967295), sha1(rand()));
29+
insert into tright select null, floor(rand()*4294967295), sha1(rand()) from tright;
30+
insert into tright select null, floor(rand()*4294967295), sha1(rand()) from tright;
31+
select count(*) from tright;
32+
count(*)
33+
4
34+
create table tleft (id int primary key, i int unsigned, key tlefti_idx(i));
35+
insert into tleft select id, i from tright;
36+
select count(*) from tright;
37+
count(*)
38+
4
39+
analyze table tright;
40+
Table Op Msg_type Msg_text
41+
test.tright analyze status OK
42+
analyze table tleft;
43+
Table Op Msg_type Msg_text
44+
test.tleft analyze status OK
45+
set @@fast_analyze_table=1;
46+
select @@fast_analyze_table;
47+
@@fast_analyze_table
48+
1
49+
analyze table tright;
50+
Table Op Msg_type Msg_text
51+
test.tright analyze status OK
52+
explain select min(sha) from tleft straight_join tright using (i) where tleft.id between 0 and 1000000;
53+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
54+
1 SIMPLE tleft NULL index PRIMARY,tlefti_idx tlefti_idx 5 NULL 4 100.00 Using where; Using index
55+
1 SIMPLE tright NULL ref i_idx i_idx 4 test.tleft.i 1 100.00 NULL
56+
set @@fast_analyze_table=0;
57+
drop table tleft, tright;

mysql-test/t/fast_analyze_table.test

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
--source include/count_sessions.inc
66

77
--disable_warnings
8-
drop table if exists t0;
8+
drop table if exists t0, tleft, tright;
99
--enable_warnings
1010

1111
create table t0 (id int primary key);
@@ -23,3 +23,29 @@ show session variables like 'fast_analyze_table';
2323
analyze table t0;
2424
set @@fast_analyze_table=0;
2525
drop table if exists t0;
26+
27+
# Test joins
28+
29+
create table tright (id int auto_increment primary key, i int unsigned not null, sha varchar(40) not null, key i_idx (i));
30+
31+
insert into tright values (null, floor(rand()*4294967295), sha1(rand()));
32+
insert into tright select null, floor(rand()*4294967295), sha1(rand()) from tright;
33+
insert into tright select null, floor(rand()*4294967295), sha1(rand()) from tright;
34+
select count(*) from tright;
35+
36+
create table tleft (id int primary key, i int unsigned, key tlefti_idx(i));
37+
insert into tleft select id, i from tright;
38+
select count(*) from tright;
39+
40+
analyze table tright;
41+
analyze table tleft;
42+
43+
set @@fast_analyze_table=1;
44+
select @@fast_analyze_table;
45+
analyze table tright;
46+
--disable_warnings
47+
explain select min(sha) from tleft straight_join tright using (i) where tleft.id between 0 and 1000000;
48+
--enable_warnings
49+
set @@fast_analyze_table=0;
50+
51+
drop table tleft, tright;

storage/innobase/dict/dict0stats.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,9 +2048,15 @@ static dberr_t dict_stats_update_persistent(
20482048
continue;
20492049
}
20502050

2051+
if (only_clustered_index) {
2052+
// Skip analyzing secondary indexes. But also, bail out before actually clearing their
2053+
// statistics.
2054+
continue;
2055+
}
2056+
20512057
dict_stats_empty_index(index);
20522058

2053-
if (only_clustered_index || dict_stats_should_ignore_index(index)) {
2059+
if (dict_stats_should_ignore_index(index)) {
20542060
continue;
20552061
}
20562062

0 commit comments

Comments
 (0)