PostgreSQL Source Code git master
Macros | Functions
ginlogic.c File Reference
#include "postgres.h"
#include "access/gin_private.h"
Include dependency graph for ginlogic.c:

Go to the source code of this file.

Macros

#define  MAX_MAYBE_ENTRIES   4
 

Functions

static bool  trueConsistentFn (GinScanKey key)
 
 
static bool  directBoolConsistentFn (GinScanKey key)
 
 
static bool  shimBoolConsistentFn (GinScanKey key)
 
 
 

Macro Definition Documentation

MAX_MAYBE_ENTRIES

#define MAX_MAYBE_ENTRIES   4

Definition at line 44 of file ginlogic.c.

Function Documentation

directBoolConsistentFn()

static bool directBoolConsistentFn ( GinScanKey  key )
static

Definition at line 65 of file ginlogic.c.

66{
67 /*
68 * Initialize recheckCurItem in case the consistentFn doesn't know it
69 * should set it. The safe assumption in that case is to force recheck.
70 */
71 key->recheckCurItem = true;
72
73 return DatumGetBool(FunctionCall8Coll(key->consistentFmgrInfo,
74 key->collation,
75 PointerGetDatum(key->entryRes),
76 UInt16GetDatum(key->strategy),
77 key->query,
78 UInt32GetDatum(key->nuserentries),
79 PointerGetDatum(key->extra_data),
80 PointerGetDatum(&key->recheckCurItem),
81 PointerGetDatum(key->queryValues),
82 PointerGetDatum(key->queryCategories)));
83}
Datum FunctionCall8Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Definition: fmgr.c:1319
static bool DatumGetBool(Datum X)
Definition: postgres.h:100
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
static Datum UInt16GetDatum(uint16 X)
Definition: postgres.h:202
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:242

References DatumGetBool(), FunctionCall8Coll(), sort-test::key, PointerGetDatum(), UInt16GetDatum(), and UInt32GetDatum().

Referenced by ginInitConsistentFunction(), and shimTriConsistentFn().

directTriConsistentFn()

static GinTernaryValue directTriConsistentFn ( GinScanKey  key )
static

Definition at line 89 of file ginlogic.c.

90{
91 return DatumGetGinTernaryValue(FunctionCall7Coll(key->triConsistentFmgrInfo,
92 key->collation,
93 PointerGetDatum(key->entryRes),
94 UInt16GetDatum(key->strategy),
95 key->query,
96 UInt32GetDatum(key->nuserentries),
97 PointerGetDatum(key->extra_data),
98 PointerGetDatum(key->queryValues),
99 PointerGetDatum(key->queryCategories)));
100}
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1285
static GinTernaryValue DatumGetGinTernaryValue(Datum X)
Definition: gin.h:81

References DatumGetGinTernaryValue(), FunctionCall7Coll(), sort-test::key, PointerGetDatum(), UInt16GetDatum(), and UInt32GetDatum().

Referenced by ginInitConsistentFunction().

ginInitConsistentFunction()

void ginInitConsistentFunction ( GinStateginstate,
GinScanKey  key 
)

Definition at line 227 of file ginlogic.c.

228{
229 if (key->searchMode == GIN_SEARCH_MODE_EVERYTHING)
230 {
231 key->boolConsistentFn = trueConsistentFn;
232 key->triConsistentFn = trueTriConsistentFn;
233 }
234 else
235 {
236 key->consistentFmgrInfo = &ginstate->consistentFn[key->attnum - 1];
237 key->triConsistentFmgrInfo = &ginstate->triConsistentFn[key->attnum - 1];
238 key->collation = ginstate->supportCollation[key->attnum - 1];
239
240 if (OidIsValid(ginstate->consistentFn[key->attnum - 1].fn_oid))
241 key->boolConsistentFn = directBoolConsistentFn;
242 else
243 key->boolConsistentFn = shimBoolConsistentFn;
244
245 if (OidIsValid(ginstate->triConsistentFn[key->attnum - 1].fn_oid))
246 key->triConsistentFn = directTriConsistentFn;
247 else
248 key->triConsistentFn = shimTriConsistentFn;
249 }
250}
#define OidIsValid(objectId)
Definition: c.h:774
#define GIN_SEARCH_MODE_EVERYTHING
Definition: gin.h:39
static GinTernaryValue trueTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:56
static GinTernaryValue shimTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:148
static GinTernaryValue directTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:89
static bool trueConsistentFn(GinScanKey key)
Definition: ginlogic.c:50
static bool directBoolConsistentFn(GinScanKey key)
Definition: ginlogic.c:65
static bool shimBoolConsistentFn(GinScanKey key)
Definition: ginlogic.c:108
Oid fn_oid
Definition: fmgr.h:59
FmgrInfo triConsistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:84
FmgrInfo consistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:83
Oid supportCollation[INDEX_MAX_KEYS]
Definition: gin_private.h:89

References GinState::consistentFn, directBoolConsistentFn(), directTriConsistentFn(), FmgrInfo::fn_oid, GIN_SEARCH_MODE_EVERYTHING, sort-test::key, OidIsValid, shimBoolConsistentFn(), shimTriConsistentFn(), GinState::supportCollation, GinState::triConsistentFn, trueConsistentFn(), and trueTriConsistentFn().

Referenced by ginFillScanKey().

shimBoolConsistentFn()

static bool shimBoolConsistentFn ( GinScanKey  key )
static

Definition at line 108 of file ginlogic.c.

109{
110 GinTernaryValue result;
111
112 result = DatumGetGinTernaryValue(FunctionCall7Coll(key->triConsistentFmgrInfo,
113 key->collation,
114 PointerGetDatum(key->entryRes),
115 UInt16GetDatum(key->strategy),
116 key->query,
117 UInt32GetDatum(key->nuserentries),
118 PointerGetDatum(key->extra_data),
119 PointerGetDatum(key->queryValues),
120 PointerGetDatum(key->queryCategories)));
121 if (result == GIN_MAYBE)
122 {
123 key->recheckCurItem = true;
124 return true;
125 }
126 else
127 {
128 key->recheckCurItem = false;
129 return result;
130 }
131}
char GinTernaryValue
Definition: gin.h:71
#define GIN_MAYBE
Definition: gin.h:78

References DatumGetGinTernaryValue(), FunctionCall7Coll(), GIN_MAYBE, sort-test::key, PointerGetDatum(), UInt16GetDatum(), and UInt32GetDatum().

Referenced by ginInitConsistentFunction().

shimTriConsistentFn()

static GinTernaryValue shimTriConsistentFn ( GinScanKey  key )
static

Definition at line 148 of file ginlogic.c.

149{
150 int nmaybe;
151 int maybeEntries[MAX_MAYBE_ENTRIES];
152 int i;
153 bool boolResult;
154 bool recheck;
155 GinTernaryValue curResult;
156
157 /*
158 * Count how many MAYBE inputs there are, and store their indexes in
159 * maybeEntries. If there are too many MAYBE inputs, it's not feasible to
160 * test all combinations, so give up and return MAYBE.
161 */
162 nmaybe = 0;
163 for (i = 0; i < key->nentries; i++)
164 {
165 if (key->entryRes[i] == GIN_MAYBE)
166 {
167 if (nmaybe >= MAX_MAYBE_ENTRIES)
168 return GIN_MAYBE;
169 maybeEntries[nmaybe++] = i;
170 }
171 }
172
173 /*
174 * If none of the inputs were MAYBE, we can just call the consistent
175 * function as-is.
176 */
177 if (nmaybe == 0)
179
180 /* First call consistent function with all the maybe-inputs set FALSE */
181 for (i = 0; i < nmaybe; i++)
182 key->entryRes[maybeEntries[i]] = GIN_FALSE;
183 curResult = directBoolConsistentFn(key);
184 recheck = key->recheckCurItem;
185
186 for (;;)
187 {
188 /* Twiddle the entries for next combination. */
189 for (i = 0; i < nmaybe; i++)
190 {
191 if (key->entryRes[maybeEntries[i]] == GIN_FALSE)
192 {
193 key->entryRes[maybeEntries[i]] = GIN_TRUE;
194 break;
195 }
196 else
197 key->entryRes[maybeEntries[i]] = GIN_FALSE;
198 }
199 if (i == nmaybe)
200 break;
201
202 boolResult = directBoolConsistentFn(key);
203 recheck |= key->recheckCurItem;
204
205 if (curResult != boolResult)
206 {
207 curResult = GIN_MAYBE;
208 break;
209 }
210 }
211
212 /* TRUE with recheck is taken to mean MAYBE */
213 if (curResult == GIN_TRUE && recheck)
214 curResult = GIN_MAYBE;
215
216 /* We must restore the original state of the entryRes array */
217 for (i = 0; i < nmaybe; i++)
218 key->entryRes[maybeEntries[i]] = GIN_MAYBE;
219
220 return curResult;
221}
#define GIN_FALSE
Definition: gin.h:76
#define GIN_TRUE
Definition: gin.h:77
#define MAX_MAYBE_ENTRIES
Definition: ginlogic.c:44
i
int i
Definition: isn.c:77

References directBoolConsistentFn(), GIN_FALSE, GIN_MAYBE, GIN_TRUE, i, sort-test::key, and MAX_MAYBE_ENTRIES.

Referenced by ginInitConsistentFunction().

trueConsistentFn()

static bool trueConsistentFn ( GinScanKey  key )
static

Definition at line 50 of file ginlogic.c.

51{
52 key->recheckCurItem = false;
53 return true;
54}

References sort-test::key.

Referenced by ginInitConsistentFunction().

trueTriConsistentFn()

static GinTernaryValue trueTriConsistentFn ( GinScanKey  key )
static

Definition at line 56 of file ginlogic.c.

57{
58 return GIN_TRUE;
59}

References GIN_TRUE.

Referenced by ginInitConsistentFunction().

AltStyle によって変換されたページ (->オリジナル) /