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

disable non-prep plan cache by default #13557

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions sql-non-prepared-plan-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ summary: Learn about the principle, usage, and examples of the SQL non-prepared

# SQL Non-Prepared Execution Plan Cache

> **Warning:**
>
> The non-prepared execution plan cache is an experimental feature. It is not recommended that you use it in the production environment. This feature might be changed or removed without prior notice. If you find a bug, you can report an [issue](https://github.com/pingcap/tidb/issues) on GitHub.

TiDB supports execution plan caching for some non-`PREPARE` statements, similar to the [`Prepare`/`Execute` statements](/sql-prepared-plan-cache.md). This feature allows these statements to skip the optimization phase and improve performance.

## Principle
Expand All @@ -20,8 +24,6 @@ The non-prepared plan cache is a session-level feature that shares a cache with

To enable or disable the non-prepared plan cache, you can set the [`tidb_enable_non_prepared_plan_cache`](/system-variables.md#tidb_enable_non_prepared_plan_cache) system variable. You can also control the size of the non-prepared plan cache using the [`tidb_session_plan_cache_size`](/system-variables.md#tidb_session_plan_cache_size-new-in-v710) system variable. When the number of cached plans exceeds `tidb_session_plan_cache_size`, TiDB evicts plans using the least recently used (LRU) strategy.

Before TiDB v7.1.0, the default value of `tidb_enable_non_prepared_plan_cache` is `OFF`, which means that the non-prepared plan cache is disabled by default. Starting from v7.1.0, the default value is `ON`, which means that the non-prepared plan cache is enabled by default.

Starting from v7.1.0, you can control the maximum size of a plan that can be cached using the system variable [`tidb_plan_cache_max_plan_size`](/system-variables.md#tidb_plan_cache_max_plan_size-new-in-v710). The default value is 2 MB. If the size of a plan exceeds this value, the plan will not be cached.

> **Note:**
Expand Down
11 changes: 9 additions & 2 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1536,15 +1536,22 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a

### tidb_enable_non_prepared_plan_cache

> **Warning:**
>
> The non-prepared execution plan cache is an experimental feature. It is not recommended that you use it in the production environment. This feature might be changed or removed without prior notice. If you find a bug, you can report an [issue](https://github.com/pingcap/tidb/issues) on GitHub.

- Scope: SESSION | GLOBAL
- Persists to cluster: Yes
- Type: Boolean
- Default value: Before v7.1.0, the default value is `OFF`. Starting from v7.1.0, the default value is `ON`.
- Default value: `OFF`
- This variable controls whether to enable the [Non-prepared plan cache](/sql-non-prepared-plan-cache.md) feature.
- When you upgrade from an earlier version to a v7.1.0 or later version, this variable remains the setting before the upgrade.

### tidb_enable_non_prepared_plan_cache_for_dml <span class="version-mark">New in v7.1.0</span>

> **Warning:**
>
> The non-prepared execution plan cache is an experimental feature. It is not recommended that you use it in the production environment. This feature might be changed or removed without prior notice. If you find a bug, you can report an [issue](https://github.com/pingcap/tidb/issues) on GitHub.

- Scope: SESSION | GLOBAL
- Persists to cluster: Yes
- Type: Boolean
Expand Down