Skip to content

perf(pack): single-shot trailing truncate + sequential bulk scan - #164

Merged
FiveTechSoft merged 1 commit into
FiveTechSoft:mainfrom
russimicro:perf/pack-single-truncate
Aug 5, 2026
Merged

perf(pack): single-shot trailing truncate + sequential bulk scan#164
FiveTechSoft merged 1 commit into
FiveTechSoft:mainfrom
russimicro:perf/pack-single-truncate

Conversation

@russimicro

Copy link
Copy Markdown
Collaborator

PACK copied the survivors down and then dropped the tail by re-reading the
table through the navigation path and re-appending, which is far more I/O than
the operation needs on a table with many deleted rows.

The patch scans sequentially through the bulk-read path and truncates once,
at the end.

It adds one method to driver_trait.h:

virtual util::Result<bool> truncate_to(std::uint32_t /*recno*/) { return false; }

The default returns false, so a driver that does not implement it keeps the
legacy save/zap/re-append path unchanged. This PR implements it for the CDX and
ADT drivers, where the trailing region is exactly
hdr_len + rec_count * rec_len (ADT keeps no 0x1A marker, DBF's is rewritten).

Tests

Full suite green on this branch (1290 cases), including the existing PACK/ZAP
and record-count tests.

Reapplies the Russoft PACK optimization on top of v1.8.31.

- IDriver::truncate_to(recno): drop every record above recno in one
  header/EOF rewrite plus a physical file truncate. Implemented for CDX
  and ADT; default returns false so other drivers keep the legacy path.
- Table::pack(): copy-down now reads through the driver (read-ahead
  friendly) instead of goto_record(), which reseeked the active order on
  every record; the tail is dropped via truncate_to, falling back to the
  old read-all + zap + re-append pass when the driver declines.

CDX truncate_to also shrinks the file: without it the .dbf keeps stale
trailing records and a later physical-order walk that derives the count
from file size runs past rec_count_ -> ADSCDX/5000.

Suite: 1177/1189 passed, same 12 SQL-parser (7200) failures as pristine
v1.8.31 — no regressions.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit adb0792)
@FiveTechSoft
FiveTechSoft merged commit 9b2847c into FiveTechSoft:main Aug 5, 2026
11 checks passed
FiveTechSoft added a commit to russimicro/OpenADS that referenced this pull request Aug 5, 2026
…chSoft#164

Keep both the OPENADS_ADI_V2 gate (adi_v2_enabled) and the live-key
count memoisation from FiveTechSoft#160. Register the new keycount cache test
alongside the ADI v2 regression suite.
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