Skip to content

Commit 4eb3b11

Browse files
committed
Turn HeapKeyTest macro into inline function
It is easier to read as a function. Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/flat/CAAKRu_YSOnhKsDyFcqJsKtBSrd32DP-jjXmv7hL0BPD-z0TGXQ@mail.gmail.com
1 parent c0f1e51 commit 4eb3b11

File tree

2 files changed

+39
-50
lines changed

2 files changed

+39
-50
lines changed

src/backend/access/heap/heapam.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,8 @@ heapgettup(HeapScanDesc scan,
719719
snapshot);
720720

721721
if (valid && key != NULL)
722-
HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd),
723-
nkeys, key, valid);
722+
valid = HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd),
723+
nkeys, key);
724724

725725
if (valid)
726726
{
@@ -1035,8 +1035,8 @@ heapgettup_pagemode(HeapScanDesc scan,
10351035
{
10361036
bool valid;
10371037

1038-
HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd),
1039-
nkeys, key, valid);
1038+
valid = HeapKeyTest(tuple, RelationGetDescr(scan->rs_base.rs_rd),
1039+
nkeys, key);
10401040
if (valid)
10411041
{
10421042
scan->rs_cindex = lineindex;

src/include/access/valid.h

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,45 @@
1414
#ifndef VALID_H
1515
#define VALID_H
1616

17+
#include "access/htup.h"
18+
#include "access/htup_details.h"
19+
#include "access/skey.h"
20+
#include "access/tupdesc.h"
21+
1722
/*
1823
* HeapKeyTest
1924
*
2025
* Test a heap tuple to see if it satisfies a scan key.
2126
*/
22-
#define HeapKeyTest(tuple, \
23-
tupdesc, \
24-
nkeys, \
25-
keys, \
26-
result) \
27-
do \
28-
{ \
29-
/* Use underscores to protect the variables passed in as parameters */ \
30-
int __cur_nkeys = (nkeys); \
31-
ScanKey __cur_keys = (keys); \
32-
\
33-
(result) = true; /* may change */ \
34-
for (; __cur_nkeys--; __cur_keys++) \
35-
{ \
36-
Datum __atp; \
37-
bool __isnull; \
38-
Datum __test; \
39-
\
40-
if (__cur_keys->sk_flags & SK_ISNULL) \
41-
{ \
42-
(result) = false; \
43-
break; \
44-
} \
45-
\
46-
__atp = heap_getattr((tuple), \
47-
__cur_keys->sk_attno, \
48-
(tupdesc), \
49-
&__isnull); \
50-
\
51-
if (__isnull) \
52-
{ \
53-
(result) = false; \
54-
break; \
55-
} \
56-
\
57-
__test = FunctionCall2Coll(&__cur_keys->sk_func, \
58-
__cur_keys->sk_collation, \
59-
__atp, __cur_keys->sk_argument); \
60-
\
61-
if (!DatumGetBool(__test)) \
62-
{ \
63-
(result) = false; \
64-
break; \
65-
} \
66-
} \
67-
} while (0)
27+
static inline bool
28+
HeapKeyTest(HeapTuple tuple, TupleDesc tupdesc, int nkeys, ScanKey keys)
29+
{
30+
int cur_nkeys = nkeys;
31+
ScanKey cur_key = keys;
32+
33+
for (; cur_nkeys--; cur_key++)
34+
{
35+
Datum atp;
36+
bool isnull;
37+
Datum test;
38+
39+
if (cur_key->sk_flags & SK_ISNULL)
40+
return false;
41+
42+
atp = heap_getattr(tuple, cur_key->sk_attno, tupdesc, &isnull);
43+
44+
if (isnull)
45+
return false;
46+
47+
test = FunctionCall2Coll(&cur_key->sk_func,
48+
cur_key->sk_collation,
49+
atp, cur_key->sk_argument);
50+
51+
if (!DatumGetBool(test))
52+
return false;
53+
}
54+
55+
return true;
56+
}
6857

6958
#endif /* VALID_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy