Re: nbtree: opt-in leaf key prefix compression

From: Greg Burd <greg(at)burd(dot)me>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: fengyao0087(at)gmail(dot)com, pg(at)bowt(dot)ie
Subject: Re: nbtree: opt-in leaf key prefix compression
Date: 2026-11-03 17:48:41
Message-ID: auocmb4xgo-Zl8_T@floki
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

v7 attached, one real fix since v4, found by the sanitizer CI.

CI was red on the Linux Autoconf and 32-bit legs (the ones built with
-fsanitize=alignment,undefined -fno-sanitize-recover=all) while every
other leg (64-bit meson, macOS, Windows) was green. The standby's
startup process aborted (SIGABRT) replaying a prefix leaf split:

itup.h:74: runtime error: member access within misaligned address
... for type 'const struct IndexTupleData'
#1 btree_xlog_split_prefix nbtxlog.c
#2 btree_xlog_split
#3 btree_redo

The split/dedup WAL payload for the right half is [chosen prefix bytes]
[high key][data items]. I was advancing past the prefix bytes by the
raw prefix length, not a MAXALIGN'd length, so the IndexTuple high key
(and the items after it) landed on an unaligned offset. On x86-64 the
misaligned read happens to work, which is why plain cassert builds and
my own testing never caught it; the alignment sanitizer correctly
rejects it, and a big-endian or stricter-alignment platform would fault
for real.

Fix: MAXALIGN the prefix region on both the logging and the replay side,
in the split path (_bt_split / btree_xlog_split_prefix) and the matching
dedup path (_bt_dedup_pass / btree_xlog_dedup). The left-half prefix is
logged last and read back as raw bytes, never dereferenced as a tuple,
so it was already fine and is unchanged.

The lesson for me is that WAL-payload packing has to be tested under the
alignment sanitizer, not just cassert.

No other changes from v4. For the committer (I hope!), a BTREE_VERSION
and catalog version bump.

best.

-greg

Attachment Content-Type Size
v7-0001-nbtree-opt-in-leaf-key-prefix-compression.patch text/plain 170.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-11-03 18:06:10 Re: Emptying oauth_validator_libraries doesn't stop OAuth logins
Previous Message Lucas Jeffrey 2026-11-03 17:29:50 Re: [PATCH] Fix segmentation fault caused by reentrancy in RI_Fkey_cascade_del (ri_triggers.c)