lazily replaying prepared statements for session manager
- 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
Assessment
This issue has not been assessed yet.