PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ginlogic.c File Reference
#include "postgres.h"
#include "access/gin_private.h"
#include "access/reloptions.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "storage/indexfsm.h"
#include "storage/lmgr.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 GinTernaryValue trueTriConsistentFn (GinScanKey key)
 
static bool directBoolConsistentFn (GinScanKey key)
 
static GinTernaryValue directTriConsistentFn (GinScanKey key)
 
static bool shimBoolConsistentFn (GinScanKey key)
 
static GinTernaryValue shimTriConsistentFn (GinScanKey key)
 
void ginInitConsistentFunction (GinState *ginstate, GinScanKey key)
 

Macro Definition Documentation

#define MAX_MAYBE_ENTRIES   4

Definition at line 50 of file ginlogic.c.

Referenced by shimTriConsistentFn().

Function Documentation

static bool directBoolConsistentFn ( GinScanKey  key)
static

Definition at line 71 of file ginlogic.c.

References GinScanKeyData::collation, GinScanKeyData::consistentFmgrInfo, DatumGetBool, GinScanKeyData::entryRes, GinScanKeyData::extra_data, FunctionCall8Coll(), GinScanKeyData::nuserentries, PointerGetDatum, GinScanKeyData::query, GinScanKeyData::queryCategories, GinScanKeyData::queryValues, GinScanKeyData::recheckCurItem, GinScanKeyData::strategy, UInt16GetDatum, and UInt32GetDatum.

Referenced by ginInitConsistentFunction(), and shimTriConsistentFn().

72 {
73  /*
74  * Initialize recheckCurItem in case the consistentFn doesn't know it
75  * should set it. The safe assumption in that case is to force recheck.
76  */
77  key->recheckCurItem = true;
78 
80  key->collation,
83  key->query,
89 }
Datum * queryValues
Definition: gin_private.h:294
Pointer * extra_data
Definition: gin_private.h:296
#define PointerGetDatum(X)
Definition: postgres.h:562
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:1216
FmgrInfo * consistentFmgrInfo
Definition: gin_private.h:287
StrategyNumber strategy
Definition: gin_private.h:297
GinTernaryValue * entryRes
Definition: gin_private.h:284
#define DatumGetBool(X)
Definition: postgres.h:399
#define UInt32GetDatum(X)
Definition: postgres.h:499
uint32 nuserentries
Definition: gin_private.h:265
GinNullCategory * queryCategories
Definition: gin_private.h:295
#define UInt16GetDatum(X)
Definition: postgres.h:471
static GinTernaryValue directTriConsistentFn ( GinScanKey  key)
static

Definition at line 95 of file ginlogic.c.

References GinScanKeyData::collation, DatumGetGinTernaryValue, GinScanKeyData::entryRes, GinScanKeyData::extra_data, FunctionCall7Coll(), GinScanKeyData::nuserentries, PointerGetDatum, GinScanKeyData::query, GinScanKeyData::queryCategories, GinScanKeyData::queryValues, GinScanKeyData::strategy, GinScanKeyData::triConsistentFmgrInfo, UInt16GetDatum, and UInt32GetDatum.

Referenced by ginInitConsistentFunction().

96 {
99  key->collation,
101  UInt16GetDatum(key->strategy),
102  key->query,
107 }
FmgrInfo * triConsistentFmgrInfo
Definition: gin_private.h:288
Datum * queryValues
Definition: gin_private.h:294
Pointer * extra_data
Definition: gin_private.h:296
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetGinTernaryValue(X)
Definition: gin.h:64
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1182
StrategyNumber strategy
Definition: gin_private.h:297
GinTernaryValue * entryRes
Definition: gin_private.h:284
#define UInt32GetDatum(X)
Definition: postgres.h:499
uint32 nuserentries
Definition: gin_private.h:265
GinNullCategory * queryCategories
Definition: gin_private.h:295
#define UInt16GetDatum(X)
Definition: postgres.h:471
void ginInitConsistentFunction ( GinState ginstate,
GinScanKey  key 
)

Definition at line 225 of file ginlogic.c.

References GinScanKeyData::attnum, GinScanKeyData::boolConsistentFn, GinScanKeyData::collation, GinScanKeyData::consistentFmgrInfo, GinState::consistentFn, directBoolConsistentFn(), directTriConsistentFn(), FmgrInfo::fn_oid, GIN_SEARCH_MODE_EVERYTHING, OidIsValid, GinScanKeyData::searchMode, shimBoolConsistentFn(), shimTriConsistentFn(), GinState::supportCollation, GinScanKeyData::triConsistentFmgrInfo, GinState::triConsistentFn, GinScanKeyData::triConsistentFn, trueConsistentFn(), and trueTriConsistentFn().

Referenced by ginFillScanKey().

226 {
228  {
231  }
232  else
233  {
234  key->consistentFmgrInfo = &ginstate->consistentFn[key->attnum - 1];
235  key->triConsistentFmgrInfo = &ginstate->triConsistentFn[key->attnum - 1];
236  key->collation = ginstate->supportCollation[key->attnum - 1];
237 
238  if (OidIsValid(ginstate->consistentFn[key->attnum - 1].fn_oid))
240  else
242 
243  if (OidIsValid(ginstate->triConsistentFn[key->attnum - 1].fn_oid))
245  else
247  }
248 }
FmgrInfo * triConsistentFmgrInfo
Definition: gin_private.h:288
Oid supportCollation[INDEX_MAX_KEYS]
Definition: gin_private.h:82
static GinTernaryValue directTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:95
static GinTernaryValue shimTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:154
#define GIN_SEARCH_MODE_EVERYTHING
Definition: gin.h:36
FmgrInfo consistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:76
FmgrInfo * consistentFmgrInfo
Definition: gin_private.h:287
#define OidIsValid(objectId)
Definition: c.h:538
OffsetNumber attnum
Definition: gin_private.h:299
static GinTernaryValue trueTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:62
Oid fn_oid
Definition: fmgr.h:59
static bool directBoolConsistentFn(GinScanKey key)
Definition: ginlogic.c:71
static bool trueConsistentFn(GinScanKey key)
Definition: ginlogic.c:56
bool(* boolConsistentFn)(GinScanKey key)
Definition: gin_private.h:285
GinTernaryValue(* triConsistentFn)(GinScanKey key)
Definition: gin_private.h:286
static bool shimBoolConsistentFn(GinScanKey key)
Definition: ginlogic.c:115
FmgrInfo triConsistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:77
static bool shimBoolConsistentFn ( GinScanKey  key)
static

Definition at line 115 of file ginlogic.c.

References GinScanKeyData::collation, DatumGetGinTernaryValue, GinScanKeyData::entryRes, GinScanKeyData::extra_data, FunctionCall7Coll(), GIN_MAYBE, GinScanKeyData::nuserentries, PointerGetDatum, GinScanKeyData::query, GinScanKeyData::queryCategories, GinScanKeyData::queryValues, GinScanKeyData::recheckCurItem, result, GinScanKeyData::strategy, GinScanKeyData::triConsistentFmgrInfo, UInt16GetDatum, and UInt32GetDatum.

Referenced by ginInitConsistentFunction().

116 {
118 
121  key->collation,
123  UInt16GetDatum(key->strategy),
124  key->query,
129  if (result == GIN_MAYBE)
130  {
131  key->recheckCurItem = true;
132  return true;
133  }
134  else
135  {
136  key->recheckCurItem = false;
137  return result;
138  }
139 }
FmgrInfo * triConsistentFmgrInfo
Definition: gin_private.h:288
Datum * queryValues
Definition: gin_private.h:294
Pointer * extra_data
Definition: gin_private.h:296
#define GIN_MAYBE
Definition: gin.h:61
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetGinTernaryValue(X)
Definition: gin.h:64
return result
Definition: formatting.c:1618
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1182
char GinTernaryValue
Definition: gin.h:57
StrategyNumber strategy
Definition: gin_private.h:297
GinTernaryValue * entryRes
Definition: gin_private.h:284
#define UInt32GetDatum(X)
Definition: postgres.h:499
uint32 nuserentries
Definition: gin_private.h:265
GinNullCategory * queryCategories
Definition: gin_private.h:295
#define UInt16GetDatum(X)
Definition: postgres.h:471
static GinTernaryValue shimTriConsistentFn ( GinScanKey  key)
static

Definition at line 154 of file ginlogic.c.

References directBoolConsistentFn(), GinScanKeyData::entryRes, GIN_FALSE, GIN_MAYBE, GIN_TRUE, i, MAX_MAYBE_ENTRIES, GinScanKeyData::nentries, and GinScanKeyData::recheckCurItem.

Referenced by ginInitConsistentFunction().

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

Definition at line 56 of file ginlogic.c.

References GinScanKeyData::recheckCurItem.

Referenced by ginInitConsistentFunction().

57 {
58  key->recheckCurItem = false;
59  return true;
60 }
static GinTernaryValue trueTriConsistentFn ( GinScanKey  key)
static

Definition at line 62 of file ginlogic.c.

References GIN_TRUE.

Referenced by ginInitConsistentFunction().

63 {
64  return GIN_TRUE;
65 }
#define GIN_TRUE
Definition: gin.h:60