Skip to content

Commit

Permalink
Merge pull request #97146 from rafiss/backport22.2-97063
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiss authored Feb 14, 2023
2 parents 977f27a + aa87129 commit 4ae29e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/logictestccl/testdata/logic_test/as_of
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BEGIN AS OF SYSTEM TIME follower_read_timestamp(); SELECT * FROM t
statement ok
ROLLBACK

statement error pgcode 0A000 cannot specify AS OF SYSTEM TIME with different timestamps
statement error pgcode 0A000 inconsistent AS OF SYSTEM TIME timestamp
SELECT * from t AS OF SYSTEM TIME '-1μs'; SELECT * from t AS OF SYSTEM TIME '-2μs'

statement ok
Expand Down
20 changes: 12 additions & 8 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,10 @@ func (ex *connExecutor) execStmtInOpenState(
p.stmt = stmt
p.cancelChecker.Reset(ctx)

// Auto-commit is disallowed during statement execution, if we previously executed any DDL.
// This is because may potentially create jobs and do other operations rather than
// a KV commit. Insteadand carry out any extra operations needed for DDL.he auto-connection executor will commit after this statement,
// in this scenario.
// This prevents commit during statement execution, but the connection executor,
// Auto-commit is disallowed during statement execution if we previously
// executed any DDL. This is because may potentially create jobs and do other
// operations rather than a KV commit.
// This prevents commit during statement execution, but the conn_executor
// will still commit this transaction after this statement executes.
p.autoCommit = canAutoCommit &&
!ex.server.cfg.TestingKnobs.DisableAutoCommitDuringExec && ex.extraTxnState.numDDL == 0
Expand Down Expand Up @@ -760,7 +759,10 @@ func (ex *connExecutor) handleAOST(ctx context.Context, stmt tree.Statement) err
if asOf == nil {
return nil
}
if ex.implicitTxn() {

// Implicit transactions can have multiple statements, so we need to check
// if one has already been executed.
if ex.implicitTxn() && !ex.extraTxnState.firstStmtExecuted {
if p.extendedEvalCtx.AsOfSystemTime == nil {
p.extendedEvalCtx.AsOfSystemTime = asOf
if !asOf.BoundedStaleness {
Expand Down Expand Up @@ -801,9 +803,11 @@ func (ex *connExecutor) handleAOST(ctx context.Context, stmt tree.Statement) err
)
}
if readTs := ex.state.getReadTimestamp(); asOf.Timestamp != readTs {
err = pgerror.Newf(pgcode.Syntax,
err = pgerror.Newf(pgcode.FeatureNotSupported,
"inconsistent AS OF SYSTEM TIME timestamp; expected: %s, got: %s", readTs, asOf.Timestamp)
err = errors.WithHint(err, "try SET TRANSACTION AS OF SYSTEM TIME")
if !ex.implicitTxn() {
err = errors.WithHint(err, "try SET TRANSACTION AS OF SYSTEM TIME")
}
return err
}
p.extendedEvalCtx.AsOfSystemTime = asOf
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/as_of
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@ SET TRANSACTION AS OF system time '-1s'

statement ok
ROLLBACK

# Check that AOST in multi-stmt implicit transaction has the proper error.
statement error inconsistent AS OF SYSTEM TIME timestamp
insert into t values(1); select * from t as of system time '-1s';

statement error inconsistent AS OF SYSTEM TIME timestamp
select * from t as of system time '-1s'; select * from t as of system time '-2s';

# Specifying the AOST in the first statement (and no others) is allowed.
statement ok
select * from t as of system time '-1s'; select * from t;

0 comments on commit 4ae29e1

Please sign in to comment.