1 /*-------------------------------------------------------------------------
4 * scan key support code
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/access/common/scankey.c
13 *-------------------------------------------------------------------------
17 #include "access/skey.h"
18 #include "catalog/pg_collation.h"
22 * ScanKeyEntryInitialize
23 * Initializes a scan key entry given all the field values.
24 * The target procedure is specified by OID (but can be invalid
25 * if SK_SEARCHNULL or SK_SEARCHNOTNULL is set).
27 * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
28 * itself, because that's what will be used for any subsidiary info attached
29 * to the ScanKey's FmgrInfo record.
32 ScanKeyEntryInitialize(ScanKey entry
,
34 AttrNumber attributeNumber
,
35 StrategyNumber strategy
,
38 RegProcedure procedure
,
41 entry
->sk_flags
= flags
;
42 entry
->sk_attno
= attributeNumber
;
43 entry
->sk_strategy
= strategy
;
44 entry
->sk_subtype
= subtype
;
45 entry
->sk_collation
= collation
;
46 entry
->sk_argument
= argument
;
47 if (RegProcedureIsValid(procedure
))
49 fmgr_info(procedure
, &entry
->sk_func
);
53 Assert(flags
& (SK_SEARCHNULL
| SK_SEARCHNOTNULL
));
54 MemSet(&entry
->sk_func
, 0, sizeof(entry
->sk_func
));
60 * Shorthand version of ScanKeyEntryInitialize: flags and subtype
61 * are assumed to be zero (the usual value), and collation is defaulted.
63 * This is the recommended version for hardwired lookups in system catalogs.
64 * It cannot handle NULL arguments, unary operators, or nondefault operators,
65 * but we need none of those features for most hardwired lookups.
67 * We set collation to C_COLLATION_OID always. This is the correct value
68 * for all collation-aware columns in system catalogs, and it will be ignored
69 * for other column types, so it's not worth trying to be more finicky.
71 * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
72 * itself, because that's what will be used for any subsidiary info attached
73 * to the ScanKey's FmgrInfo record.
76 ScanKeyInit(ScanKey entry
,
77 AttrNumber attributeNumber
,
78 StrategyNumber strategy
,
79 RegProcedure procedure
,
83 entry
->sk_attno
= attributeNumber
;
84 entry
->sk_strategy
= strategy
;
85 entry
->sk_subtype
= InvalidOid
;
86 entry
->sk_collation
= C_COLLATION_OID
;
87 entry
->sk_argument
= argument
;
88 fmgr_info(procedure
, &entry
->sk_func
);
92 * ScanKeyEntryInitializeWithInfo
93 * Initializes a scan key entry using an already-completed FmgrInfo
94 * function lookup record.
96 * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
97 * itself, because that's what will be used for any subsidiary info attached
98 * to the ScanKey's FmgrInfo record.
101 ScanKeyEntryInitializeWithInfo(ScanKey entry
,
103 AttrNumber attributeNumber
,
104 StrategyNumber strategy
,
110 entry
->sk_flags
= flags
;
111 entry
->sk_attno
= attributeNumber
;
112 entry
->sk_strategy
= strategy
;
113 entry
->sk_subtype
= subtype
;
114 entry
->sk_collation
= collation
;
115 entry
->sk_argument
= argument
;
116 fmgr_info_copy(&entry
->sk_func
, finfo
, CurrentMemoryContext
);