Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: add AsOfClause for START TRANSACTION READ ONLY statement #1215

Merged
merged 10 commits into from
May 18, 2021
7 changes: 6 additions & 1 deletion ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ const (
Year = "year"
YearWeek = "yearweek"
LastDay = "last_day"
TiDBParseTso = "tidb_parse_tso"
// TSO functions
// TiDBBoundedStaleness is used to determine the TS for a read only request with the given bounded staleness.
// It will be used in the Stale Read feature.
// For more info, please see AsOfClause.
TiDBBoundedStaleness = "tidb_bounded_staleness"
TiDBParseTso = "tidb_parse_tso"

// string functions
ASCII = "ascii"
Expand Down
6 changes: 6 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ type BeginStmt struct {
ReadOnly bool
Bound *TimestampBound
CausalConsistencyOnly bool
// AS OF is used to read the data at a specific point of time.
// Should only be used when ReadOnly is true.
AsOf *AsOfClause
}

// Restore implements Node interface.
Expand All @@ -415,6 +418,9 @@ func (n *BeginStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord(" WITH TIMESTAMP BOUND MIN READ TIMESTAMP ")
return n.Bound.Timestamp.Restore(ctx)
}
} else if n.AsOf != nil {
ctx.WriteKeyWord(" ")
return n.AsOf.Restore(ctx)
}
} else if n.CausalConsistencyOnly {
ctx.WriteKeyWord("START TRANSACTION WITH CAUSAL CONSISTENCY ONLY")
Expand Down
Loading