Oracle hints你需要知道的

oracle表连接的三种关联机制

a.嵌套循环:NL。用一张表的每一条数据取和另一张表的每条数据进行关联
b.哈希连接:hash。在内存中完成运算,匹配的是两张表共同的哈希值
c.排序合并:sort merge。两张表进行排序,然后用一张表的每一条数据取和另一张表的每条数据进行关联

你们一般用哪种关联机制

在表连接的时候,oracle中的hints优化器会自动把三种关联机制都试一遍,选择一种最优的机制给到我们,
所以我们一般选择默认的关联机制

以下连接,oracle默认用的是sort merge:cost=6 (hints优化器)

select * 
  from emp   e
  join dept  d
    on e.deptno = d.deptno

强行使用嵌套循环NL:cost=10(hints优化器)

select /*+ USE_NL(e,d)*/ * 
  from emp   e
  join dept  d
    on e.deptno = d.deptno

强行使用哈希连接hash:cost=7(hints优化器)

select /*+ USE_HASH(e,d)*/ * 
  from emp   e
  join dept  d
    on e.deptno = d.deptno

强行使用排序连接MERGE(hints优化器)

select /*+ USE_MERGE(e,d)*/ * 
  from emp_range_list   e
  join dept  d
    on e.deptno = d.deptno

并行执行parallel(抢夺资源)。一般用:4,8,16(hints优化器)

select /*+ parallel(16)*/ * 
  from emp_range_list   e
  join dept  d
    on e.deptno = d.deptno

优选选择扫描哪种表leading (oracle默认是扫描小表) (hints优化器)

select /*+ leading(e,d)*/ * 
  from emp   e
  join dept  d
on e.deptno = d.deptno

强制使用指定的索引 : /+ index(表名,索引名)/

给emp1表的deptno,sal创建组合和位图索引,在查询的时候,会使用哪个索引呢

create         index pk_emp11 on emp1(deptno, sal);   --组合索引
create  bitmap index pk_emp12 on emp1(deptno);        --位图索引


select * from emp1 where deptno = 10;  --现在走的是位图索引,cost=1


select /*+ index(e,pk_emp11)*/ * from emp1 e where deptno = 10;  --现在走的是组合索引,cost=2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值