From d833034909ecedf5fd7c49488f9f7726e67a7bd6 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Wed, 31 Dec 2025 16:06:33 +0800 Subject: [PATCH v2] nbtree: store operator family OID in a local variable in _bt_setup_array_cmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assign the index attribute’s operator family OID to a local variable instead of repeating rel->rd_opfamily[attno - 1] at each call site. This matches the style used by other functions in nbtpreprocesskeys.c and makes the cross-type comparison logic easier to read and maintain. Author: Chao Li Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/CAEoWx2kkCno19Kz1P9L1meuFQYxYg7HctCPc+ySGFDOAbfTCDg@mail.gmail.com --- src/backend/access/nbtree/nbtpreprocesskeys.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/backend/access/nbtree/nbtpreprocesskeys.c b/src/backend/access/nbtree/nbtpreprocesskeys.c index 5235ef9a8f5..8bbcb7ef9ae 100644 --- a/src/backend/access/nbtree/nbtpreprocesskeys.c +++ b/src/backend/access/nbtree/nbtpreprocesskeys.c @@ -2656,6 +2656,7 @@ _bt_setup_array_cmp(IndexScanDesc scan, ScanKey skey, Oid elemtype, Relation rel = scan->indexRelation; RegProcedure cmp_proc; Oid opcintype = rel->rd_opcintype[skey->sk_attno - 1]; + Oid opfamily; Assert(skey->sk_strategy == BTEqualStrategyNumber); Assert(OidIsValid(elemtype)); @@ -2674,6 +2675,8 @@ _bt_setup_array_cmp(IndexScanDesc scan, ScanKey skey, Oid elemtype, return; } + opfamily = rel->rd_opfamily[skey->sk_attno - 1]; + /* * Look up the appropriate cross-type comparison function in the opfamily. * @@ -2685,8 +2688,7 @@ _bt_setup_array_cmp(IndexScanDesc scan, ScanKey skey, Oid elemtype, * incomplete, but only in cases where it's quite likely that _bt_first * would fail in just the same way (had we not failed before it could). */ - cmp_proc = get_opfamily_proc(rel->rd_opfamily[skey->sk_attno - 1], - opcintype, elemtype, BTORDER_PROC); + cmp_proc = get_opfamily_proc(opfamily, opcintype, elemtype, BTORDER_PROC); if (!RegProcedureIsValid(cmp_proc)) elog(ERROR, "missing support function %d(%u,%u) for attribute %d of index \"%s\"", BTORDER_PROC, opcintype, elemtype, skey->sk_attno, @@ -2707,8 +2709,7 @@ _bt_setup_array_cmp(IndexScanDesc scan, ScanKey skey, Oid elemtype, * non-cross-type comparison procs for any datatype that it supports at * all. */ - cmp_proc = get_opfamily_proc(rel->rd_opfamily[skey->sk_attno - 1], - elemtype, elemtype, BTORDER_PROC); + cmp_proc = get_opfamily_proc(opfamily, elemtype, elemtype, BTORDER_PROC); if (!RegProcedureIsValid(cmp_proc)) elog(ERROR, "missing support function %d(%u,%u) for attribute %d of index \"%s\"", BTORDER_PROC, elemtype, elemtype, -- 2.39.5 (Apple Git-154)