GaussDB-指定子查询不展开的Hint

31 阅读1分钟

GaussDB-指定子查询不展开的Hint

功能描述

数据库在对查询进行逻辑优化时通常会将可以提升的子查询提升到上层来避免嵌套执行,但对于某些本身选择率较低且可以使用索引过滤访问页面的子查询,嵌套执行不会导致性能下降过多,而提升之后扩大了查询路径的搜索范围,可能导致性能变差。对于此类情况,可以使用no_expand hint进行调试。大多数情况下不建议使用此hint。

语法格式

| ``` no_expand[(@queryblock)]

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

#### 参数说明

[(@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_expand没有括号"()"。

#### 示例

正常的查询执行:

| ```
explain select * from t1 where t1.c1 in (select t2.c1 from t2); 
``` |
| ------------------------------------------------------------------------ |

计划:

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

加入no_expand:

| ```
explain select * from t1 where t1.c1 in (select /*+ no_expand*/ t2.c1 from t2); 
``` |
| ---------------------------------------------------------------------------------------- |

计划:

![](https://p9-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/56e0719ee1e54048a3e4ffed615ba515~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgamVycnl3YW5nMTk4Mw==:q75.awebp?rk3s=f64ab15b&x-expires=1773214603&x-signature=%2BQfTvjfjjliirWtck%2FeppjCgCbs%3D)

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