Skip to content

Commit

Permalink
optimizer-hints: add docs for nth_plan() hint (#4227)
Browse files Browse the repository at this point in the history
* optimizer-hints: add docs for `nth_plan()` hint

* optimizer-hints: add a notes for `nth_plan()`

* Update optimizer-hints.md

Co-authored-by: TomShawn <[email protected]>
  • Loading branch information
time-and-fate and TomShawn authored Aug 24, 2020
1 parent 0b48800 commit 837c2c6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions optimizer-hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,23 @@ SELECT /*+ READ_CONSISTENT_REPLICA() */ * FROM t;
```sql
prepare stmt FROM 'SELECT /*+ IGNORE_PLAN_CACHE() */ * FROM t WHERE t.id = ?';
```

### NTH_PLAN(N)

`NTH_PLAN(N)` 提示优化器选用在物理优化阶段搜索到的第 `N` 个物理计划。`N` 必须是正整数。

如果指定的 `N` 超出了物理优化阶段的搜索范围,TiDB 会返回 warning,并根据不存在该 Hint 时一样的策略选择最优物理计划。

该 Hint 在启用 cascades planner 的情况下不会生效。

以下示例会强制优化器在物理阶段选择搜索到的第 3 个物理计划:

{{< copyable "sql" >}}

```sql
SELECT /*+ NTH_PLAN(3) */ count(*) from t where a > 5;
```

> **注意:**
>
> `NTH_PLAN(N)` 主要用于测试用途,并且在未来不保证其兼容性,请谨慎使用。

0 comments on commit 837c2c6

Please sign in to comment.