-
Notifications
You must be signed in to change notification settings - Fork 695
planner: update doc for Instance plan cache #21017
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @qw4990, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Gemini-code-assist here, providing a summary of this pull request. This PR focuses on updating the documentation for TiDB's prepared plan cache. The primary goal is to introduce and explain the newly supported instance-level plan cache feature, differentiating it from the existing session-level cache. The changes cover how to enable and configure the instance cache, how to monitor its contents using new system tables, how to manage its memory usage, and clarifies the current capabilities of the ADMIN FLUSH PLAN_CACHE
statement regarding instance cache.
Highlights
- Introduction of Instance Plan Cache: Adds a new section explaining the concept of instance-level plan cache, which is shared across all sessions in an instance, contrasting it with the session-level cache.
- Enabling Instance Plan Cache: Documents the
tidb_enable_instance_plan_cache
system variable (introduced in v8.4.0) used to switch between session and instance plan caching. - Viewing Instance Plan Cache Contents: Introduces the
information_schema.tidb_plan_cache
andinformation_schema.cluster_tidb_plan_cache
system tables (available after v8.5.0) for inspecting entries in the instance-level plan cache, including a SQL example. - Instance Plan Cache Memory Management: Adds documentation for the
tidb_instance_plan_cache_max_size
andtidb_instance_plan_cache_reserved_percentage
system variables used to control the memory limit and purge behavior of the instance plan cache. - Clearing Plan Cache: Adds a note under the 'Clear execution plan cache' section clarifying that the
ADMIN FLUSH PLAN_CACHE
statement currently only supports clearing the session-level cache. - Platform-Specific Notes: Includes
<CustomContent>
blocks to add notes specific to TiDB and TiDB Cloud regarding potential plan cache misses due to memory limits.
Changelog
- sql-prepared-plan-cache.md
- Added a new section 'Session and Instance Level Prepared Plan Cache' starting around line 20.
- Documented the
tidb_enable_instance_plan_cache
system variable for enabling instance-level cache. - Included a SQL example demonstrating plan sharing across sessions with instance-level cache enabled.
- Introduced and provided examples for the
information_schema.tidb_plan_cache
andinformation_schema.cluster_tidb_plan_cache
system tables for viewing instance cache entries (after v8.5.0). - Added platform-specific notes about plan cache misses under the 'Plan Cache Memory Usage' section (around line 279).
- Added a new subheading 'Session Level Plan Cache Memory Management' (around line 291).
- Added a new subheading 'Instance Level Plan Cache Memory Management' (around line 316).
- Documented the
tidb_instance_plan_cache_max_size
andtidb_instance_plan_cache_reserved_percentage
system variables. - Added a note under 'Clear execution plan cache' (around line 324) about the current limitation of
ADMIN FLUSH PLAN_CACHE
for instance cache.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request provides a valuable update to the documentation for the Instance Plan Cache feature. The new sections on session vs. instance level caches, viewing cache entries, and memory management are well-structured and informative. The examples provided are clear and helpful for users to understand the functionality.
My review focuses on enhancing clarity, conciseness, and adherence to the TiDB documentation style guide. The suggestions aim to make the text even more user-friendly and precise. Overall, the changes significantly improve the documentation for this feature.
Summary of Findings
- Clarity and Phrasing: Several sentences were updated for better clarity, flow, and formality, aligning with the technical documentation style.
- Punctuation and Formatting: Minor punctuation (e.g., extra space before a period) and formatting of calculations were adjusted.
- Terminology Consistency: Ensured consistent use of terms like "clearing" plan cache.
- Tense Consistency: Adjusted verb tenses to prefer present tense for describing system behavior, as per the style guide.
Merge Readiness
The pull request is in good shape and the documentation updates are valuable. The suggested changes are minor and aim to further improve clarity and adherence to the style guide. As per the documentation style guide, I am providing these comments for consideration and not requesting changes to block the merge. I am not authorized to approve pull requests; please ensure other reviewers approve these changes before merging.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Not a big update, please help review @songrijie @Oreoxmt |
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
Co-authored-by: Aolin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we will have another doc PR when it's enabled by default and admin flush global plan_cache
is supported, right?
|
||
</CustomContent> | ||
TiDB purges the instance-level plan cache periodically. You can control the amount of memory purged each time by using the [`tidb_instance_plan_cache_reserved_percentage`](/system-variables.md#tidb_instance_plan_cache_reserved_percentage-new-in-v840) system variable. For example, if the default percentage is `0.1` and the maximum cache size is `200MiB`, TiDB purges `200 * 0.1 = 20MiB` of memory each time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this description is different from the description in the system variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<CustomContent platform="tidb"> | ||
|
||
Due to memory limits, plan cache entries might be missed. You can check this status by viewing the [`Plan Cache Miss OPS` metric](/grafana-tidb-dashboard.md) in the Grafana dashboard. | ||
|
||
</CustomContent> | ||
|
||
<CustomContent platform="tidb-cloud"> | ||
|
||
Due to memory limits, plan cache entries might be missed. | ||
|
||
</CustomContent> | ||
|
||
### Memory management of session-level plan cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this change, the tag is misplaced.
It's already wrapped in a <CustomContent platform="tidb">
tag here.
Yes, but it's the next version, not v9.0. |
@@ -17,6 +17,78 @@ When the execution plan cache is enabled, in the first execution every `Prepare` | |||
|
|||
TiDB also supports execution plan caching for some non-`PREPARE` statements, similar to the `Prepare`/`Execute` statements. For more details, refer to [Non-prepared plan cache](/sql-non-prepared-plan-cache.md). | |||
|
|||
## Session-level and instance-level Prepared Plan Cache | |||
|
|||
TiDB supports both session-level plan cache and instance-level plan cache. Session-level plan cache maintains a separate cache for each session, while instance-level plan cache maintains a single shared cache across all sessions in an instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shall recommend customers to select instances plan cache, as it caches more plans with given memory size. Otherwise, customers would ask which one should be chosen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any scenario we recommend session plan cache?
|
||
TiDB supports both session-level plan cache and instance-level plan cache. Session-level plan cache maintains a separate cache for each session, while instance-level plan cache maintains a single shared cache across all sessions in an instance. | ||
|
||
To enable or disable instance-level plan cache, you can use the [`tidb_enable_instance_plan_cache`](/system-variables.md#tidb_enable_instance_plan_cache-new-in-v840) system variable. When you set this variable to `ON`, instance-level plan cache is used. Otherwise, session-level plan cache is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial size of instance plan cache is small. We'd better mention setting proper cache size.
* `information_schema.tidb_plan_cache`: shows entries of instance plan cache in the current TiDB instance. | ||
* `information_schema.cluster_tidb_plan_cache`: shows entries of instance plan cache across all available TiDB instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we include a page to describe the view under https://docs.pingcap.com/zh/tidb/stable/information-schema/ ?
First-time contributors' checklist
What is changed, added or deleted? (Required)
Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions.
What is the related PR or file link(s)?
Do your changes match any of the following descriptions?