planner: fix begin statement consumed read_ts wrongly (#25492)

This commit is contained in:
Song Gao
2021-06-17 10:48:37 +08:00
committed by GitHub
parent 74055f7f0e
commit 9e08fc559c
2 changed files with 11 additions and 1 deletions

View File

@ -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) {

View File

@ -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