Skip to content

fix: canonical DELETE scanner + key-only single-index delete (W1) - #371

Merged
MPCoreDeveloper merged 5 commits into
masterfrom
perf/canonical-delete-fastpath
Sep 3, 2026
Merged

fix: canonical DELETE scanner + key-only single-index delete (W1)#371
MPCoreDeveloper merged 5 commits into
masterfrom
perf/canonical-delete-fastpath

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

Stack

Inhoud

  1. fix: canonieke DELETE-scannerTryScanCanonicalDml's DELETE-tak consumente nooit de whitespace/het WHERE-keyword na de tabelnaam → elke canonieke DELETE ... WHERE col = literal viel terug op de regex-path. Gevolg: DeleteMultipleKeys + B1 (perf: key-only DELETE row decode (B1) #370) waren dead code in de benchmark-harness (verklaart waarom perf: batch tombstone writes (C4) + structured batch DELETE (B3) #369/perf: key-only DELETE row decode (B1) #370 neutraal leken). Nu routeren canonieke batch-deletes door de structured path.
  2. Diagnostiek: Database.CanonicalDeleteStatementsParsed + regressietest CanonicalBatchDelete_EngagesStructuredPath.
  3. W1 (key-only no-read): in DeleteMultipleKeys, wanneer de tabel geen PK-tree heeft en exact één geregistreerde hash-index (geen B-tree manager) waarvan de key de conditiewaarde is, worden posities met de bekende key verwijderd — géén per-rij engine.Read/decode.
  4. docs/performance/EXECUTION_PLAN_UPDATE_DELETE.md — gecombineerd uitvoerdocument (eigen analyse + Grok second opinion) incl. D2-bevindingen.

D2-attributie (env-gated fase-timers, DELETE 10K docs-tabel)

Fase SQL Direct
per-rij read+decode 62-82 ms ~66 ms
commit-tombstones ~50 ms ~48 ms
core (index/B-tree) 23-56 ms ~32 ms
hash-lookup 5-10 ms ~5 ms

Grote vervolg-hefboom met deze cijfers: de per-rij read + per-rij Index.Delete (auto-rowid-PK) vervangen door één batch PK stale/lazy-rebuild na een grote delete-batch.

Validatie

  • Full SharpCoreDB.Tests (Debug) + Release/CI-filter op alle vier de suites: EXIT=0.
  • Release benchmark DELETE blijft ~43-50K ops/s (scanner-fix is voor deze harness gedrag-neutraal; W1 raakt alleen single-index-zonder-PK tabellen).

MPCoreDeveloper added 5 commits September 3, 2026 20:18
… flush rewrite)

Stap-0 profiling showed batch DELETE (ExecuteBatchSQL wraps every batch in a storage transaction) was NOT using the tombstone path: the rollback-safe deferral only counted _pendingLogicalDeletes, so db.Flush() still ran the #366 full-file CompactPendingDeletes rewrite (~0.5-0.7s; DELETE stuck at ~12-16K ops/s).

- IStorage.BufferTombstoneForCommit (default no-op) + Storage implementation: buffered offsets per file, applied as in-place negative-prefix markers by ApplyBufferedTombstones() inside FlushBufferedAppendsAndOverwrites() (the commit path) AFTER buffered appends are on disk; rollback discards the buffer via ClearBufferedAppends().

- DeleteRecordsCore + the contiguous FW bulk path now buffer the deleted offsets when IsInTransaction instead of incrementing _pendingLogicalDeletes, so the flush-time full-file rewrite is off the batch-DELETE path entirely.

- Regression: batch DELETE survives reopen even WITHOUT an explicit Flush after ExecuteBatchSQL (commit already tombstoned the rows).

Measured (same machine, Release, comparative harness DELETE 10K of ~100K rows): SQL 0.82s/12K -> 0.24s/41K ops/s, Direct 0.63s/16K -> 0.17s/58K ops/s; --pk legacy 0.16s/62K, fixed-width 0.13s/78K ops/s. Full suite EXIT=0.
- IStorage.TombstoneRecords (default loops TombstoneRecord); Storage batches the in-place negative-prefix markers over one cached read handle and evicts each affected page-cache page once instead of once per row.

- ApplyBufferedTombstones (commit path) and Table.TombstoneDeletedPositions (direct non-transactional deletes) route through the batch API; offsets that are not physical records (EOF/already-marked) are skipped safely.
…parse (B3)

- TryParseDeleteForBatch now also returns the canonical WHERE column + raw literal; ExecuteBatchSQL groups (where, column, literal) instead of plain WHERE strings.

- Table.DeleteMultipleKeys mirrors DeleteMultiple (contiguous-FW gate -> PK fast path -> hash fast path -> generic fallback) but resolves keys directly from the pre-parsed column/literal; the 'col = literal' string and the second TryParseSimpleWhereClause pass are built only when a generic fallback actually runs.

- Non-canonical statements keep the string path (mixed tables rebuild on the rare path).
…index columns

The structured batch DELETE path (DeleteMultipleKeys) now decodes a minimal row: BuildDeleteKeyColumns computes the needed columns (PK + every loaded hash-index column), and DeserializeDeleteKeyRow walks the legacy variable-length record skipping the unneeded columns' payload parsing entirely, building a 1-3 entry dictionary instead of a full row. DeleteRecordsCore performs the identical PK/hash lookups on that subset. Fixed-width layouts and corrupt rows fall back to the full DeserializeRowFromSpan.

Measured (Release, comparative harness DELETE 10K of ~100K rows, median of 3): SQL ~39-42K and Direct ~57K ops/s — neutral within run noise on this small-row workload; the win shows on wider rows / long unindexed TEXT payloads where payload parsing and boxing are skipped. Full suite + 4 CI-filter suites EXIT=0.
D2 profiling (env-gated phase timers) showed TryScanCanonicalDml's DELETE branch never consumed the whitespace/WHERE keyword after the table name, so every canonical 'DELETE ... WHERE col = literal' fell back to the regex path - DeleteMultipleKeys/B1 were dead code in the benchmark harness.

- Fix scanner: DELETE now consumes whitespace + WHERE + whitespace before the WHERE column; canonical batch deletes route through the structured DeleteMultipleKeys path.

- Diagnostics: Database.CanonicalDeleteStatementsParsed counter + CanonicalBatchDelete_EngagesStructuredPath regression test.

- W1: in DeleteMultipleKeys, when the table has no PK tree and exactly one registered hash index (no B-tree manager) whose key is the condition value, delete positions are recorded with the known key - no per-row engine.Read/decode.

Profile attribution (DELETE 10K, docs): read+decode 62-82ms, commit markers ~50ms, core 23-56ms, index 5-10ms. Per-row read remains while the delete core must remove each auto-rowid PK entry - next lever is batch PK stale/lazy-rebuild.

docs/performance/EXECUTION_PLAN_UPDATE_DELETE.md: combined execution plan + D2 findings.
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@MPCoreDeveloper
MPCoreDeveloper changed the base branch from perf/keyonly-delete to master September 3, 2026 19:35
@MPCoreDeveloper
MPCoreDeveloper merged commit df85a8b into master Sep 3, 2026
2 checks passed
@MPCoreDeveloper
MPCoreDeveloper deleted the perf/canonical-delete-fastpath branch September 3, 2026 19:41
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