Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c5c4de7

Browse files
fix mysql index
1 parent 41d9003 commit c5c4de7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎docs/database/MySQL Index.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@
1515
## 使用索引的注意事项?
1616

1717
1. 在经常需要搜索的列上,可以加快搜索的速度;
18+
1819
2. 在经常使用在WHERE子句中的列上面创建索引,加快条件的判断速度。
20+
1921
3. 在经常需要排序的列上创 建索引,因为索引已经排序,这样查询可以利用索引的排序,加快排序查询时间;
22+
2023
4. 对于中到大型表索引都是非常有效的,但是特大型表的话维护开销会很大,不适合建索引
24+
2125
5. 在经常用在连接的列上,这 些列主要是一些外键,可以加快连接的速度;
26+
2227
6. 避免 where 子句中对宇段施加函数,这会造成无法命中索引。
28+
2329
7. 在使用InnoDB时使用与业务无关的自增主键作为主键,即使用逻辑主键,而不要使用业务主键。
24-
8. 将打算加索引的列设置为 NOT NULL ,否则将导致引擎放弃使用索引而进行全表扫描
30+
31+
8. ~~将打算加索引的列设置为 NOT NULL ,否则将导致引擎放弃使用索引而进行全表扫描。~~
32+
33+
订正,来自[issue758](https://github.com/Snailclimb/JavaGuide/issues/758)**某一列设置为default null,where是可以走索引,另外 `index` 是否设置 `NULL` 是不影响性能的。**《高性能MySQL》第四章是这样说的:And, in case you’re wondering, allowing NULL values in the index really doesn’t impact performance 。NULL 值的索引查找流程参考:https://juejin.im/post/5d5defc2518825591523a1db
34+
2535
9. 删除长期未使用的索引,不用的索引的存在会造成不必要的性能损耗 MySQL 5.7 可以通过查询 sys 库的 chema_unused_indexes 视图来查询哪些索引从未被使用
36+
2637
10. 在使用 limit offset 查询缓慢时,可以借助索引来提高性能
2738

2839
## Mysql索引主要使用的两种数据结构

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /