Skip to content

sql: operations against the table backing sequences should be non-transactional #42780

@ajwerner

Description

@ajwerner

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:

  1. in terminal A, create sequence s then issue BEGIN; SELECT * FROM s; -- then observe the result.

  2. in terminal B, run SELECT nextval('s') a couple of times

  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sql-pgcompatSemantic compatibility with PostgreSQLA-sql-sequencesSequence handling in SQLC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions