メインコンテンツまでスキップ

ヒントを配布する

概要

Distribute hintはJoinのshuffle方法を制御するために使用されます。

構文

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

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

Join順序をテキストの順序に固定し、その後Joinに期待する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ヒントは、join shuffleメソッドを制御するために一般的に使用されるヒントで、shuffleまたはbroadcast distributionメソッドを手動で指定することができます。Distributeヒントを適切に使用することで、join shuffleメソッドの現場でのチューニングニーズを満たし、システム制御の柔軟性を高めることができます。