PostgreSQL Source Code  git master
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

◆ MAX_MAYBE_ENTRIES

#define MAX_MAYBE_ENTRIES   4

Definition at line 50 of file ginlogic.c.

Referenced by shimTriConsistentFn().

Function Documentation

◆ directBoolConsistentFn()

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:299
Pointer * extra_data
Definition: gin_private.h:301
#define PointerGetDatum(X)
Definition: postgres.h:556
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:1321
FmgrInfo * consistentFmgrInfo
Definition: gin_private.h:292
StrategyNumber strategy
Definition: gin_private.h:302
GinTernaryValue * entryRes
Definition: gin_private.h:289
#define DatumGetBool(X)
Definition: postgres.h:393
#define UInt32GetDatum(X)
Definition: postgres.h:493
uint32 nuserentries
Definition: gin_private.h:270
GinNullCategory * queryCategories
Definition: gin_private.h:300
#define UInt16GetDatum(X)
Definition: postgres.h:465

◆ directTriConsistentFn()

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 {
98  key->collation,
100  UInt16GetDatum(key->strategy),
101  key->query,
106 }
FmgrInfo * triConsistentFmgrInfo
Definition: gin_private.h:293
Datum * queryValues
Definition: gin_private.h:299
Pointer * extra_data
Definition: gin_private.h:301
#define PointerGetDatum(X)
Definition: postgres.h:556
#define DatumGetGinTernaryValue(X)
Definition: gin.h:65
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1287
StrategyNumber strategy
Definition: gin_private.h:302
GinTernaryValue * entryRes
Definition: gin_private.h:289
#define UInt32GetDatum(X)
Definition: postgres.h:493
uint32 nuserentries
Definition: gin_private.h:270
GinNullCategory * queryCategories
Definition: gin_private.h:300
#define UInt16GetDatum(X)
Definition: postgres.h:465

◆ ginInitConsistentFunction()

void ginInitConsistentFunction ( GinState ginstate,
GinScanKey  key 
)

Definition at line 223 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().

224 {
226  {
229  }
230  else
231  {
232  key->consistentFmgrInfo = &ginstate->consistentFn[key->attnum - 1];
233  key->triConsistentFmgrInfo = &ginstate->triConsistentFn[key->attnum - 1];
234  key->collation = ginstate->supportCollation[key->attnum - 1];
235 
236  if (OidIsValid(ginstate->consistentFn[key->attnum - 1].fn_oid))
238  else
240 
241  if (OidIsValid(ginstate->triConsistentFn[key->attnum - 1].fn_oid))
243  else
245  }
246 }
FmgrInfo * triConsistentFmgrInfo
Definition: gin_private.h:293
Oid supportCollation[INDEX_MAX_KEYS]
Definition: gin_private.h:87
static GinTernaryValue directTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:95
static GinTernaryValue shimTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:152
#define GIN_SEARCH_MODE_EVERYTHING
Definition: gin.h:37
FmgrInfo consistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:81
FmgrInfo * consistentFmgrInfo
Definition: gin_private.h:292
#define OidIsValid(objectId)
Definition: c.h:644
OffsetNumber attnum
Definition: gin_private.h:304
static GinTernaryValue trueTriConsistentFn(GinScanKey key)
Definition: ginlogic.c:62
bool(* boolConsistentFn)(GinScanKey key)
Definition: gin_private.h:290
Oid fn_oid
Definition: fmgr.h:59
GinTernaryValue(* triConsistentFn)(GinScanKey key)
Definition: gin_private.h:291
static bool directBoolConsistentFn(GinScanKey key)
Definition: ginlogic.c:71
static bool trueConsistentFn(GinScanKey key)
Definition: ginlogic.c:56
static bool shimBoolConsistentFn(GinScanKey key)
Definition: ginlogic.c:114
FmgrInfo triConsistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:82

◆ shimBoolConsistentFn()

static bool shimBoolConsistentFn ( GinScanKey  key)
static

Definition at line 114 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, GinScanKeyData::strategy, GinScanKeyData::triConsistentFmgrInfo, UInt16GetDatum, and UInt32GetDatum.

Referenced by ginInitConsistentFunction().

115 {
116  GinTernaryValue result;
117 
119  key->collation,
121  UInt16GetDatum(key->strategy),
122  key->query,
127  if (result == GIN_MAYBE)
128  {
129  key->recheckCurItem = true;
130  return true;
131  }
132  else
133  {
134  key->recheckCurItem = false;
135  return result;
136  }
137 }
FmgrInfo * triConsistentFmgrInfo
Definition: gin_private.h:293
Datum * queryValues
Definition: gin_private.h:299
Pointer * extra_data
Definition: gin_private.h:301
#define GIN_MAYBE
Definition: gin.h:62
#define PointerGetDatum(X)
Definition: postgres.h:556
#define DatumGetGinTernaryValue(X)
Definition: gin.h:65
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1287
char GinTernaryValue
Definition: gin.h:58
StrategyNumber strategy
Definition: gin_private.h:302
GinTernaryValue * entryRes
Definition: gin_private.h:289
#define UInt32GetDatum(X)
Definition: postgres.h:493
uint32 nuserentries
Definition: gin_private.h:270
GinNullCategory * queryCategories
Definition: gin_private.h:300
#define UInt16GetDatum(X)
Definition: postgres.h:465

◆ shimTriConsistentFn()

static GinTernaryValue shimTriConsistentFn ( GinScanKey  key)
static

Definition at line 152 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().

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

◆ trueConsistentFn()

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 }

◆ trueTriConsistentFn()

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:61