Skip to content

Commit

Permalink
parser: add AsOfClause for START TRANSACTION READ ONLY statement (#1215)
Browse files Browse the repository at this point in the history
* Add AsOfClause for START TRANSACTION READ ONLY statement

Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato authored May 18, 2021
1 parent 92d468f commit 92fa6fe
Show file tree
Hide file tree
Showing 5 changed files with 3,911 additions and 3,876 deletions.
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

0 comments on commit 92fa6fe

Please sign in to comment.