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

专门添加一个IsDeleted(bool类型)字段, DeleteTime字段只用来记录删除时间 #158

Open
wdydxf opened this issue Apr 30, 2020 · 2 comments

Comments

@wdydxf
Copy link

wdydxf commented Apr 30, 2020

您的功能请求与现有问题有关吗?请描述

where DeleteTime is null的效率有点差, 测试了300万条数据, 关联三个表时, 非常耗时.
查阅了相关资料, 资料说尽量不用IsNull做判断.

描述您想要的解决方案

专门添加一个IsDeleted(bool类型)字段, DeleteTime字段只用来记录删除时间

描述你考虑过的替代方案

现在的方式也可以使用

附加上下文,比如截图

@gmf520
Copy link
Member

gmf520 commented Apr 30, 2020

  1. 逻辑删除涉及到唯一索引的问题,只用一个bool字段是实现不了唯一索引,因而用DateTime类型,即能表示已删除,同时也解决已删除数据的唯一索引问题
  2. 判断一个字段是否为null不应该成为性能的瓶颈吧

@xuejmnet
Copy link

确实mysql尽可能使用非null或许使用最小时间做为删除字段判断会比isnull高效譬如>1970/01/01之类的

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

No branches or pull requests

3 participants