SHOW GLOBAL STATUS like'Innodb_page_size';
show global variables like "%datadir%";
show global variables like '%innodb_file_per_table%';
show global variables like '%tmp_table_size%';
create table t1 (
a int primary key,
b int,
c int,
d int,
e varchar(20)
) engine=InnoDB;
insert into t1 values(4,3,1,1,'d');
insert into t1 values(1,1,1,1,'a');
insert into t1 values(8,8,8,8,'h');
insert into t1 values(2,2,2,2,'b');
insert into t1 values(5,2,3,5,'e');
insert into t1 values(3,3,2,2,'c');
insert into t1 values(7,4,5,5,'g');
insert into t1 values(6,6,4,4,'f');
EXPLAIN select * from t1 where a=1;
create INDEX idx_t1_bcd on t1(b,c,d);
create INDEX idx_t1_b on t1(b);
create INDEX idx_t1_c on t1(c);
EXPLAIN select * from t1 where b=1;
EXPLAIN select * from t1 where b=1 and c=1;
EXPLAIN select * from t1 where c=1;
EXPLAIN select * from t1 where b=1 or c=1;
EXPLAIN SELECT * FROM t1 WHERE b=1
UNION ALL
SELECT * FROM t1 WHERE c=1;
index 类型虽然需要扫描整个索引,但通常比 ALL 全表扫描要快,因为索引文件通常比数据文件小。
理想情况下,应尽量让查询的 type 至少达到 range 级别,最好能达到 ref
https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html