From c2637dcca05a0d52184cf92c14529f4bcdd1a5d3 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Thu, 7 Apr 2022 12:47:50 +0200 Subject: [PATCH v1 3/6] Optimize attribute iterator access for single-column btree keys This removes the index_getattr_nocache call path, which has significant overhead. --- src/include/access/nbtree_specialize.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/include/access/nbtree_specialize.h b/src/include/access/nbtree_specialize.h index b2ee09621e..2e17a761a0 100644 --- a/src/include/access/nbtree_specialize.h +++ b/src/include/access/nbtree_specialize.h @@ -100,8 +100,26 @@ #define nbts_attiter_attnum spec_i +/* + * Simplified (optimized) variant of index_getattr specialized for extracting + * only the first attribute: cache offset is guaranteed to be 0, and as such + * no cache is required. + */ #define nbts_attiter_nextattdatum(itup, tupDesc) \ - index_getattr(itup, 1, tupDesc, &(NBTS_MAKE_NAME(itup, isNull))) +( \ + AssertMacro(spec_i == 1), \ + (IndexTupleHasNulls(itup) && att_isnull(0, (char *)(itup) + sizeof(IndexTupleData))) ? \ + ( \ + (NBTS_MAKE_NAME(itup, isNull)) = true, \ + (Datum)NULL \ + ) \ + : \ + ( \ + (NBTS_MAKE_NAME(itup, isNull) = false), \ + (Datum) fetchatt(TupleDescAttr((tupDesc), 0), \ + (char *) (itup) + IndexInfoFindDataOffset((itup)->t_info)) \ + ) \ +) #define nbts_attiter_curattisnull(tuple) \ NBTS_MAKE_NAME(tuple, isNull) -- 2.30.2