From 9d8b01960463dc64ff5b111d523ff80fce3017af Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Mon, 31 Oct 2022 13:40:06 -0400 Subject: [PATCH v1 2/3] Turn HeapKeyTest macro into function This should always be inlined appropriately now. It is easier to read as a function. Also, remove unused include in catcache.c. --- src/backend/access/heap/heapam.c | 10 ++-- src/backend/utils/cache/catcache.c | 1 - src/include/access/valid.h | 76 ++++++++++++------------------ 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 12be87efed..1c995faa12 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -716,8 +716,10 @@ heapgettup(HeapScanDesc scan, snapshot); if (valid && key != NULL) - HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd), - nkeys, key, valid); + { + valid = HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd), + nkeys, key); + } if (valid) { @@ -1032,8 +1034,8 @@ heapgettup_pagemode(HeapScanDesc scan, { bool valid; - HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd), - nkeys, key, valid); + valid = HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd), + nkeys, key); if (valid) { scan->rs_cindex = lineindex; diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 38e943fab2..30ef0ba39c 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -19,7 +19,6 @@ #include "access/relscan.h" #include "access/sysattr.h" #include "access/table.h" -#include "access/valid.h" #include "access/xact.h" #include "catalog/pg_collation.h" #include "catalog/pg_operator.h" diff --git a/src/include/access/valid.h b/src/include/access/valid.h index a5525d0d63..26071f723e 100644 --- a/src/include/access/valid.h +++ b/src/include/access/valid.h @@ -19,51 +19,35 @@ * * Test a heap tuple to see if it satisfies a scan key. */ -#define HeapKeyTest(tuple, \ - tupdesc, \ - nkeys, \ - keys, \ - result) \ -do \ -{ \ - /* Use underscores to protect the variables passed in as parameters */ \ - int __cur_nkeys = (nkeys); \ - ScanKey __cur_keys = (keys); \ - \ - (result) = true; /* may change */ \ - for (; __cur_nkeys--; __cur_keys++) \ - { \ - Datum __atp; \ - bool __isnull; \ - Datum __test; \ - \ - if (__cur_keys->sk_flags & SK_ISNULL) \ - { \ - (result) = false; \ - break; \ - } \ - \ - __atp = heap_getattr((tuple), \ - __cur_keys->sk_attno, \ - (tupdesc), \ - &__isnull); \ - \ - if (__isnull) \ - { \ - (result) = false; \ - break; \ - } \ - \ - __test = FunctionCall2Coll(&__cur_keys->sk_func, \ - __cur_keys->sk_collation, \ - __atp, __cur_keys->sk_argument); \ - \ - if (!DatumGetBool(__test)) \ - { \ - (result) = false; \ - break; \ - } \ - } \ -} while (0) +static inline bool +HeapKeyTest(HeapTuple tuple, TupleDesc tupdesc, int nkeys, ScanKey keys) +{ + int cur_nkeys = nkeys; + ScanKey cur_key = keys; + + for (; cur_nkeys--; cur_key++) + { + Datum atp; + bool isnull; + Datum test; + + if (cur_key->sk_flags & SK_ISNULL) + return false; + + atp = heap_getattr(tuple, cur_key->sk_attno, tupdesc, &isnull); + + if (isnull) + return false; + + test = FunctionCall2Coll(&cur_key->sk_func, + cur_key->sk_collation, + atp, cur_key->sk_argument); + + if (!DatumGetBool(test)) + return false; + } + + return true; +} #endif /* VALID_H */ -- 2.37.0