| From: | Greg Burd <greg(at)burd(dot)me> |
|---|---|
| To: | Yao Feng <fengyao0087(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Peter Geoghegan <pg(at)bowt(dot)ie> |
| Subject: | Re: nbtree: opt-in leaf key prefix compression |
| Date: | 2026-12-02 15:18:27 |
| Message-ID: | 179622360988.1668930.17628603511662471792@burd.me |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed, Dec 2, 2026 at 7:21 PM Yao Feng <fengyao0087(at)gmail(dot)com> wrote:
Hi Yao,
Thanks for the insert/split benchmarking. The ascending-insert density
collapse was a real oversight, thanks for pointing that out. I also took
to heart the two smaller items you spotted.
v20 attached, rebased onto dc168a83874. A rightmost split now packs its
finalized left half to fillfactor measured in coded bytes. For
append-only inserts that share a long prefix the index ends up as dense
as a bulk build.
mode | index size | leaf density
----------+------------+-------------
off | 41 MB | 89.7%
on (v19) | 37 MB | 37.8%
on (v20) | 19 MB | 72.2%
which feel right as the append-only insert case now matches a CREATE
INDEX of the same keys (19 MB, 72.4%).
I adjusted the budget for the rightmost split so that it finalizes the
left half while the right half stays within one plain page. This is so
it may pack the left half's decoded content up to the full two-page
budget as long as the coded left half fits one physical page at
fillfactor.
> Since btree_xlog_split() already builds a coded left page directly
> from litems[] via _bt_prefix_form_page(), could rightmost splits pack
> leftpage directly in coded form up to fillfactor / the 2 * usable
> budget instead of capping it at one plain page?
Yes, agreed. _bt_split's rightmost case now takes the
decoded-item-array path, _bt_prefix_findsplitloc ranks points by the
coded size of the left half against fillfactor (not by decoded size
against one page), and the left half is formed with _bt_prefix_form_page
rather than built plain then recompressed.
> _bt_search_insert() skips the rightmost fastpath whenever
> P_HASPREFIX(opaque) is set [...] is there a reason we can't keep the
> fastpath for coded rightmost leaves?
I rethought this and could remember no good reason not to do what you
suggest. The fastpath's room check now reserves
BTREE_PREFIX_CODE_OVERHEAD and consults _bt_prefix_split_needed (both
O(1)), so it bails to the full descent exactly when a split is needed,
and sequential inserts into a coded rightmost leaf no longer descend
from the root every time.
> Checking hdr->decodedsz + hikeysz > usable up front would avoid that
> wasted decode pass.
Obvious in hindsight, done now. _bt_prefix_try_plain_page returns early
on that check before the decode-until-overflow loop, so a page whose
decoded content cannot fit one plain page is no longer decoded twice.
> why does _bt_split() have to decode the whole page, split in plain
> space, and re-compress both halves, instead of splitting directly on
> the coded page? [...] Have you considered splitting directly in coded
> space [...]?
I have, and I think it is the right next step, but as its own change on
top of this one rather than folded into the density fix. Splitting in
coded space (partition and copy coded items, trim and remap anchors per
half, rebuild the directory only when compression degrades) avoids the
decode and re-encode on every split and removes the ~2x cap you noted.
v20 attached, rebased onto dc168a83874.
best.
-greg
| Attachment | Content-Type | Size |
|---|---|---|
| v20-0001-nbtree-add-opt-in-leaf-key-prefix-compression.patch | application/octet-stream | 283.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-12-02 15:38:41 | Re: Interrupts vs signals |
| Previous Message | Baji Shaik | 2026-12-02 14:35:33 | Re: postgres_fdw: statistics import can silently fall back to sampling across encodings |