*: forbid using cache when stale read in binary proto (#33818)
close pingcap/tidb#33814
This commit is contained in:
@ -1371,6 +1371,19 @@ func TestPlanCacheWithStaleReadByBinaryProto(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10"))
|
||||
}
|
||||
|
||||
stmtID2, _, _, err := se.PrepareStmt("select * from t1 where id=1")
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 2; i++ {
|
||||
rs, err := se.ExecutePreparedStmt(context.TODO(), stmtID2, nil)
|
||||
require.NoError(t, err)
|
||||
tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 100"))
|
||||
}
|
||||
tk.MustExec("set @@tx_read_ts=@a")
|
||||
rs, err := se.ExecutePreparedStmt(context.TODO(), stmtID2, nil)
|
||||
require.NoError(t, err)
|
||||
// will fail
|
||||
tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10"))
|
||||
}
|
||||
|
||||
func TestIssue30872(t *testing.T) {
|
||||
|
||||
@ -2268,9 +2268,9 @@ func (s *session) cachedPlanExec(ctx context.Context,
|
||||
// IsCachedExecOk check if we can execute using plan cached in prepared structure
|
||||
// Be careful for the short path, current precondition is ths cached plan satisfying
|
||||
// IsPointGetWithPKOrUniqueKeyByAutoCommit
|
||||
func (s *session) IsCachedExecOk(ctx context.Context, preparedStmt *plannercore.CachedPrepareStmt) (bool, error) {
|
||||
func (s *session) IsCachedExecOk(ctx context.Context, preparedStmt *plannercore.CachedPrepareStmt, isStaleness bool) (bool, error) {
|
||||
prepared := preparedStmt.PreparedAst
|
||||
if prepared.CachedPlan == nil || preparedStmt.SnapshotTSEvaluator != nil {
|
||||
if isStaleness {
|
||||
return false, nil
|
||||
}
|
||||
// check auto commit
|
||||
@ -2351,7 +2351,7 @@ func (s *session) ExecutePreparedStmt(ctx context.Context, stmtID uint32, args [
|
||||
}
|
||||
|
||||
executor.CountStmtNode(preparedStmt.PreparedAst.Stmt, s.sessionVars.InRestrictedSQL)
|
||||
ok, err = s.IsCachedExecOk(ctx, preparedStmt)
|
||||
ok, err = s.IsCachedExecOk(ctx, preparedStmt, snapshotTS != 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user