Skip to content

Commit

Permalink
Merge #35618
Browse files Browse the repository at this point in the history
35618: sql: Use current hlc time to check if AS OF SYSTEM TIME is in the future r=vivekmenezes a=vivekmenezes

stop usng the statement timestamp which is computed using the
physical time as the current time. The physical time can
at times jump backwards.

fixes #35155

Release note: None

Co-authored-by: Vivek Menezes <[email protected]>
  • Loading branch information
craig[bot] and vivekmenezes committed Mar 12, 2019
2 parents e34c9b5 + f9d734b commit 6a9c978
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 9 additions & 1 deletion pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,15 @@ func checkResultType(typ types.T) error {
// EvalAsOfTimestamp evaluates and returns the timestamp from an AS OF SYSTEM
// TIME clause.
func (p *planner) EvalAsOfTimestamp(asOf tree.AsOfClause) (_ hlc.Timestamp, err error) {
return tree.EvalAsOfTimestamp(asOf, &p.semaCtx, p.EvalContext())
ts, err := tree.EvalAsOfTimestamp(asOf, &p.semaCtx, p.EvalContext())
if err != nil {
return hlc.Timestamp{}, err
}
if now := p.execCfg.Clock.Now(); now.Less(ts) {
return hlc.Timestamp{}, errors.Errorf(
"AS OF SYSTEM TIME: cannot specify timestamp in the future (%s > %s)", ts, now)
}
return ts, nil
}

// ParseHLC parses a string representation of an `hlc.Timestamp`.
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/sem/tree/as_of.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ func EvalAsOfTimestamp(
return ts, errors.Errorf("AS OF SYSTEM TIME: zero timestamp is invalid")
} else if ts.Less(zero) {
return ts, errors.Errorf("AS OF SYSTEM TIME: timestamp before 1970-01-01T00:00:00Z is invalid")
} else if stmtTimestamp.Before(ts.GoTime()) {
return ts, errors.Errorf("AS OF SYSTEM TIME: cannot specify timestamp in the future (%s > %s)",
ts.GoTime(), stmtTimestamp)
}
return ts, nil
}
Expand Down

0 comments on commit 6a9c978

Please sign in to comment.