Skip to content

Fix SQLite batch unique-key handling - #1399

Merged
bgentry merged 1 commit into
masterfrom
bg/sqlite-batch-unique-nonce
Sep 28, 2026
Merged

bgentry merged 1 commit into
masterfrom
bg/sqlite-batch-unique-nonce

Conversation

@bgentry

@bgentry bgentry commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

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 InsertMany variants, conflict atomicity across all drivers, nonce format, and keys outside enforced states.

@bgentry
bgentry force-pushed the bg/sqlite-batch-unique-nonce branch 2 times, most recently from 0fe5762 to e04c84a Compare September 27, 2026 22:19

@brandur brandur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

@bgentry

bgentry commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

@brandur yeah sure that's fine, that one is approved

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
bgentry force-pushed the bg/sqlite-batch-unique-nonce branch from e04c84a to 3ccb708 Compare September 28, 2026 15:29
@bgentry
bgentry enabled auto-merge (squash) September 28, 2026 15:29
@bgentry
bgentry merged commit 9489911 into master Sep 28, 2026
15 checks passed
@bgentry
bgentry deleted the bg/sqlite-batch-unique-nonce branch September 28, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants