oracle 优化
oracle 优化
1.尽量使用有索引的字段进行条件判断
2.like索引字段 尽量 使用 'XXX%',前面不要加% 加了走全表
3.使用多表查询 in 的 语句 改成使用exists not in 改成 not exists
4.不要使用 != 或者 <> 这会直接全表扫描
5.or 不要使用
select name from t where t.id = 1 or t.id=5
改成 select name from t where t.id = 1
union all select name from t where t.id = 5
6.order by 字段尽量是索引
7.字段最好不要为null,存 空字符串 或者 数字为0
8.表达式 select count(1) from table t where t.score/2 = 30 不走索引
select count(1) from table t where t.score = 30*2 走索引
9.优化难度上升 在sql语句中使用
select /*+ parallel(表别名,需要开启的线程数)*/ from table t
select /*+ parallel(t,2)*/ from table t //开启2线程
数据高于百万级以上的 最多开2线程 如果开4线程 导致内存爆出 会更慢 尽量不要使用 数据库压力会大