建议7.19:用case语句合并多次表扫描
select count ( case when column1 < 1000 then 1 else null end ),
count ( case when column1 between 1000 and 5000 then 1 else null end),
count ( case when column1 > 5000 then 1 else null end)
from t_tablename;
建议7.20:慎用distinct、union、order by、group by语句,因为这些语句会引起排序,在无法消除排序的情况下尽量不要使用。
建议7.21:当使用索引产生的逻辑I/O远远大于表扫描时,应该屏蔽索引,如果字段为数值型的就在表达式后面“+ 0”,为字符型的就并上一个“空串”。
--数值型屏蔽索引
select column
from t_tablename
where column_num + 0 > 30;
--字符型屏蔽索引
select column
from t_tablename
where column_char || '' = 'ABC';