MySQL优化

MySQL的查询中,如果使用(not in进行子查询)或者(is not null)后,会让查询速度变得很慢,笔者十分不建议使用。下面有笔者总结的代替方法。
代替  (not in 进行 子查询 ):将子查询 转变为 表连接,相关的逻辑写在 表连接 的关系上
代替  (is not null):将 is not null  的字段,使用 ifnull()替换为其他值,然后 ifnull()!=其他值,就能进行筛选了
select USER_NAME from test where USER_NAME is not null
select USER_NAME from test where (IFNULL(USER_NAME, 'kong') != 'kong') = 1

 

posted @ 2021-12-15 09:41  石三爷  阅读(42)  评论(0编辑  收藏  举报