mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-7317: Make an index ignorable to the optimizer
This feature adds the functionality of ignorability for indexes. Indexes are not ignored be default. To control index ignorability explicitly for a new index, use IGNORE or NOT IGNORE as part of the index definition for CREATE TABLE, CREATE INDEX, or ALTER TABLE. Primary keys (explicit or implicit) cannot be made ignorable. The table INFORMATION_SCHEMA.STATISTICS get a new column named IGNORED that would store whether an index needs to be ignored or not.
This commit is contained in:
@ -40,16 +40,16 @@ optimize table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 0 PRIMARY 1 a A 5 NULL NULL BTREE
|
||||
t1 1 b 1 b A 1 NULL NULL BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 0 PRIMARY 1 a A 5 NULL NULL BTREE NO
|
||||
t1 1 b 1 b A 1 NULL NULL BTREE NO
|
||||
optimize table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status Table is already up to date
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 0 PRIMARY 1 a A 5 NULL NULL BTREE
|
||||
t1 1 b 1 b A 1 NULL NULL BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 0 PRIMARY 1 a A 5 NULL NULL BTREE NO
|
||||
t1 1 b 1 b A 1 NULL NULL BTREE NO
|
||||
drop table t1;
|
||||
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=myisam;
|
||||
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
|
||||
@ -339,13 +339,13 @@ optimize table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 b 1 b A 5 NULL NULL YES BTREE
|
||||
t1 1 c 1 c A 5 NULL NULL YES BTREE
|
||||
t1 1 a 1 a A 1 NULL NULL BTREE
|
||||
t1 1 a 2 b A 5 NULL NULL YES BTREE
|
||||
t1 1 c_2 1 c A 5 NULL NULL YES BTREE
|
||||
t1 1 c_2 2 a A 5 NULL NULL BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 b 1 b A 5 NULL NULL YES BTREE NO
|
||||
t1 1 c 1 c A 5 NULL NULL YES BTREE NO
|
||||
t1 1 a 1 a A 1 NULL NULL BTREE NO
|
||||
t1 1 a 2 b A 5 NULL NULL YES BTREE NO
|
||||
t1 1 c_2 1 c A 5 NULL NULL YES BTREE NO
|
||||
t1 1 c_2 2 a A 5 NULL NULL BTREE NO
|
||||
explain select * from t1,t2 where t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL a NULL NULL NULL 2
|
||||
@ -363,13 +363,13 @@ optimize table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 b 1 b A 10 NULL NULL YES BTREE
|
||||
t1 1 c 1 c A 10 NULL NULL YES BTREE
|
||||
t1 1 a 1 a A 10 NULL NULL BTREE
|
||||
t1 1 a 2 b A 10 NULL NULL YES BTREE
|
||||
t1 1 c_2 1 c A 10 NULL NULL YES BTREE
|
||||
t1 1 c_2 2 a A 10 NULL NULL BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 b 1 b A 10 NULL NULL YES BTREE NO
|
||||
t1 1 c 1 c A 10 NULL NULL YES BTREE NO
|
||||
t1 1 a 1 a A 10 NULL NULL BTREE NO
|
||||
t1 1 a 2 b A 10 NULL NULL YES BTREE NO
|
||||
t1 1 c_2 1 c A 10 NULL NULL YES BTREE NO
|
||||
t1 1 c_2 2 a A 10 NULL NULL BTREE NO
|
||||
explain select * from t1,t2 where t1.b=t2.b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL b NULL NULL NULL 2 Using where
|
||||
@ -379,13 +379,13 @@ optimize table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 b 1 b A 5 NULL NULL YES BTREE
|
||||
t1 1 c 1 c A 5 NULL NULL YES BTREE
|
||||
t1 1 a 1 a A 1 NULL NULL BTREE
|
||||
t1 1 a 2 b A 5 NULL NULL YES BTREE
|
||||
t1 1 c_2 1 c A 5 NULL NULL YES BTREE
|
||||
t1 1 c_2 2 a A 5 NULL NULL BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 b 1 b A 5 NULL NULL YES BTREE NO
|
||||
t1 1 c 1 c A 5 NULL NULL YES BTREE NO
|
||||
t1 1 a 1 a A 1 NULL NULL BTREE NO
|
||||
t1 1 a 2 b A 5 NULL NULL YES BTREE NO
|
||||
t1 1 c_2 1 c A 5 NULL NULL YES BTREE NO
|
||||
t1 1 c_2 2 a A 5 NULL NULL BTREE NO
|
||||
explain select * from t1,t2 force index(c) where t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
||||
@ -613,29 +613,29 @@ test.t1 2924214226
|
||||
drop table t1,t2;
|
||||
create table t1 (a int, key (a));
|
||||
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
|
||||
t1 1 a 1 a A NULL NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A NULL NULL NULL YES BTREE NO
|
||||
alter table t1 disable keys;
|
||||
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
|
||||
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled NO
|
||||
create table t2 (a int);
|
||||
set @@rand_seed1=31415926,@@rand_seed2=2718281828;
|
||||
insert t1 select * from t2;
|
||||
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
|
||||
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled NO
|
||||
alter table t1 enable keys;
|
||||
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
|
||||
t1 1 a 1 a A 1000 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 1000 NULL NULL YES BTREE NO
|
||||
alter table t1 engine=heap;
|
||||
alter table t1 disable keys;
|
||||
Warnings:
|
||||
Note 1031 Storage engine MEMORY of the table `test`.`t1` doesn't have this option
|
||||
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
|
||||
t1 1 a 1 a NULL 500 NULL NULL YES HASH
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a NULL 500 NULL NULL YES HASH NO
|
||||
drop table t1,t2;
|
||||
create table t1 ( a tinytext, b char(1), index idx (a(1),b) );
|
||||
insert into t1 values (null,''), (null,'');
|
||||
@ -679,16 +679,16 @@ Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE NO
|
||||
insert into t1 values (11);
|
||||
delete from t1 where a=11;
|
||||
check table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE NO
|
||||
set myisam_stats_method=nulls_equal;
|
||||
set @save_use_stat_tables = @@use_stat_tables;
|
||||
set @@use_stat_tables = COMPLEMENTARY;
|
||||
@ -702,16 +702,16 @@ Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 5 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 5 NULL NULL YES BTREE NO
|
||||
insert into t1 values (11);
|
||||
delete from t1 where a=11;
|
||||
check table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 5 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 5 NULL NULL YES BTREE NO
|
||||
set @@use_stat_tables = @save_use_stat_tables;
|
||||
set myisam_stats_method=DEFAULT;
|
||||
show variables like 'myisam_stats_method';
|
||||
@ -724,16 +724,16 @@ Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE NO
|
||||
insert into t1 values (11);
|
||||
delete from t1 where a=11;
|
||||
check table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 10 NULL NULL YES BTREE NO
|
||||
drop table t1;
|
||||
set myisam_stats_method=nulls_ignored;
|
||||
show variables like 'myisam_stats_method';
|
||||
@ -754,22 +754,22 @@ Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 2 NULL NULL YES BTREE
|
||||
t1 1 a 2 b A 4 NULL NULL YES BTREE
|
||||
t1 1 a 3 c A 4 NULL NULL YES BTREE
|
||||
t1 1 a 4 d A 4 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 2 NULL NULL YES BTREE NO
|
||||
t1 1 a 2 b A 4 NULL NULL YES BTREE NO
|
||||
t1 1 a 3 c A 4 NULL NULL YES BTREE NO
|
||||
t1 1 a 4 d A 4 NULL NULL YES BTREE NO
|
||||
delete from t1;
|
||||
analyze table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||
t1 1 a 1 a A 0 NULL NULL YES BTREE
|
||||
t1 1 a 2 b A 0 NULL NULL YES BTREE
|
||||
t1 1 a 3 c A 0 NULL NULL YES BTREE
|
||||
t1 1 a 4 d A 0 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 0 NULL NULL YES BTREE NO
|
||||
t1 1 a 2 b A 0 NULL NULL YES BTREE NO
|
||||
t1 1 a 3 c A 0 NULL NULL YES BTREE NO
|
||||
t1 1 a 4 d A 0 NULL NULL YES BTREE NO
|
||||
set myisam_stats_method=DEFAULT;
|
||||
drop table t1;
|
||||
set @@use_stat_tables = @save_use_stat_tables;
|
||||
@ -1815,13 +1815,13 @@ Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
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
|
||||
t1 1 a 1 a A 8 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 8 NULL NULL YES BTREE NO
|
||||
alter table t1 disable keys;
|
||||
alter table t1 enable keys;
|
||||
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
|
||||
t1 1 a 1 a A 8 NULL NULL YES BTREE
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
||||
t1 1 a 1 a A 8 NULL NULL YES BTREE NO
|
||||
drop table t1;
|
||||
create table t1 (c1 int) engine=myisam pack_keys=0;
|
||||
create table t2 (c1 int) engine=myisam pack_keys=1;
|
||||
|
Reference in New Issue
Block a user