Skip to content

Commit b1f9e32

Browse files
committed
[docs update] 解释数据库不同删除命令快慢不同的原因
1 parent 88f36fd commit b1f9e32

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

docs/database/数据库基础知识.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,14 @@ truncate 和 drop 属于 DDL(数据定义语言)语句,操作立即生效,
132132

133133
### 执行速度不同
134134

135-
一般来说:drop>truncate>delete(这个我没有设计测试过)。
135+
一般来说:drop > truncate > delete(这个我没有设计测试过)。
136+
> `delete`命令执行的时候会产生数据库的`binlog`日志,而日志记录是需要消耗时间的,但是也有个好处方便数据回滚恢复。
137+
>
138+
> `truncate`命令执行的时候不会产生数据库日志,因此比`delete`要快。除此之外,还会把表的自增值重置和索引恢复到初始大小等。
139+
>
140+
> `drop`命令会把表占用的空间全部释放掉。
141+
>
142+
> Tips:你应该更多地关注在使用场景上,而不是执行效率。
136143
137144
## 数据库设计通常分为哪几步?
138145

0 commit comments

Comments
 (0)