mysql 'OR','IN',‘union’效率分析
1、
EXPLAIN (SELECT * FROM m_news WHERE TYPES = 5 ) UNION (SELECT * FROM m_news WHERE TYPES = 10 );
2、
EXPLAIN SELECT * FROM m_news WHERE TYPES = 5 OR TYPES =10;
3、
EXPLAIN SELECT * FROM m_news WHERE TYPES IN (5,10);
结论:从影响行数来说,用'or'和‘in’ 效果是一样的,‘union’效率高很多。
转载保留链接