

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 聯結提示
<a name="join-hints"></a>

聯結提示會建議查詢執行的聯結策略。語法、引數和一些範例來自 [Apache Spark SQL 參考](https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-hints.html#join-hints)，以取得詳細資訊

### BROADCAST
<a name="broadcast-hint"></a>

建議使用 AWS Clean Rooms 廣播聯結。無論 autoBroadcastJoinThreshold 為何，都會廣播具有提示的聯結端。如果聯結的兩端都有廣播提示，則具有較小大小 （根據統計資料） 的那一側將廣播。

*別名：*BROADCASTJOIN、MAPJOIN

*參數：*資料表識別符 （選用）

*範例*：

```
-- Broadcast a specific table
SELECT /*+ BROADCAST(students) */ e.name, s.course
FROM employees e JOIN students s ON e.id = s.id;

-- Broadcast multiple tables
SELECT /*+ BROADCASTJOIN(s, d) */ *
FROM employees e
JOIN students s ON e.id = s.id
JOIN departments d ON e.dept_id = d.id;
```

### MERGE
<a name="merge-hint"></a>

建議使用 AWS Clean Rooms 隨機排序合併聯結。

*別名：*SHUFFLE\$1MERGE、MERGEJOIN

*參數：*資料表識別符 （選用）

*範例*：

```
-- Use merge join for a specific table
SELECT /*+ MERGE(employees) */ *
FROM employees e JOIN students s ON e.id = s.id;

-- Use merge join for multiple tables
SELECT /*+ MERGEJOIN(e, s, d) */ *
FROM employees e
JOIN students s ON e.id = s.id
JOIN departments d ON e.dept_id = d.id;
```

### SHUFFLE\$1HASH
<a name="shuffle-hash-hint"></a>

建議使用 AWS Clean Rooms 隨機雜湊聯結。如果兩端都有隨機雜湊提示，則查詢最佳化工具會選擇較小的端 （根據統計資料） 做為建置端。

*參數：*資料表識別符 （選用）

*範例*：

```
-- Use shuffle hash join
SELECT /*+ SHUFFLE_HASH(students) */ *
FROM employees e JOIN students s ON e.id = s.id;
```

### SHUFFLE\$1REPLICATE\$1NL
<a name="shuffle-replicate-nl-hint"></a>

建議使用 AWS Clean Rooms shuffle-and-replicate巢狀迴圈聯結。

*參數：*資料表識別符 （選用）

*範例*：

```
-- Use shuffle-replicate nested loop join
SELECT /*+ SHUFFLE_REPLICATE_NL(students) */ *
FROM employees e JOIN students s ON e.id = s.id;
```

### Spark SQL 中的提示疑難排解
<a name="join-hint-warning-cases"></a>

下表顯示未在 SparkSQL 中套用提示的常見案例。如需其他資訊，請參閱 [考量和限制](sql-commands-hints-spark.md#hints-usage-notes)。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/clean-rooms/latest/sql-reference/join-hints.html)