Skip to content

mvcc: fix autoincrement handling#5691

Draft
PThorpe92 wants to merge 8 commits intotursodatabase:mainfrom
PThorpe92:mvcc_autoinc
Draft

mvcc: fix autoincrement handling#5691
PThorpe92 wants to merge 8 commits intotursodatabase:mainfrom
PThorpe92:mvcc_autoinc

Conversation

@PThorpe92
Copy link
Collaborator

@PThorpe92 PThorpe92 commented Mar 2, 2026

Description

Addressing #5687 and adds some of the tests added in that PR.

Problem

AUTOINCREMENT in MVCC had two correctness issues:

  1. Concurrent writers could fail with WriteWriteConflict on sqlite_sequence.
  2. In mixed INSERT / UPDATE rowid / DELETE workloads, auto-assigned rowids could diverge from SQLite semantics (including monotonicity failures in fuzzed cases).

Solution

At a high level:
MVCC now treats sqlite_sequence specially for conflict/read semantics:

  • ignore row-level WW conflicts on sqlite_sequence at delete/commit time
  • when reading sqlite_sequence, prefer the visible version with the highest seq

Insert translation was tightened so sequence-row updates are stable and deterministic in MVCC:

  • MVCC uses fixed sequence-row identity strategy where appropriate
  • update path uses REQUIRE_SEEK to avoid duplicate sequence-row artifacts
  • AUTOINCREMENT allocation now uses a floor in MVCC:
    • floor = max(sqlite_sequence.seq, current table max rowid)
    • that floor is passed into NewRowid so concurrent allocation remains allocator-driven but never falls behind sequence/table state
  • Rowid-update paths no longer poison allocator state:
    • UPDATE ... SET rowid=... writes are marked and applied without bumping the allocator as if they were normal autogen inserts
  • Negative rowid edge handling in NewRowid initialization is normalized to SQLite-compatible behavior for autogen allocation.

@PThorpe92 PThorpe92 marked this pull request as draft March 2, 2026 18:55
Copy link

@turso-bot turso-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review @sivukhin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant