GaussDB-Join方式的Hint

75 阅读1分钟

GaussDB-Join方式的Hint

功能描述

指明Join使用的方法,可以为Nested Loop、Hash Join和Merge Join。

语法格式

| ``` [no] nestloop|hashjoin|mergejoin([@queryblock] table_list)

| ------------------------------------------------------------------- |

#### 参数说明

-   @queryblock请参见[指定Hint所处的查询块Queryblock](https://doc.hcs.huawei.com/db/zh-cn/gaussdbqlh/24.1.30/devg-dist/gaussdb-12-0272.html#ZH-CN_TOPIC_0000001911585745)章节,可省略,表示在当前查询块生效。
-   no表示hint的join方式不使用。

<!---->

-   table_list为表示hint表集合的字符串,该字符串中的表与[join_table_list](https://doc.hcs.huawei.com/db/zh-cn/gaussdbqlh/24.1.30/devg-dist/gaussdb-12-0274.html#ZH-CN_TOPIC_0000001911667077__zh-cn_topic_0000001704538597_section1280444714345)相同,只是中间不允许出现括号指定join的优先级。

例如:

no nestloop(t1 t2 t3)表示:生成t1、t2、t3三表连接计划时,不使用nestloop。三表连接计划可能是t2,t3先join,再跟t1join,或t1,t2先join,再跟t3join。此hint只hint最后一次join的join方式,对于两表连接的方法不hint。如果需要,可以单独指定,例如:任意表均不允许nestloop连接,且希望t2,t3先join,则增加hint:no nestloop(t2 t3)。

#### 示例

对[示例](https://doc.hcs.huawei.com/db/zh-cn/gaussdbqlh/24.1.30/devg-dist/gaussdb-12-0271.html#ZH-CN_TOPIC_0000001911666285__zh-cn_topic_0000001656058848_section671421102912)中原语句使用如下hint:

| ```
explain select /*+ nestloop(store_sales store_returns item) */ i_product_name product_name ... 
``` |
| ------------------------------------------------------------------------------------------------------- |

该hint表示:生成store_sales、store_returns和item三表的结果集时,最后的两表关联使用nestloop。生成计划如下所示:

![](https://p3-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/b5997161da054d778d2c4789b67ba0ba~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgamVycnl3YW5nMTk4Mw==:q75.awebp?rk3s=f64ab15b&x-expires=1772002599&x-signature=0TYIO99EomPm98n5KnHvKCdEAwU%3D)

更多详情请参考GaussDB 文档中心:<https://doc.hcs.huawei.com/db/zh-cn/gaussdbqlh/24.1.30/productdesc/qlh_03_0001.html>