メインコンテンツまでスキップ
バージョン: 2.1

配布のヒント

概要

Distributeヒントは、結合のシャッフル方式を制御するために使用されます。

構文

  • 右TableのDistribute Typeの指定をサポートしており、[shuffle]または[broadcast]のいずれかを指定でき、Joinの右Tableの前に記述する必要があります。
  • 任意の数のDistributeヒントをサポートします。
  • 正しくプランを生成できないDistributeヒントに遭遇した場合、システムはエラーを表示しません。ヒントを適用するため最善の努力を行い、最終的なDistribute方式はEXPLAIN出力に表示されます。

Orderedヒントとの組み合わせでの使用

結合順序をテキストの順序に固定し、その後結合に期待されるDistribute方式を指定します。例:

使用前:

mysql> explain shape plan select count(*) from t1 join t2 on t1.c1 = t2.c2;
+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner) |
+----------------------------------------------------------------------------------+
| PhysicalResultSink |
| --hashAgg[GLOBAL] |
| ----PhysicalDistribute[DistributionSpecGather] |
| ------hashAgg[LOCAL] |
| --------PhysicalProject |
| ----------hashJoin[INNER_JOIN] hashCondition=((t1.c1 = t2.c2)) otherCondition=() |
| ------------PhysicalProject |
| --------------PhysicalOlapScan[t1] |
| ------------PhysicalDistribute[DistributionSpecHash] |
| --------------PhysicalProject |
| ----------------PhysicalOlapScan[t2] |
+----------------------------------------------------------------------------------+

使用後:

mysql> explain shape plan select /*+ ordered */ count(*) from t2 join[broadcast] t1 on t1.c1 = t2.c2;
+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner) |
+----------------------------------------------------------------------------------+
| PhysicalResultSink |
| --hashAgg[GLOBAL] |
| ----PhysicalDistribute[DistributionSpecGather] |
| ------hashAgg[LOCAL] |
| --------PhysicalProject |
| ----------hashJoin[INNER_JOIN] hashCondition=((t1.c1 = t2.c2)) otherCondition=() |
| ------------PhysicalProject |
| --------------PhysicalOlapScan[t2] |
| ------------PhysicalDistribute[DistributionSpecReplicated] |
| --------------PhysicalProject |
| ----------------PhysicalOlapScan[t1] |
| |
| Hint log: |
| Used: ORDERED |
| UnUsed: |
| SyntaxError: |
+----------------------------------------------------------------------------------+

Explain Shape PlanはDistributeオペレータに関する情報を表示します。具体的には:

  • DistributionSpecReplicatedは、対応するデータが全てのBEノードに複製されることを示します。
  • DistributionSpecGatherは、データがFEノードに収集されることを示します。
  • DistributionSpecHashは、特定のhashKeyとアルゴリズムに基づいて、データが異なるBEノードに分散されることを示します。

Leading Hintとの組み合わせでの使用

SQLクエリを記述する際、LEADINGヒントを使用しながら、各JOIN操作に対して対応するDISTRIBUTEメソッドを指定することができます。以下は、SQLクエリにおいてDistribute HintLeading Hintを混在させる方法を示す具体的な例です。

explain shape plan
select
nation,
o_year,
sum(amount) as sum_profit
from
(
select
/*+ leading(orders shuffle {lineitem shuffle part} shuffle {supplier broadcast nation} shuffle partsupp) */
n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from
part,
supplier,
lineitem,
partsupp,
orders,
nation
where
s_suppkey = l_suppkey
and ps_suppkey = l_suppkey
and ps_partkey = l_partkey
and p_partkey = l_partkey
and o_orderkey = l_orderkey
and s_nationkey = n_nationkey
and p_name like '%green%'
) as profit
group by
nation,
o_year
order by
nation,
o_year desc;

概要

Distributeヒントは、結合シャッフル方法を制御するための一般的に使用されるヒントで、シャッフルまたはブロードキャスト配信方法の手動指定を可能にします。Distributeヒントの適切な使用により、結合シャッフル方法の現場チューニングニーズを満たすことができ、システム制御の柔軟性が向上します。

このページでは