From 10a0dcfc25fba51b2e0d3bbcb11584ecfb70f848 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Sat, 17 Oct 2026 11:02:49 -0400 Subject: [PATCH] Fix nbtree unsatisfiable row compare assertion failure. An assertion within nbtree preprocessing's _bt_mark_scankey_required function expects the first member key of a row compare to have the same strategy as its header key, which its caller passes. But the first row member key won't necessarily have been commuted in cases where the row compare is unsatisfiable due to its first member key having a NULL argument. This led to spurious assertion failures in the single key fast path call to _bt_mark_scankey_required. To fix, always commute the row members, even when the row compare is unsatisfiable. That way the header and its members will always agree on strategy. Oversight in commit ec986020, which improved nbtree's unsatisfiable RowCompare detection. Author: Peter Geoghegan Backpatch-through: 18 --- src/backend/access/nbtree/nbtpreprocesskeys.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/access/nbtree/nbtpreprocesskeys.c b/src/backend/access/nbtree/nbtpreprocesskeys.c index 39c0a5d610f..14d9349225e 100644 --- a/src/backend/access/nbtree/nbtpreprocesskeys.c +++ b/src/backend/access/nbtree/nbtpreprocesskeys.c @@ -733,14 +733,11 @@ _bt_fix_scankey_strategy(ScanKey skey, int16 *indoption) /* If it's a row header, fix row member flags and strategies similarly */ if (skey->sk_flags & SK_ROW_HEADER) { + bool satisfiable; ScanKey subkey = (ScanKey) DatumGetPointer(skey->sk_argument); - if (subkey->sk_flags & SK_ISNULL) - { - /* First row member is NULL, so RowCompare is unsatisfiable */ - Assert(subkey->sk_flags & SK_ROW_MEMBER); - return false; - } + /* If first row member is NULL, RowCompare is unsatisfiable */ + satisfiable = !(subkey->sk_flags & SK_ISNULL); for (;;) { @@ -753,6 +750,8 @@ _bt_fix_scankey_strategy(ScanKey skey, int16 *indoption) break; subkey++; } + + return satisfiable; } return true;