perf: single-pass contiguous UPDATE for plaintext fixed-width tables - #360
Merged
Conversation
B8: Table.TryBulkUpdateContiguousFixedWidth turns a batch of strictly ascending pk=literal updates on a plaintext fixed-width columnar table into one contiguous range read + in-memory field patches + buffered same-length overwrites (no per-row pread). AppendOnly --pk measured UPDATE ~45K -> ~84K ops/s (+86%); UPDATE gap vs SQLite 5.1x -> 3.2x. Adds IStorage.HasBufferedOverwrite + IStorage.ReadBytesRange (shared cached handle) so the raw-range read can never observe stale bytes from the transaction write-behind buffer and never opens a conflicting handle inside a transaction. Fixed-size hash-indexed SET columns are re-pointed in-batch from the raw slots; variable-length indexed columns, PK writes, CHECK constraints, encrypted DBs and non-adjacent/descending keys fall back to the generic per-row loop before any write.
|
This was referenced Sep 3, 2026
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.



Summary
B8: single-pass contiguous UPDATE fast path. When a batch UPDATE (via
ExecuteBatchSQL→Table.UpdateMultiple) hits a plaintext fixed-width columnar table with strictly ascendingpk = <literal>matches whose records are physically adjacent in the data file (fixed-width ⇒ constant stride[4-byte length][FixedSize payload]), the target records are read as one contiguous byte range through the storage layer's cached file handle and patched in memory — no per-row pread.Measured (AppendOnly
--pk, default = fixed-width)Correctness & scope
NoEncryptMode) so a raw range equals the logical records;IStorage.HasBufferedOverwrite) so the range read can never see stale disk bytes;IStorage.ReadBytesRange(default null; Storage implements it over the cached read handle —ReadBytesAt's fresh per-call handle conflicted with the transaction's open handles).Table.BulkContiguousUpdateBatchesdiagnostics counter; the tests prove the path engages.Tests
Full suite 1650/1650 (+5 new
FixedWidthBulkUpdateTests): engage + durability across reopen, re-engage on a second committed batch (fresh bytes), fallback for gapped keys, fallback for hash-indexed/variable columns with index re-point correctness, fallback for non-plaintext config.Note: a pre-existing quirk surfaced while writing these tests — a large descending-order
ExecuteBatchSQLUPDATE batch silently applies nothing in the generic loop (legacy and fixed-width). Out of scope here; the fallback test uses a gapped-ascending shape instead.