MapJoin は、大きなテーブルと 1 つまたは複数の小さなテーブルを結合するのに役立ちます。通常の結合操作よりも高速です。

MapJoin の典型的なシナリオは次のとおりです。データ量が少ない場合、SQL は結合操作を実行するプログラムのメモリに、指定されたすべての小さいテーブルをロードして、JOIN 実行を高速化します。
MapJoin を使用するときは、以下にご注意ください。
  • 「左外部結合」の左側のテーブルは大きなテーブルである必要があります。
  • 右外部結合の右表は大きな表でなければなりません。
  • INNER JOIN では、左右両方のテーブルを大きなテーブルにすることができます。
  • FULL OUTER JOIN の場合、MapJoin は使用できません。
  • MapJoin は小さなテーブルをサブクエリとしてサポートします。
  • MapJoin が使用されていて、小さなテーブルまたはサブクエリを参照する必要がある場合は、エイリアスを参照する必要があります。
  • MapJoin は、等価でない JOIN 条件、または OR を使用して接続された複数の条件をサポートしています。
  • 現在、MaxCompute では、最大 8 つの小さなテーブルを MapJoin で指定できます。 それ以外の場合は、エラーが返されます。
  • MapJoin が使用される場合、すべての小さなテーブルによって占有される合計メモリは 512 MB を超えることはできません。 MaxCompute は圧縮ストレージを使用するため、小さなテーブルがメモリにロードされるとデータサイズは急激に拡大します。 512 MB の制限は、小さなテーブルがメモリにロードされた後のサイズを表します。 We can config the total memory by SET odps.sql.mapjoin.memory.max=2048; . The maximum configurable memory is 2048MB.
  • When JOIN is performed on the multiple tables, the two leftmost tables cannot be tables for MapJoin at the same time.
例:
select /* + mapjoin(a) */
        a.shop_name,
        b.customer_id,
        b.total_price
    from shop a join sale_detail b
    on a.shop_name = b.shop_name;

MaxCompute SQL does not support complex JOIN conditions, such as non-equivalent expressions and the OR logic, in the ON condition of common JOIN operations. However, MapJoin supports such operations.

例:
select /*+ mapjoin(a) */
        a.total_price,
        b.total_price
    from shop a join sale_detail b
    on a.total_price < b.total_price or a.total_price + b.total_price < 500;