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

ヒントを配布

概要

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

構文

  • 右側テーブルの Distribute Type の指定をサポートしており、[shuffle] または [broadcast] のいずれかを指定でき、Join の右側テーブルの前に記述する必要があります。
  • 任意の数の Distribute Hints をサポートします。
  • 正しくプランを生成できない Distribute 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ヒントは、結合シャッフル方法を制御するために一般的に使用されるヒントであり、シャッフルまたはブロードキャスト配信方法を手動で指定することができます。Distributeヒントを適切に使用することで、結合シャッフル方法のオンサイトチューニングニーズに対応し、システム制御の柔軟性を高めることができます。

このページでは