更新时间:2024-04-28 GMT+08:00
分享

Plan Hint调优概述

Plan Hint为用户提供了直接影响执行计划生成的手段,用户可以通过指定join顺序,join、stream、scan方法,指定结果行数,指定重分布过程中的倾斜信息,指定配置参数的值等多个手段来进行执行计划的调优,以提升查询的性能。

功能描述

Plan Hint支持在SELECT、INSERT、UPDATE、MERGE、DELETE关键字后通过如下形式指定:

1
/*+ <plan hint> */

可以同时指定多个hint,之间使用空格分隔。hint只能hint当前层的计划,对于子查询计划的hint,需要在子查询对应的关键字后指定hint。

例如:

1
select /*+ <plan_hint1> <plan_hint2> */ * from t1, (select /*+ <plan_hint3> */ from t2) where 1=1;

其中<plan_hint1>,<plan_hint2>为外层查询的hint,<plan_hint3>为内层子查询的hint。

如果在视图定义(CREATE VIEW)时指定hint,则在该视图每次被应用时会使用该hint。

当使用random plan功能(参数plan_mode_seed不为0)时,查询指定的plan hint不会被使用。

支持范围

当前版本Plan Hint支持的范围如下,后续版本会进行增强。

  • 指定Join顺序的Hint - leading hint。
  • 指定Join方式的Hint,仅支持除semi/anti join,unique plan之外的常用hint。
  • 指定结果集行数的Hint。
  • 指定Stream方式的Hint。
  • 指定Scan方式的Hint,仅支持常用的tablescan,indexscan和indexonlyscan的hint。
  • 指定子链接块名的Hint。
  • 指定倾斜信息的Hint,仅支持Join与HashAgg的重分布过程倾斜。
  • 指定Agg重分布列Hint。仅8.1.3.100及以上集群版本支持。
  • 指定子查询不提升的Hint。仅8.2.0及以上集群版本支持。
  • 指定配置参数值的Hint,仅支持部分配置参数,详见配置参数的hint

注意事项

  • 不支持Sort、Setop和Subplan的hint。
  • 不支持SMP和Node Group场景下的Hint。
  • 不支持对INSERT语句的目标表使用Hint。

示例

本章节使用同一个语句进行示例,便于Plan Hint支持的各方法作对比,示例语句及不带hint的原计划如下所示:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
explain
select i_product_name product_name
,i_item_sk item_sk
,s_store_name store_name
,s_zip store_zip
,ad2.ca_street_number c_street_number
,ad2.ca_street_name c_street_name
,ad2.ca_city c_city
,ad2.ca_zip c_zip
,count(*) cnt
,sum(ss_wholesale_cost) s1
,sum(ss_list_price) s2
,sum(ss_coupon_amt) s3
FROM   store_sales
,store_returns
,store
,customer
,promotion
,customer_address ad2
,item
WHERE  ss_store_sk = s_store_sk AND
ss_customer_sk = c_customer_sk AND
ss_item_sk = i_item_sk and
ss_item_sk = sr_item_sk and
ss_ticket_number = sr_ticket_number and
c_current_addr_sk = ad2.ca_address_sk and
ss_promo_sk = p_promo_sk and
i_color in ('maroon','burnished','dim','steel','navajo','chocolate') and
i_current_price between 35 and 35 + 10 and
i_current_price between 35 + 1 and 35 + 15
group by i_product_name
,i_item_sk
,s_store_name
,s_zip
,ad2.ca_street_number
,ad2.ca_street_name
,ad2.ca_city
,ad2.ca_zip
;

分享:

    相关文档

    相关产品