About hint "leading"

From link: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:30441579130547

The driving tables, the first tables accessed.

when you join t1 to t2 to t3 to t4 we could go

t3 -> t4 -> t2 -> t1
t1 -> t2 -> t3 -> t4
t4 -> t3 -> t2 -> t1

and so on -- leading says "use this table to start the join chain"


ops$tkyte@ORA9IR2> create table t1 ( x int, y int );
 
Table created.
 
ops$tkyte@ORA9IR2> create table t2 ( x int, y int );
 
Table created.
 
ops$tkyte@ORA9IR2> create table t3 ( x int, y int );
 
Table created.
 
ops$tkyte@ORA9IR2> create table t4 ( x int, y int );
 
Table created.
 
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> set autotrace traceonly explain
ops$tkyte@ORA9IR2> select /*+ leading( t3 ) */ *
  2    from t1, t2, t3, t4
  3   where t1.x = t2.y
  4     and t2.x = t3.y
  5     and t3.x = t4.y
  6  /
 
Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=11 Card=82 Bytes=8528)
   1    0   HASH JOIN (Cost=11 Card=82 Bytes=8528)
   2    1     HASH JOIN (Cost=8 Card=82 Bytes=6396)
   3    2       HASH JOIN (Cost=5 Card=82 Bytes=4264)
   4    3         TABLE ACCESS (FULL) OF 'T3' (Cost=2 Card=82 Bytes=2132)
   5    3         TABLE ACCESS (FULL) OF 'T2' (Cost=2 Card=82 Bytes=2132)
   6    2       TABLE ACCESS (FULL) OF 'T1' (Cost=2 Card=82 Bytes=2132)
   7    1     TABLE ACCESS (FULL) OF 'T4' (Cost=2 Card=82 Bytes=2132)
 
Here we said "start with t3", So Oracle is going to drive with T3, join it to T2, join
that to T1 and then join all of that with T4...
 
 
ops$tkyte@ORA9IR2> select /*+ leading( t4 ) */ *
  2    from t1, t2, t3, t4
  3   where t1.x = t2.y
  4     and t2.x = t3.y
  5     and t3.x = t4.y
  6  /
 
Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=11 Card=82 Bytes=8528)
   1    0   HASH JOIN (Cost=11 Card=82 Bytes=8528)
   2    1     HASH JOIN (Cost=8 Card=82 Bytes=6396)
   3    2       HASH JOIN (Cost=5 Card=82 Bytes=4264)
   4    3         TABLE ACCESS (FULL) OF 'T4' (Cost=2 Card=82 Bytes=2132)
   5    3         TABLE ACCESS (FULL) OF 'T3' (Cost=2 Card=82 Bytes=2132)
   6    2       TABLE ACCESS (FULL) OF 'T2' (Cost=2 Card=82 Bytes=2132)
   7    1     TABLE ACCESS (FULL) OF 'T1' (Cost=2 Card=82 Bytes=2132)
 
 
 
ops$tkyte@ORA9IR2> set autotrace off

Now we said to start with T4, and Oracle goes T4 to T3 to T2 to T1....
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值