首页 > Linux操作系统 > Linux操作系统 > (ZT) 修改表连接顺序的hint

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

原创 Linux操作系统 作者:zergduan 时间:2009-03-11 16:57:59 0 删除 编辑

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 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:

FROM    tab1, tab2, tab3, tab4
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_hash(t2) swap_join_inputs(t2)

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博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

上一篇: 组合索引顺序
请登录后发表评论 登录


  • 博文量
  • 访问量