mysql 表的设计中经常有一个字段state,假设取值在(0,1,2,3),这种情况下sql语句
sql * from bt where state=0 or state=1 在几百万的数据时,速度非常比较慢。
用UNION 效率也不高。
请问有经验的大牛们,你们遇到这种情况怎么处理呢?
sql * from bt where state=0 or state=1 在几百万的数据时,速度非常比较慢。
用UNION 效率也不高。
请问有经验的大牛们,你们遇到这种情况怎么处理呢?
select * from bt where state=0
union all
select * from bt where state=1
where state=0 由于MYSQL会认为符合条件的记录大于 30% ,MYSQL会认为没有必要走索引。
union all
select * from bt where state=1