Fix SQLite batch unique-key handling - #1399
Merged
Merged
Conversation
bgentry
force-pushed
the
bg/sqlite-batch-unique-nonce
branch
2 times, most recently
from
September 27, 2026 22:19
0fe5762 to
e04c84a
Compare
brandur
reviewed
Sep 27, 2026
brandur
left a comment
Contributor
There was a problem hiding this comment.
Just since I'm pretty sure this is a clear conflict with the Yugabyte PR, do you mind if we try to merge that first since it's been outstanding for a long time?
Contributor
Author
|
@brandur yeah sure that's fine, that one is approved |
brandur
approved these changes
Sep 28, 2026
SQLite gives every job in a returning batch the same nonce. When two jobs share an active unique key, the second conflict returns the first job's nonce and both results claim insertion even though only one row exists. PostgreSQL rejects this batch. Reject repeated active unique keys before SQLite writes the batch and give each row its own 16-character nonce. This makes batch conflicts fail atomically like PostgreSQL while keeping the no-returning path free of nonce metadata. Exercise both client batch APIs and the shared driver suite, including keys outside their enforced states and per-row nonce formatting.
bgentry
force-pushed
the
bg/sqlite-batch-unique-nonce
branch
from
September 28, 2026 15:29
e04c84a to
3ccb708
Compare
bgentry
enabled auto-merge (squash)
September 28, 2026 15:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The SQLite driver currently uses one metadata nonce for every job in a returning batch. When two jobs have the same active unique key, the second conflict returns the first job with that same nonce. Both results report an insertion even though only one row exists. PostgreSQL rejects the batch and leaves no rows.
Reject repeated active unique keys before SQLite inserts the batch, matching PostgreSQL's atomic failure behavior. Give each row its own 16-character nonce so duplicate reporting remains accurate. Keep the no-returning insert path nonce-free, and allow jobs whose states fall outside the uniqueness rule to share a key.
Shared client and driver coverage exercises both
InsertManyvariants, conflict atomicity across all drivers, nonce format, and keys outside enforced states.