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

Support sql binding takes effect immediately for query using prepared-plan-cache #28831

Closed
dbsid opened this issue Oct 14, 2021 · 1 comment
Closed
Assignees
Labels
epic/plan-cache epic/sql-plan-management sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@dbsid
Copy link
Contributor

dbsid commented Oct 14, 2021

Enhancement

With prepared plan cache enabled, when a prepared statement is submitted to tidb server, the plan cache is checked if there is an existing plan to re-use, otherwise, tidb server will compile a plan for the query. If there is sql binding for the query, the binding will be used when compiling the plan.

In real-world cases, it's no uncommon that a sub-optimal cached plan is observed for a prepared statement. To fix this issue, the DBA want to creates a sql binding to force an optimal plan, but the new sql binding will not take effect immediately. Since the existing plan in prepared plan cache will not be evicted and the new query execution keep re-using the current plan. Usually the only way to fix wrong plans issue is to rebuild the application connection.

To improve usability of the prepared plan cache and sql binding, I propose add two functions(after prepared plan cache goes GA):

  1. Add an option to invalidate all the entries in prepared plan cache for the specific query, so that the new queries request will be re-compiled, and the newly created sql binding takes effect immediately.
  2. Add a general api to invalidate a specific sql digest in prepared plan cache. In cases when the cached plan is not optimal, DBA can call this API to evict the existing plan, after re-gather the statistics or create a sql binding.
@dbsid dbsid added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Oct 14, 2021
@dbsid dbsid changed the title Support sql binding takes effect immediately when query using prepared-plan-cache Support sql binding takes effect immediately for query using prepared-plan-cache Oct 14, 2021
@Reminiscent
Copy link
Contributor

Close due to #30169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic/plan-cache epic/sql-plan-management sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants