Is your feature request related to a problem? Please describe.
Sequences currently are backed by a table with a single row. Operations against that table are already irregular in so far as they use the KV IncrementRequest which is not exposed to SQL.
Currently operations against the backing table are transactional and can use features such as historical reads.
The sequence-as-data-source behavior should be to also skip the current kv object and read the latest mvcc value.
The same behavior exists in postgres: reads from sequences do not operate at the current txn read snapshot but instead to the latest sequence state.
Check as follows:
-
in terminal A, create sequence s then issue BEGIN; SELECT * FROM s; -- then observe the result.
-
in terminal B, run SELECT nextval('s') a couple of times
-
back in terminal A, still inside the txn, run SELECT * FROM s again. Observe: the value has changed. Reads from sequences are non-transactional.
Describe the solution you'd like
Avoid using the current transaction when accessing sequences.
Describe alternatives you've considered
To leave the behavior as is and move it to a deprecated form of sequences and to introduce a new sequence type with better semantics.
Additional context
This work is in anticipation of making sequences my efficient by side-stepping MVCC for its operations.
Jira issue: CRDB-5324
Epic CRDB-60873
Is your feature request related to a problem? Please describe.
Sequences currently are backed by a table with a single row. Operations against that table are already irregular in so far as they use the KV IncrementRequest which is not exposed to SQL.
Currently operations against the backing table are transactional and can use features such as historical reads.
The sequence-as-data-source behavior should be to also skip the current kv object and read the latest mvcc value.
The same behavior exists in postgres: reads from sequences do not operate at the current txn read snapshot but instead to the latest sequence state.
Check as follows:
in terminal A, create sequence s then issue BEGIN; SELECT * FROM s; -- then observe the result.
in terminal B, run SELECT nextval('s') a couple of times
back in terminal A, still inside the txn, run SELECT * FROM s again. Observe: the value has changed. Reads from sequences are non-transactional.
Describe the solution you'd like
Avoid using the current transaction when accessing sequences.
Describe alternatives you've considered
To leave the behavior as is and move it to a deprecated form of sequences and to introduce a new sequence type with better semantics.
Additional context
This work is in anticipation of making sequences my efficient by side-stepping MVCC for its operations.
Jira issue: CRDB-5324
Epic CRDB-60873