Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据表通用字段 delete_time 导致的性能问题 #166

Closed
colorful3 opened this issue Jul 6, 2021 · 1 comment
Closed

数据表通用字段 delete_time 导致的性能问题 #166

colorful3 opened this issue Jul 6, 2021 · 1 comment
Labels
⚡Performance performance issue

Comments

@colorful3
Copy link
Member

对于数据的软删除,Lin CMS是通过delete_time字段是否为null来判断的。因此所有的查询语句,都会拼接上一个 where 条件delete_time is null。这种做法会引发很诸多性能问题:
因为delete_time默认值为null,可以为 null ,会导致查询效率大打折扣,explain会走全表扫描:
image

推荐增加 is_deleted 字段来做删除标识,这种是比较常用的逻辑删除做法,查询性能上至少比现在的做法要好:

is_deleted int(1)  NOT NULL DEFAULT 0 COMMENT '0:正常 1:已删除'

参考链接:
性能优化案例分析之一:软删除是慢查询的罪魁祸首?
小心 MySQL Soft Delete
为什么 MySQL 不推荐默认值为 null ?

@sunlin92 sunlin92 added the ⚡Performance performance issue label Jul 7, 2021
@colorful3
Copy link
Member Author

该问题可参考 Lin CMS Spring Boot 的issue 展开探讨下:
TaleLin/lin-cms-spring-boot#235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡Performance performance issue
Projects
None yet
Development

No branches or pull requests

2 participants