Skip to content

Commit

Permalink
Merge pull request #82654 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.1-82504

release-22.1: sql: soften AOST check to be a pgerror
  • Loading branch information
rafiss authored Jun 14, 2022
2 parents 64374c2 + 81059e7 commit 08b192b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/as_of
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ BEGIN AS OF SYSTEM TIME follower_read_timestamp(); SELECT * FROM t
statement ok
ROLLBACK

statement ok
SET enable_implicit_transaction_for_batch_statements = true

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

statement ok
RESET enable_implicit_transaction_for_batch_statements

statement ok
SET DEFAULT_TRANSACTION_USE_FOLLOWER_READS TO TRUE

Expand Down
6 changes: 4 additions & 2 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,11 @@ func (ex *connExecutor) handleAOST(ctx context.Context, stmt tree.Statement) err
}
return errors.AssertionFailedf("expected bounded_staleness set with a max_timestamp_bound")
}
return errors.AssertionFailedf(
return pgerror.Newf(
pgcode.FeatureNotSupported,
"cannot specify AS OF SYSTEM TIME with different timestamps. expected: %s, got: %s",
p.extendedEvalCtx.AsOfSystemTime.Timestamp, asOf.Timestamp,
p.extendedEvalCtx.AsOfSystemTime.Timestamp,
asOf.Timestamp,
)
}
// If we're in an explicit txn, we allow AOST but only if it matches with
Expand Down
23 changes: 23 additions & 0 deletions pkg/sql/pgwire/testdata/pgtest/as_of_system_time
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ ReadyForQuery
{"Type":"CommandComplete","CommandTag":"SELECT 0"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# Make sure two AOSTs in the same txn errors as appropriate.
send
Parse {"Name": "parse1", "Query": "SELECT * FROM tab AS OF SYSTEM TIME '-1us'"}
Bind {"DestinationPortal": "aostportal1", "PreparedStatement": "parse1"}
Execute {"Portal": "aostportal1"}
Parse {"Name": "parse2", "Query": "SELECT * FROM tab AS OF SYSTEM TIME '-4us'"}
Bind {"DestinationPortal": "aostportal2", "PreparedStatement": "parse2"}
Execute {"Portal": "aostportal2"}
Sync
----

until
ErrorResponse
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"DataRow","Values":[{"text":"1"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ErrorResponse","Code":"0A000"}
{"Type":"ReadyForQuery","TxStatus":"I"}


# Make sure AOST is handled consistently during Bind/Execute. This also should
# not be able to see the data in the table, since this is a historical read.
send
Expand Down

0 comments on commit 08b192b

Please sign in to comment.