feat(storage): free-list + VACUUM to reclaim orphan pages (SQLR-6)#89
Merged
Conversation
DROP TABLE / DROP INDEX / ALTER TABLE DROP COLUMN now route the dropped object's pages onto a persisted free-page list (header bytes [28..32], chained `FreelistTrunk` pages, format version v6 on demand). Subsequent saves draw from the freelist before extending the file, so unrelated tables keep their page numbers across drops and the diff pager skips their byte-identical re-stages. `VACUUM;` (new SQL statement) compacts the file by ignoring the freelist and allocating contiguously from page 1, then double-checkpoints so the on-disk shrink is visible immediately. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
header.freelist_head(bytes [28..32], format version v6 on demand) plus a newFreelistTrunkpage type. AfterDROP TABLE/DROP INDEX/ALTER TABLE DROP COLUMN, the dropped object's pages move onto the freelist instead of triggering a global page-number renumber.save_database's linearnext_free_pagecounter with aPageAllocatorthat draws from per-table preferred pools → global freelist → file extension. Unrelated tables keep their page numbers across drops, so the diff pager skips writing their byte-identical leaves.VACUUM;SQL statement (executor.rs, mod.rs dispatch) compacts the file by ignoring both pools and allocating linearly from page 1, then double-checkpoints so the on-disk shrink is visible immediately. BareVACUUM;only — modifiers rejected.Test plan
cargo fmt --all -- --checkcargo clippy --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs --all-targets— no new errorscargo test --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs— 441 tests pass (9 new SQLR-6 tests + 11 unit tests for allocator/freelist)cargo doc --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs --no-depsbuilds cleanDROP TABLE accounts; VACUUM;→ reports2 pages reclaimed (8192 bytes), file shrinks on disk, reopen confirms remaining table's rows intactOut of scope (follow-up tickets to be filed)
on_diskcache (pre-existing pager limitation, unchanged by this PR).🤖 Generated with Claude Code