00001 /*------------------------------------------------------------------------- 00002 * 00003 * skey.h 00004 * POSTGRES scan key definitions. 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00008 * Portions Copyright (c) 1994, Regents of the University of California 00009 * 00010 * src/include/access/skey.h 00011 * 00012 *------------------------------------------------------------------------- 00013 */ 00014 #ifndef SKEY_H 00015 #define SKEY_H 00016 00017 #include "access/attnum.h" 00018 #include "fmgr.h" 00019 00020 00021 /* 00022 * Strategy numbers identify the semantics that particular operators have 00023 * with respect to particular operator classes. In some cases a strategy 00024 * subtype (an OID) is used as further information. 00025 */ 00026 typedef uint16 StrategyNumber; 00027 00028 #define InvalidStrategy ((StrategyNumber) 0) 00029 00030 /* 00031 * We define the strategy numbers for B-tree indexes here, to avoid having 00032 * to import access/nbtree.h into a lot of places that shouldn't need it. 00033 */ 00034 #define BTLessStrategyNumber 1 00035 #define BTLessEqualStrategyNumber 2 00036 #define BTEqualStrategyNumber 3 00037 #define BTGreaterEqualStrategyNumber 4 00038 #define BTGreaterStrategyNumber 5 00039 00040 #define BTMaxStrategyNumber 5 00041 00042 00043 /* 00044 * A ScanKey represents the application of a comparison operator between 00045 * a table or index column and a constant. When it's part of an array of 00046 * ScanKeys, the comparison conditions are implicitly ANDed. The index 00047 * column is the left argument of the operator, if it's a binary operator. 00048 * (The data structure can support unary indexable operators too; in that 00049 * case sk_argument would go unused. This is not currently implemented.) 00050 * 00051 * For an index scan, sk_strategy and sk_subtype must be set correctly for 00052 * the operator. When using a ScanKey in a heap scan, these fields are not 00053 * used and may be set to InvalidStrategy/InvalidOid. 00054 * 00055 * If the operator is collation-sensitive, sk_collation must be set 00056 * correctly as well. 00057 * 00058 * A ScanKey can also represent a ScalarArrayOpExpr, that is a condition 00059 * "column op ANY(ARRAY[...])". This is signaled by the SK_SEARCHARRAY 00060 * flag bit. The sk_argument is not a value of the operator's right-hand 00061 * argument type, but rather an array of such values, and the per-element 00062 * comparisons are to be ORed together. 00063 * 00064 * A ScanKey can also represent a condition "column IS NULL" or "column 00065 * IS NOT NULL"; these cases are signaled by the SK_SEARCHNULL and 00066 * SK_SEARCHNOTNULL flag bits respectively. The argument is always NULL, 00067 * and the sk_strategy, sk_subtype, sk_collation, and sk_func fields are 00068 * not used (unless set by the index AM). 00069 * 00070 * SK_SEARCHARRAY, SK_SEARCHNULL and SK_SEARCHNOTNULL are supported only 00071 * for index scans, not heap scans; and not all index AMs support them, 00072 * only those that set amsearcharray or amsearchnulls respectively. 00073 * 00074 * A ScanKey can also represent an ordering operator invocation, that is 00075 * an ordering requirement "ORDER BY indexedcol op constant". This looks 00076 * the same as a comparison operator, except that the operator doesn't 00077 * (usually) yield boolean. We mark such ScanKeys with SK_ORDER_BY. 00078 * SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here. 00079 * 00080 * Note: in some places, ScanKeys are used as a convenient representation 00081 * for the invocation of an access method support procedure. In this case 00082 * sk_strategy/sk_subtype are not meaningful (but sk_collation can be); and 00083 * sk_func may refer to a function that returns something other than boolean. 00084 */ 00085 typedef struct ScanKeyData 00086 { 00087 int sk_flags; /* flags, see below */ 00088 AttrNumber sk_attno; /* table or index column number */ 00089 StrategyNumber sk_strategy; /* operator strategy number */ 00090 Oid sk_subtype; /* strategy subtype */ 00091 Oid sk_collation; /* collation to use, if needed */ 00092 FmgrInfo sk_func; /* lookup info for function to call */ 00093 Datum sk_argument; /* data to compare */ 00094 } ScanKeyData; 00095 00096 typedef ScanKeyData *ScanKey; 00097 00098 /* 00099 * About row comparisons: 00100 * 00101 * The ScanKey data structure also supports row comparisons, that is ordered 00102 * tuple comparisons like (x, y) > (c1, c2), having the SQL-spec semantics 00103 * "x > c1 OR (x = c1 AND y > c2)". Note that this is currently only 00104 * implemented for btree index searches, not for heapscans or any other index 00105 * type. A row comparison is represented by a "header" ScanKey entry plus 00106 * a separate array of ScanKeys, one for each column of the row comparison. 00107 * The header entry has these properties: 00108 * sk_flags = SK_ROW_HEADER 00109 * sk_attno = index column number for leading column of row comparison 00110 * sk_strategy = btree strategy code for semantics of row comparison 00111 * (ie, < <= > or >=) 00112 * sk_subtype, sk_collation, sk_func: not used 00113 * sk_argument: pointer to subsidiary ScanKey array 00114 * If the header is part of a ScanKey array that's sorted by attno, it 00115 * must be sorted according to the leading column number. 00116 * 00117 * The subsidiary ScanKey array appears in logical column order of the row 00118 * comparison, which may be different from index column order. The array 00119 * elements are like a normal ScanKey array except that: 00120 * sk_flags must include SK_ROW_MEMBER, plus SK_ROW_END in the last 00121 * element (needed since row header does not include a count) 00122 * sk_func points to the btree comparison support function for the 00123 * opclass, NOT the operator's implementation function. 00124 * sk_strategy must be the same in all elements of the subsidiary array, 00125 * that is, the same as in the header entry. 00126 * SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here. 00127 */ 00128 00129 /* 00130 * ScanKeyData sk_flags 00131 * 00132 * sk_flags bits 0-15 are reserved for system-wide use (symbols for those 00133 * bits should be defined here). Bits 16-31 are reserved for use within 00134 * individual index access methods. 00135 */ 00136 #define SK_ISNULL 0x0001 /* sk_argument is NULL */ 00137 #define SK_UNARY 0x0002 /* unary operator (not supported!) */ 00138 #define SK_ROW_HEADER 0x0004 /* row comparison header (see above) */ 00139 #define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */ 00140 #define SK_ROW_END 0x0010 /* last row comparison member */ 00141 #define SK_SEARCHARRAY 0x0020 /* scankey represents ScalarArrayOp */ 00142 #define SK_SEARCHNULL 0x0040 /* scankey represents "col IS NULL" */ 00143 #define SK_SEARCHNOTNULL 0x0080 /* scankey represents "col IS NOT 00144 * NULL" */ 00145 #define SK_ORDER_BY 0x0100 /* scankey is for ORDER BY op */ 00146 00147 00148 /* 00149 * prototypes for functions in access/common/scankey.c 00150 */ 00151 extern void ScanKeyInit(ScanKey entry, 00152 AttrNumber attributeNumber, 00153 StrategyNumber strategy, 00154 RegProcedure procedure, 00155 Datum argument); 00156 extern void ScanKeyEntryInitialize(ScanKey entry, 00157 int flags, 00158 AttrNumber attributeNumber, 00159 StrategyNumber strategy, 00160 Oid subtype, 00161 Oid collation, 00162 RegProcedure procedure, 00163 Datum argument); 00164 extern void ScanKeyEntryInitializeWithInfo(ScanKey entry, 00165 int flags, 00166 AttrNumber attributeNumber, 00167 StrategyNumber strategy, 00168 Oid subtype, 00169 Oid collation, 00170 FmgrInfo *finfo, 00171 Datum argument); 00172 00173 #endif /* SKEY_H */