select ... from ... where ...group by ... having ... order by
from ... where ... select ...
(join_on) (group by_having) (distinct_union)
一. SQL语句尽量用大写,尽量不用*(整体)
oracle解析时,往往将小写得字母 转换成大写的
二. FROM表中,【小表+交叉表】放最右边
oracle从右到左顺序处理,
三. where条件中,连接条件放最左,过滤最多记录放最右边
用exists替代in
oracle从下到上处理
四. select中,避免使用distinct(1次),union,minus,order by
用 union all代替union
尽量使用decode函数(避免扫描相同记录,相同表)???
这些操作会使用非常耗费资源的sort排序功能
调整sort_area_size大小,排序使用的数据结构
decode(条件,case1,value1,case2,value2,case3,value3)
五. where替代having
having只会在检索出记录之后,聚合之后,才会进行过滤
六. 尽量不在索引列进行操作
使用索引提高查询效率,但会增加存储代价,需要定期维护
alter index indexname rebuld 表空间名
1. 不在索引使用not,or,会执行全表扫描
2. 不在索引使用函数 ||字符串拼接函数
3. 不在索引列使用is null,is not null
4. 不在索引列使用!= 索引只能告诉我们什么存在于表中
1. 使用多列索引的第一列
2. 用where代替order by
七. 用union all代替union,用union代替or(索引列适用)
对索引列使用or会造成 全表扫描