[译] MYSQL索引最佳实践

2019-08-28  本文已影响0人  零一间

你做了一个明智的选择

MySQL 索引一览表

简述索引

索引有什么用

你可能听说过的索引类型

类BTREE索引家族

B+Tree 示例

[图片上传失败...(image-25edf6-1566955387819)]

MyISAM、Innodb索引对比

BTREE索引能用于什么操作 ?

字符索引

联合索引

索引的开销

索引成本的影响

Innodb表的索引

MySQL是如何使用索引的

使用索引进行查询

复合索引比较复杂

MySQL优化器的第一法则

所用索引进行排序

高效排序的联合索引

MySQL使用索引排序的规则

避免读取数据(只读取索引)

Min/Max的优化

联表查询中索引的使用

使用多索引

前缀索引

选择前缀长度

mysql> select count(distinct(title)) total,count(distinct(left(title,10))) p10,count(distinct(left(title,20))) p20 from title;

total p10 p20
998335 624949 960894

1 row in set (44.19 sec)

使用最多的Title mysql> select count(*) cnt, title tl from title group by tl order by cnt desc limit 3;

cnt tl
136 The Wedding
129 Lost and Found
112 Horror Marathon

3 rows in set (27.49 sec)

使用最多的Title 前缀 mysql> select count(*) cnt, left(title,20) tl from title group by tl order by cnt desc limit 3;

cnt tl
184 Wetten, dass..? aus
136 The Wedding
129 Lost and Found

3 rows in set (33.23 sec)

MySQL如何选择使用哪个索引的?

更多关于索引的选择

使用EXPLAIN

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE title range NULL production_year 5 NULL 201 Using index for group-by

1 row in set (0.01 sec)

MySQL Explain 101

索引策略

索引策略示例

Trick #1: 枚举范围

Trick #2: 添加一个假的条件

Trick #3: 虚实Filesort

原文链接

上一篇 下一篇

猜你喜欢

热点阅读