cherry-pick 1.1: sql: ensure that AS OF SYSTEM TIME is handled consistently #20286
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #20267.
Prior to this patch, two inconsistencies were present in the code:
a user-visible inconsistency:
AS OF SYSTEM TIME
(henceforthreferred to as "AOST") was accepted anywhere in a query as soon as
it was present at the top level SELECT statement, including with
conflicting timestamps. Accepting AOST in multiple places doesn't
feel undesirable, but allowing conflicting timestamps to be
specified is unsound with the current underlying mechanism (a shared
timestamp for the entire transaction).
an internal inconsistency, visible to CockroachDB developers: the
presence of an AOST clause during planning was erroneously conflated
with the flag that disables caching of table descriptors
(
planner.avoidCachedDescriptors
). This is erroneous because,although AOST implies
avoidCachedDescriptors == true
(we can'tuse the cache while time travelling), the converse is not true: when
processing view descriptors (and perhaps, in the future, for other
reasons), we also disable descriptor caching although AOST is not
involved.
This patch rectifies this situation as follows:
a new planner flag
asOfSystemTime
is introduced to indicatethat an AOST clause was properly recognized at the top level.
the logic that allows or refuses AOST clauses in FROM clauses in
arbitrarily nested SELECT clauses (including, potentially, those
expanded from views), is modified to use this new flag.
the timestamps of AOST clauses, if multiple are specified, are
checked to be equal to the one set at the top level. This
restriction might be lifted in the future if we ever support
different AOST clauses per data source.
In addition, the error message when an AOST clause is not given in the
proper syntactic position is improved to hint where it should be
placed instead.
Release note (sql, bug fix): it is not possible any more to indicate
conflicting
AS OF SYSTEM TIME
clauses in different part of a query.cc @cockroachdb/release