MySql资料 ·

MySQL不推荐使用 (is not null) 和 (not in 进行 子查询),以及它们的替代查询方法

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