MysqlEXISTS代替IN写法提升效率IN语句:
SELECT * FROM order WHERE status IN (1,2,3)
EXISTS语句转换:
SELECT * FROM order a WHERE EXISTS(
SELECT * FROM (
SELECT 1  AS type UNION ALL
exists的用法SELECT 2 AS type UNION ALL
SELECT 3 AS type
) b pe
)
该代码⽤到了临时结果集的概念
SELECT * FROM (
SELECT 1  AS type UNION ALL
SELECT 2 AS type UNION ALL
SELECT 3 AS type
) b
结论:
IN肯定会⾛索引,但是当IN的取值范围较⼤时会导致索引失效,⾛全表扫描,如果使⽤了 not in,则不⾛索引

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。