Skip to content

Phase F reclaim: free-space splitting and coalescing - #90

Merged
jdatcmd merged 1 commit into
mainfrom
phase-f/reclaim-split-coalesce
Jul 23, 2026
Merged

Phase F reclaim: free-space splitting and coalescing#90
jdatcmd merged 1 commit into
mainfrom
phase-f/reclaim-split-coalesce

Conversation

@jdatcmd

@jdatcmd jdatcmd commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Adds partial-block reuse (split-on-allocate) and adjacency coalescing (coalesce-on-free) to the physical-reclaim free list, behind pgcolumnar.reclaim_coalesce (default on; off reverts to whole-range reuse).

  • record_free_space stores the page-aligned footprint, so free ranges tile the file page-aligned.
  • ColumnarAllocateFreeSpace splits an oversized chosen range and records the page-aligned remnant.
  • record_free_space merges an immediately adjacent range before insertion — restricted to ranges freed by the same transaction, so it never forces an older already-reusable neighbor to a newer freed_xid (which delays reuse; native_reclaim_cycles caught that regression). Same-transaction coalescing still merges the many groups one maintenance op retires together — the fragmentation case that matters.

Guards: an assert-only invariant (ColumnarCheckFreeSpaceNoOverlap) runs at the end of each online maintenance op — live footprints and free ranges must tile with no overlap. New native_reclaim_frag.sh: retiring 18 adjacent groups → 1 coalesced free range (GUC on) vs 18 fragmented rows (off), and a large recluster then reuses in place (smaller final file) instead of extending; parity holds in both modes.

Full PostgreSQL 15-19 matrix green.

🤖 Generated with Claude Code

Adds partial-block reuse and adjacency coalescing to the physical-reclaim free
list, behind pgcolumnar.reclaim_coalesce (default on; off reverts to whole-range
reuse). record_free_space stores the page-aligned footprint so free ranges tile
the file page-aligned; ColumnarAllocateFreeSpace splits an oversized chosen range
and records the page-aligned remnant; record_free_space merges an immediately
adjacent range before insertion.

Coalescing is restricted to ranges freed by the SAME transaction: merging a fresh
free with an older already-reusable neighbor would force the union to the newer
freed_xid (required for safety), delaying reuse of space that was reusable a
moment ago -- a regression the native_reclaim_cycles guard caught (the file grew
every cycle). Same-transaction coalescing still merges the many groups one
maintenance op retires together, which is the fragmentation case that matters.

Adds an assert-only invariant (ColumnarCheckFreeSpaceNoOverlap) run at the end of
each online maintenance op: live row-group footprints and free ranges must tile
the file with no overlap. Adds native_reclaim_frag.sh: retiring 18 adjacent groups
yields 1 coalesced free range with the GUC on vs 18 fragmented rows off, and a
large reclustering then reuses in place (smaller final file) instead of extending;
parity holds in both modes. Full 15-19 matrix green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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