Skip to content

Commit

Permalink
planner: add explanation about force_index and force index (#8625)
Browse files Browse the repository at this point in the history
  • Loading branch information
time-and-fate authored Mar 18, 2022
1 parent fead57a commit 8514416
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion choose-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ mysql> SHOW WARNINGS;

通过 [Optimizer Hints](/optimizer-hints.md) 可以实现单条查询对索引选择的控制。

- `USE_INDEX`/`IGNORE_INDEX` 可以强制优化器使用/不使用某些索引。
- `USE_INDEX`/`IGNORE_INDEX` 可以强制优化器使用/不使用某些索引。`FORCE_INDEX``USE_INDEX` 的作用相同。

- `READ_FROM_STORAGE` 可以强制优化器对于某些表选择 TiKV/TiFlash 的存储引擎进行查询。
17 changes: 17 additions & 0 deletions optimizer-hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ SELECT /*+ USE_INDEX(t1, idx1, idx2) */ * FROM t1;
>
> 当该 Hint 中只指定表名,不指定索引名时,表示不考虑使用任何索引,而是选择全表扫。
### FORCE_INDEX(t1_name, idx1_name [, idx2_name ...])

`FORCE_INDEX(t1_name, idx1_name [, idx2_name ...])` 提示优化器对指定表仅使用给出的索引。

`FORCE_INDEX(t1_name, idx1_name [, idx2_name ...])` 的使用方法、作用和 `USE_INDEX(t1_name, idx1_name [, idx2_name ...])` 相同。

以下四个查询语句的效果相同:

{{< copyable "sql" >}}

```sql
SELECT /*+ USE_INDEX(t, idx1) */ * FROM t;
SELECT /*+ FORCE_INDEX(t, idx1) */ * FROM t;
SELECT * FROM t use index(idx1);
SELECT * FROM t force index(idx1);
```

### IGNORE_INDEX(t1_name, idx1_name [, idx2_name ...])

`IGNORE_INDEX(t1_name, idx1_name [, idx2_name ...])` 提示优化器对指定表忽略给出的索引。
Expand Down

0 comments on commit 8514416

Please sign in to comment.