planner: fix begin statement consumed read_ts wrongly (#25492)
This commit is contained in:
@ -507,6 +507,14 @@ func (s *testStaleTxnSerialSuite) TestSetTransactionReadOnlyAsOf(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(err.Error(), Equals, "start transaction read only as of is forbidden after set transaction read only as of")
|
||||
tk.MustExec(`SET TRANSACTION READ ONLY as of timestamp '2021-04-21 00:42:12'`)
|
||||
err = tk.ExecToErr(`START TRANSACTION READ ONLY AS OF TIMESTAMP '2020-09-06 00:00:00'`)
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(err.Error(), Equals, "start transaction read only as of is forbidden after set transaction read only as of")
|
||||
|
||||
tk.MustExec("begin")
|
||||
c.Assert(tk.Se.GetSessionVars().TxnReadTS.PeakTxnReadTS(), Equals, uint64(424394603102208000))
|
||||
tk.MustExec("commit")
|
||||
tk.MustExec(`START TRANSACTION READ ONLY AS OF TIMESTAMP '2020-09-06 00:00:00'`)
|
||||
}
|
||||
|
||||
func (s *testStaleTxnSerialSuite) TestValidateReadOnlyInStalenessTransaction(c *C) {
|
||||
|
||||
@ -2447,7 +2447,7 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (Plan,
|
||||
case *ast.ShutdownStmt:
|
||||
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.ShutdownPriv, "", "", "", nil)
|
||||
case *ast.BeginStmt:
|
||||
readTS := b.ctx.GetSessionVars().TxnReadTS.UseTxnReadTS()
|
||||
readTS := b.ctx.GetSessionVars().TxnReadTS.PeakTxnReadTS()
|
||||
if raw.AsOf != nil {
|
||||
startTS, err := calculateTsExpr(b.ctx, raw.AsOf)
|
||||
if err != nil {
|
||||
@ -2456,6 +2456,8 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (Plan,
|
||||
p.StaleTxnStartTS = startTS
|
||||
} else if readTS > 0 {
|
||||
p.StaleTxnStartTS = readTS
|
||||
// consume read ts here
|
||||
b.ctx.GetSessionVars().TxnReadTS.UseTxnReadTS()
|
||||
}
|
||||
}
|
||||
return p, nil
|
||||
|
||||
Reference in New Issue
Block a user