Document nbtree row comparison design.
authorPeter Geoghegan <pg@bowt.ie>
Sun, 2 Nov 2025 20:27:05 +0000 (15:27 -0500)
committerPeter Geoghegan <pg@bowt.ie>
Sun, 2 Nov 2025 20:27:05 +0000 (15:27 -0500)
commitb8f1c62807a58dc97e9262a17e7d0cadb305322b
treed3bf5a8b926c33d9c3080c85a8e1087ff36be6e2
parent4f08586c7ae5df69f768b3c4cf87f2e1a543a975
Document nbtree row comparison design.

Add comments explaining when and where it is safe for nbtree to treat
row compare keys as if they were simple scalar inequality keys on the
row's most significant column.  This is particularly important within
_bt_advance_array_keys, which deals with required inequality keys in a
general and uniform way, without any special handling for row compares.

Also spell out the implications of _bt_check_rowcompare's approach of
_conditionally_ evaluating lower-order row compare subkeys, particularly
when one of its lower-order subkeys might see NULL index tuple values
(these may or may not affect whether the qual as a whole is satisfied).
The behavior in this area isn't particularly intuitive, so these issues
seem worth going into.

In passing, add a few more defensive/documenting row comparison related
assertions to _bt_first and _bt_check_rowcompare.

Follow-up to commits bd3f59fd and ec986020.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Victor Yegorov <vyegorov@gmail.com>
Reviewed-By: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAH2-Wznwkak_K7pcAdv9uH8ZfNo8QO7+tHXOaCUddMeTfaCCFw@mail.gmail.com
Backpatch-through: 18
src/backend/access/nbtree/nbtsearch.c
src/backend/access/nbtree/nbtutils.c