Skip to content

fix(update): re-point hash indexes in batch in-place UPDATE fastPatch (stale-index bug) - #355

Merged
MPCoreDeveloper merged 1 commit into
release/v2.1.0.0from
fix/stale-index-v21
Sep 2, 2026
Merged

fix(update): re-point hash indexes in batch in-place UPDATE fastPatch (stale-index bug)#355
MPCoreDeveloper merged 1 commit into
release/v2.1.0.0from
fix/stale-index-v21

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

Summary

Cherry-pick of the phase-1 in-place batch-UPDATE fix (from perf/fixedwidth-backport 08bd7eb2) to the v2.1 line.

Why

Measurement (probe replicating the comparative harness UPDATE workload) showed the B7 raw-byte fastPatch in Table.UpdateMultiple ran without write-amplification (0 file growth) but left stale hash-index entries whenever the update touched an auto-indexed column (EnableHashIndexes=true indexes every column): after UPDATE docs SET score = …, a query on the new score value returned nothing and the old value still matched. That is a data-integrity bug.

What changes

  • Table.CRUD.cs fastPatch: after a successful same-length in-place write, re-point every hash index whose column the update changed (old key decoded from the pre-write row bytes, new key added at the same position). The fast path is kept.
  • Storage.Append.cs: buffer in-place overwrites payload-only (no [4+len] copy per row); extracted BufferOrWriteOverwriteInPlace; new OverwriteRecordAtSameLength skips the per-row length-prefix read when the caller guarantees same length.
  • IStorage / IStorageEngine: additive default methods OverwriteRecordAtSameLength / TryUpdateInPlaceSameLength (default routes to the verified path; AppendOnlyEngine uses the fast path).

Validation (net11)

  • Build: 0 errors.
  • 222 targeted DML / fixed-width / indexing / storage-engine tests green.
  • Probe on net10 (master line): UPDATE batch 28.3K → 33.8K ops/s, 0 file growth, and after updating an auto-indexed column the index returns the new value (0 mismatches in 1000 point-reads).

…e 1)

Measured root cause (probe): the B7 raw-byte fastPatch ran without write-amplification (0 file growth) but (a) re-read the length prefix per row and (b) left stale hash-index entries when the update touched an auto-indexed column - a latent data-integrity bug for EnableHashIndexes tables.

- Storage.Append: buffer in-place overwrites as payload-only (no [4+len] copy/row); extracted BufferOrWriteOverwriteInPlace; added OverwriteRecordAtSameLength (skips the per-row length-prefix read when the caller guarantees same length).

- IStorage/IStorageEngine: additive default methods OverwriteRecordAtSameLength / TryUpdateInPlaceSameLength (default routes to the verified path; AppendOnlyEngine uses the fast path).

- Table.UpdateMultiple fastPatch: after a same-length in-place write, re-point every hash index whose column the update changed (old key from the pre-write row, new key at the same position) - fixes the stale-index bug while keeping the fast path.

Validation: full SharpCoreDB.Tests suite 1635/1635 green; 222 targeted DML/fixed-width/indexing tests green; probe: UPDATE 28.3K -> 33.8K ops/s (0 file growth) and point-reads after updating an auto-indexed column return the new value (0 mismatches in 1000).

Note: the same stale-index fastPatch exists on release/v2.1.0.0 and should be cherry-picked there.
(cherry picked from commit 08bd7eb)
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@MPCoreDeveloper
MPCoreDeveloper merged commit d433b88 into release/v2.1.0.0 Sep 2, 2026
1 of 2 checks passed
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.

1 participant