pingcap / pingcap/tidb

lazily replaying prepared statements for session manager

Open
#35,806 0 comments 0 reactions 1 assignee Claimed by @djshow832 View on GitHub
sig/sql-infra type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

Currently, we replay prepared statements as soon as `set session_states` executes. However, it may fail in some cases.
For example, in session A:
1. create table `t1`.
2. prepare a statement `stmt` from `select * from t1`.
3. drop the table `t1`.
Then migrate the session from A to B:
1. session B tries to replay the `PREPARE` statement, but it fails because table `t1` doesn't exist.
2. The session cannot be migrated because of the failure, and the client is disconnected.

However, there are 2 cases where the client doesn't need to be disconnected:
- the prepared statement `stmt` won't be executed anymore, because the user doesn't want it anymore.
- the session will recreate the table `t1` later, and then the `stmt` can be executed.

Except for dropping tables, there are other cases where this could happen:
- alter the table.
- drop the current db where the statement is prepared.
- update the privilege of the user after the statement is prepared.
- update the `sql_mode` after the statement is prepared.

So if replaying the prepared statement fails, we can save the encoded prepared statement and replay it when it is executed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.