请问这两段条件有什么不同吗,查询效率相差好大

2019-10-09 18:55:33 +08:00
 lituancheng
条件 1:
(user_credit_change.pre_status is null and user_credit_change.after_status is null) or (user_credit_change.pre_status = 0 and user_credit_change.after_status = 30) or (user_credit_change.pre_status = 0 and user_credit_change.after_status = 41)

条件 2:
(user_credit_change.pre_status = 0 and user_credit_change.after_status = 41)

条件 1 耗时 100ms,条件 2 耗时 20 多 s,哪位大神可以解惑下,谢谢啦
4000 次点击
所在节点    MySQL
6 条回复
msaionyc
2019-10-09 18:59:27 +08:00
explain
lituancheng
2019-10-09 19:02:22 +08:00
@msaionyc explain 的结果是一样的
lituancheng
2019-10-09 19:03:16 +08:00
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE user NULL ALL NULL NULL NULL NULL 15 10.00 Using where; Using temporary; Using filesort
1 SIMPLE user_credit_apply NULL ref PRIMARY,uniq_user_status uniq_user_status 258 cashloan.user.uuid 10 50.00 Using index condition
1 SIMPLE user_credit_change NULL eq_ref uniq_start_identifier,uniq_end_identifier uniq_end_identifier 259 cashloan.user_credit_apply.request_id,const 1 5.00 Using where
1 SIMPLE user_id_card NULL eq_ref uniq_user uniq_user 134 cashloan.user_credit_apply.user_uuid,const 1 100.00 Using index condition
lituancheng
2019-10-09 19:03:30 +08:00
@lituancheng explain 结果
wangyzj
2019-10-09 19:09:48 +08:00
你这问的没法回答啊
Aresxue
2019-10-10 10:46:11 +08:00
两条 sql 都不是等价的。感觉像是 null 导致的问题,但是没有执行计划也说不准

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/607574

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX