1 /*-------------------------------------------------------------------------
4 * POSTGRES scan key definitions.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
17 #include "access/attnum.h"
22 * Strategy numbers identify the semantics that particular operators have
23 * with respect to particular operator classes. In some cases a strategy
24 * subtype (an OID) is used as further information.
26 typedef uint16 StrategyNumber
;
28 #define InvalidStrategy ((StrategyNumber) 0)
31 * We define the strategy numbers for B-tree indexes here, to avoid having
32 * to import access/nbtree.h into a lot of places that shouldn't need it.
34 #define BTLessStrategyNumber 1
35 #define BTLessEqualStrategyNumber 2
36 #define BTEqualStrategyNumber 3
37 #define BTGreaterEqualStrategyNumber 4
38 #define BTGreaterStrategyNumber 5
40 #define BTMaxStrategyNumber 5
44 * A ScanKey represents the application of a comparison operator between
45 * a table or index column and a constant. When it's part of an array of
46 * ScanKeys, the comparison conditions are implicitly ANDed. The index
47 * column is the left argument of the operator, if it's a binary operator.
48 * (The data structure can support unary indexable operators too; in that
49 * case sk_argument would go unused. This is not currently implemented.)
51 * For an index scan, sk_strategy and sk_subtype must be set correctly for
52 * the operator. When using a ScanKey in a heap scan, these fields are not
53 * used and may be set to InvalidStrategy/InvalidOid.
55 * A ScanKey can also represent a condition "column IS NULL"; this is signaled
56 * by the SK_SEARCHNULL flag bit. In this case the argument is always NULL,
57 * and the sk_strategy, sk_subtype, and sk_func fields are not used (unless
58 * set by the index AM). Currently, SK_SEARCHNULL is supported only for
59 * index scans, not heap scans; and not all index AMs support it.
61 * Note: in some places, ScanKeys are used as a convenient representation
62 * for the invocation of an access method support procedure. In this case
63 * sk_strategy/sk_subtype are not meaningful, and sk_func may refer to a
64 * function that returns something other than boolean.
66 typedef struct ScanKeyData
68 int sk_flags
; /* flags, see below */
69 AttrNumber sk_attno
; /* table or index column number */
70 StrategyNumber sk_strategy
; /* operator strategy number */
71 Oid sk_subtype
; /* strategy subtype */
72 FmgrInfo sk_func
; /* lookup info for function to call */
73 Datum sk_argument
; /* data to compare */
76 typedef ScanKeyData
*ScanKey
;
79 * About row comparisons:
81 * The ScanKey data structure also supports row comparisons, that is ordered
82 * tuple comparisons like (x, y) > (c1, c2), having the SQL-spec semantics
83 * "x > c1 OR (x = c1 AND y > c2)". Note that this is currently only
84 * implemented for btree index searches, not for heapscans or any other index
85 * type. A row comparison is represented by a "header" ScanKey entry plus
86 * a separate array of ScanKeys, one for each column of the row comparison.
87 * The header entry has these properties:
88 * sk_flags = SK_ROW_HEADER
89 * sk_attno = index column number for leading column of row comparison
90 * sk_strategy = btree strategy code for semantics of row comparison
92 * sk_subtype, sk_func: not used
93 * sk_argument: pointer to subsidiary ScanKey array
94 * If the header is part of a ScanKey array that's sorted by attno, it
95 * must be sorted according to the leading column number.
97 * The subsidiary ScanKey array appears in logical column order of the row
98 * comparison, which may be different from index column order. The array
99 * elements are like a normal ScanKey array except that:
100 * sk_flags must include SK_ROW_MEMBER, plus SK_ROW_END in the last
101 * element (needed since row header does not include a count)
102 * sk_func points to the btree comparison support function for the
103 * opclass, NOT the operator's implementation function.
104 * sk_strategy must be the same in all elements of the subsidiary array,
105 * that is, the same as in the header entry.
109 * ScanKeyData sk_flags
111 * sk_flags bits 0-15 are reserved for system-wide use (symbols for those
112 * bits should be defined here). Bits 16-31 are reserved for use within
113 * individual index access methods.
115 #define SK_ISNULL 0x0001 /* sk_argument is NULL */
116 #define SK_UNARY 0x0002 /* unary operator (currently unsupported) */
117 #define SK_ROW_HEADER 0x0004 /* row comparison header (see above) */
118 #define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */
119 #define SK_ROW_END 0x0010 /* last row comparison member (see above) */
120 #define SK_SEARCHNULL 0x0020 /* scankey represents a "col IS NULL" qual */
124 * prototypes for functions in access/common/scankey.c
126 extern void ScanKeyInit(ScanKey entry
,
127 AttrNumber attributeNumber
,
128 StrategyNumber strategy
,
129 RegProcedure procedure
,
131 extern void ScanKeyEntryInitialize(ScanKey entry
,
133 AttrNumber attributeNumber
,
134 StrategyNumber strategy
,
136 RegProcedure procedure
,
138 extern void ScanKeyEntryInitializeWithInfo(ScanKey entry
,
140 AttrNumber attributeNumber
,
141 StrategyNumber strategy
,