(ZT) 修改表连接顺序的hint

Full Hinting
Filed under: Execution plans, Hints — Jonathan Lewis @ 9:17 pm UTC Jan 16,2007

This question came up some time ago on the comp.database.oracle.server newsgroup.
It’s an interesting question, and I’m not sure I know the answer.

Is there a way to tell the optimizer to precisely follow the exact plan & access
paths you want ? You can’t specify a hint to join a result set to a table, then
the result set this join will yield with another table etc., so how can you deal
with this ?
If I have:

SELECT...
FROM    tab1, tab2, tab3, tab4
WHERE
        tab1.id = tab3.id
AND     tab3.id = tab2.id
AND     tab2.id = tab4.id
AND     {filter clauses};
;

How could I force the optimizer to first join TAB1 and TAB3 with a nested loop,
then join this result to TAB2 using a hash etc etc. ??


For the general case, I’m not sure if there is always a solution; but for this
particular example, Oracle 10g makes it particularly easy to express:

/*+
        leading (t1, t3, t2, t4)
        use_nl(t3)
        use_hash(t2) swap_join_inputs(t2)
        use_nl(t4)
*/

The leading() hint allows you to specify the join order, and the use_nl(t3)
ensures we get a nested loop from t1 to t3. We then have to join to t2 because of
the leading() hint, but the  swap_join_inputs() would make t2 the build (first) table
and the intermediate result the probe (second) table in the hash join. Finally we
specify a nested loop for the join to t4. (For 9i, just change the leading() hint
to an ordered() hint, in this case - (added 20th April: and swap the order of t2
and t3 in the from clause))

But even in 10g there are probably cases where you would have  to do things like
introduce partial order through in-line views with no_merge hints, or subquery
factoring with materialize hints to get the plan you want.

Unfortunately, one of the difficulties of exercising total control is that Oracle’s
optimizer works very hard to produce “left-deep” trees; and sometimes we know that
the best plan comes from a “bushy” tree - and it can be hard to produce a legal execution
plan which generates partial results and still joins those results efficients.

Ultimately there are a few dozen hints which exist but are not documented and a few
dozen that exist but are not documented properly, and the list keeps growing - so it
can be hard to figure out exactly how to force a particular execution plan to appear;
it’s hard to know if there are even enough hints (yet) to describe every path we might want.

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/386081/viewspace-566843/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/386081/viewspace-566843/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值