Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update documents related to Plan Cache #9553

Merged
merged 24 commits into from
May 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Aolin <aolinz@outlook.com>
ran-huang and Oreoxmt authored May 26, 2022
commit 4f245addacf83c644299eea1299abfdb33b2e7cd
2 changes: 1 addition & 1 deletion sql-prepared-plan-cache.md
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ key 中任何一项变动(如切换数据库,重命名 `Prepare` 语句,
- 考虑到不同 `Execute` 的参数会不同,执行计划缓存为了保证适配性会禁止一些和具体参数值密切相关的激进查询优化手段,导致对特定的一些参数值,查询计划可能不是最优。比如查询的过滤条件为 `where a > ? and a < ?`,第一次 `Execute` 时参数分别为 2 和 1,考虑到这两个参数下次执行时可能会是 1 和 2,优化器不会生成对当前参数最优的 `TableDual` 执行计划。
- 如果不考虑缓存失效和淘汰,一份执行计划缓存会对应各种不同的参数取值,理论上也会导致某些取值下执行计划非最优。比如查询过滤条件为 `where a < ?`,假如第一次执行 `Execute` 时用的参数值为 1,此时优化器生成最优的 `IndexScan` 执行计划放入缓存,在后续执行 `Exeucte` 时参数变为 10000,此时 `TableScan` 可能才是更优执行计划,但由于执行计划缓存,执行时还是会使用先前生成的 `IndexScan`。因此执行计划缓存更适用于查询较为简单(查询编译耗时占比较高)且执行计划较为固定的业务场景。

目前执行计划缓存功能默认打开,可以通过变量 `tidb_enable_prepared_plan_cache` 启用或关闭这项功能。
目前执行计划缓存功能默认打开,可以通过变量 [`tidb_enable_prepared_plan_cache`](/system-variables.md#tidb_enable_prepared_plan_cache-从-v610-版本开始引入) 启用或关闭这项功能。

> **注意:**
>
1 change: 0 additions & 1 deletion system-variables.md
Original file line number Diff line number Diff line change
@@ -1474,7 +1474,6 @@ explain select * from t where age=5;
- 范围:`[0, 1]`
- 这个变量用来控制是否在 profile 输出中标记出对应的 SQL 语句,用于定位和排查性能问题。


### `tidb_prepared_plan_cache_memory_guard_ratio` <span class="version-mark">从 v6.1.0 版本开始引入</span>

- 作用域:GLOBAL