PostgreSQL Source Code  git master
spgist_name_ops.c File Reference
#include "postgres.h"
#include "access/spgist.h"
#include "catalog/pg_type.h"
#include "utils/datum.h"
Include dependency graph for spgist_name_ops.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (spgist_name_config)
 
Datum spgist_name_config (PG_FUNCTION_ARGS)
 
static Datum formTextDatum (const char *data, int datalen)
 
static int commonPrefix (const char *a, const char *b, int lena, int lenb)
 
static bool searchChar (Datum *nodeLabels, int nNodes, int16 c, int *i)
 
 PG_FUNCTION_INFO_V1 (spgist_name_choose)
 
Datum spgist_name_choose (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (spgist_name_inner_consistent)
 
Datum spgist_name_inner_consistent (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (spgist_name_leaf_consistent)
 
Datum spgist_name_leaf_consistent (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (spgist_name_compress)
 
Datum spgist_name_compress (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ commonPrefix()

static int commonPrefix ( const char *  a,
const char *  b,
int  lena,
int  lenb 
)
static

Definition at line 76 of file spgist_name_ops.c.

References i.

Referenced by spgist_name_choose().

77 {
78  int i = 0;
79 
80  while (i < lena && i < lenb && *a == *b)
81  {
82  a++;
83  b++;
84  i++;
85  }
86 
87  return i;
88 }
int i

◆ formTextDatum()

static Datum formTextDatum ( const char *  data,
int  datalen 
)
static

Definition at line 51 of file spgist_name_ops.c.

References palloc(), PointerGetDatum, SET_VARSIZE, SET_VARSIZE_SHORT, VARATT_SHORT_MAX, VARHDRSZ, and VARHDRSZ_SHORT.

Referenced by spgist_name_choose(), and spgist_name_compress().

52 {
53  char *p;
54 
55  p = (char *) palloc(datalen + VARHDRSZ);
56 
57  if (datalen + VARHDRSZ_SHORT <= VARATT_SHORT_MAX)
58  {
59  SET_VARSIZE_SHORT(p, datalen + VARHDRSZ_SHORT);
60  if (datalen)
61  memcpy(p + VARHDRSZ_SHORT, data, datalen);
62  }
63  else
64  {
65  SET_VARSIZE(p, datalen + VARHDRSZ);
66  memcpy(p + VARHDRSZ, data, datalen);
67  }
68 
69  return PointerGetDatum(p);
70 }
#define SET_VARSIZE_SHORT(PTR, len)
Definition: postgres.h:343
#define VARHDRSZ_SHORT
Definition: postgres.h:292
#define VARATT_SHORT_MAX
Definition: postgres.h:294
#define PointerGetDatum(X)
Definition: postgres.h:600
#define VARHDRSZ
Definition: c.h:627
void * palloc(Size size)
Definition: mcxt.c:1062
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342

◆ PG_FUNCTION_INFO_V1() [1/5]

◆ PG_FUNCTION_INFO_V1() [2/5]

PG_FUNCTION_INFO_V1 ( spgist_name_choose  )

◆ PG_FUNCTION_INFO_V1() [3/5]

PG_FUNCTION_INFO_V1 ( spgist_name_inner_consistent  )

◆ PG_FUNCTION_INFO_V1() [4/5]

PG_FUNCTION_INFO_V1 ( spgist_name_leaf_consistent  )

◆ PG_FUNCTION_INFO_V1() [5/5]

PG_FUNCTION_INFO_V1 ( spgist_name_compress  )

◆ searchChar()

static bool searchChar ( Datum nodeLabels,
int  nNodes,
int16  c,
int *  i 
)
static

Definition at line 96 of file spgist_name_ops.c.

References DatumGetInt16, PG_FUNCTION_INFO_V1(), and spgist_name_choose().

Referenced by spgist_name_choose().

97 {
98  int StopLow = 0,
99  StopHigh = nNodes;
100 
101  while (StopLow < StopHigh)
102  {
103  int StopMiddle = (StopLow + StopHigh) >> 1;
104  int16 middle = DatumGetInt16(nodeLabels[StopMiddle]);
105 
106  if (c < middle)
107  StopHigh = StopMiddle;
108  else if (c > middle)
109  StopLow = StopMiddle + 1;
110  else
111  {
112  *i = StopMiddle;
113  return true;
114  }
115  }
116 
117  *i = StopHigh;
118  return false;
119 }
signed short int16
Definition: c.h:428
char * c
#define DatumGetInt16(X)
Definition: postgres.h:488
int i

◆ spgist_name_choose()

Datum spgist_name_choose ( PG_FUNCTION_ARGS  )

Definition at line 123 of file spgist_name_ops.c.

References spgChooseOut::addNode, spgChooseIn::allTheSame, commonPrefix(), spgChooseIn::datum, DatumGetName, DatumGetTextPP, formTextDatum(), spgChooseIn::hasPrefix, i, Int16GetDatum, spgChooseIn::level, spgChooseOut::matchNode, NameStr, spgChooseIn::nNodes, spgChooseIn::nodeLabels, palloc(), PG_FUNCTION_INFO_V1(), PG_GETARG_POINTER, PG_RETURN_VOID, spgChooseIn::prefixDatum, spgChooseOut::result, spgChooseOut::resultType, searchChar(), spgAddNode, spgist_name_inner_consistent(), spgMatchNode, spgSplitTuple, spgChooseOut::splitTuple, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by searchChar().

124 {
127  Name inName = DatumGetName(in->datum);
128  char *inStr = NameStr(*inName);
129  int inSize = strlen(inStr);
130  char *prefixStr = NULL;
131  int prefixSize = 0;
132  int commonLen = 0;
133  int16 nodeChar = 0;
134  int i = 0;
135 
136  /* Check for prefix match, set nodeChar to first byte after prefix */
137  if (in->hasPrefix)
138  {
139  text *prefixText = DatumGetTextPP(in->prefixDatum);
140 
141  prefixStr = VARDATA_ANY(prefixText);
142  prefixSize = VARSIZE_ANY_EXHDR(prefixText);
143 
144  commonLen = commonPrefix(inStr + in->level,
145  prefixStr,
146  inSize - in->level,
147  prefixSize);
148 
149  if (commonLen == prefixSize)
150  {
151  if (inSize - in->level > commonLen)
152  nodeChar = *(unsigned char *) (inStr + in->level + commonLen);
153  else
154  nodeChar = -1;
155  }
156  else
157  {
158  /* Must split tuple because incoming value doesn't match prefix */
159  out->resultType = spgSplitTuple;
160 
161  if (commonLen == 0)
162  {
163  out->result.splitTuple.prefixHasPrefix = false;
164  }
165  else
166  {
167  out->result.splitTuple.prefixHasPrefix = true;
168  out->result.splitTuple.prefixPrefixDatum =
169  formTextDatum(prefixStr, commonLen);
170  }
171  out->result.splitTuple.prefixNNodes = 1;
172  out->result.splitTuple.prefixNodeLabels =
173  (Datum *) palloc(sizeof(Datum));
174  out->result.splitTuple.prefixNodeLabels[0] =
175  Int16GetDatum(*(unsigned char *) (prefixStr + commonLen));
176 
177  out->result.splitTuple.childNodeN = 0;
178 
179  if (prefixSize - commonLen == 1)
180  {
181  out->result.splitTuple.postfixHasPrefix = false;
182  }
183  else
184  {
185  out->result.splitTuple.postfixHasPrefix = true;
186  out->result.splitTuple.postfixPrefixDatum =
187  formTextDatum(prefixStr + commonLen + 1,
188  prefixSize - commonLen - 1);
189  }
190 
191  PG_RETURN_VOID();
192  }
193  }
194  else if (inSize > in->level)
195  {
196  nodeChar = *(unsigned char *) (inStr + in->level);
197  }
198  else
199  {
200  nodeChar = -1;
201  }
202 
203  /* Look up nodeChar in the node label array */
204  if (searchChar(in->nodeLabels, in->nNodes, nodeChar, &i))
205  {
206  /*
207  * Descend to existing node. (If in->allTheSame, the core code will
208  * ignore our nodeN specification here, but that's OK. We still have
209  * to provide the correct levelAdd and restDatum values, and those are
210  * the same regardless of which node gets chosen by core.)
211  */
212  int levelAdd;
213 
214  out->resultType = spgMatchNode;
215  out->result.matchNode.nodeN = i;
216  levelAdd = commonLen;
217  if (nodeChar >= 0)
218  levelAdd++;
219  out->result.matchNode.levelAdd = levelAdd;
220  if (inSize - in->level - levelAdd > 0)
221  out->result.matchNode.restDatum =
222  formTextDatum(inStr + in->level + levelAdd,
223  inSize - in->level - levelAdd);
224  else
225  out->result.matchNode.restDatum =
226  formTextDatum(NULL, 0);
227  }
228  else if (in->allTheSame)
229  {
230  /*
231  * Can't use AddNode action, so split the tuple. The upper tuple has
232  * the same prefix as before and uses a dummy node label -2 for the
233  * lower tuple. The lower tuple has no prefix and the same node
234  * labels as the original tuple.
235  *
236  * Note: it might seem tempting to shorten the upper tuple's prefix,
237  * if it has one, then use its last byte as label for the lower tuple.
238  * But that doesn't win since we know the incoming value matches the
239  * whole prefix: we'd just end up splitting the lower tuple again.
240  */
241  out->resultType = spgSplitTuple;
242  out->result.splitTuple.prefixHasPrefix = in->hasPrefix;
243  out->result.splitTuple.prefixPrefixDatum = in->prefixDatum;
244  out->result.splitTuple.prefixNNodes = 1;
245  out->result.splitTuple.prefixNodeLabels = (Datum *) palloc(sizeof(Datum));
246  out->result.splitTuple.prefixNodeLabels[0] = Int16GetDatum(-2);
247  out->result.splitTuple.childNodeN = 0;
248  out->result.splitTuple.postfixHasPrefix = false;
249  }
250  else
251  {
252  /* Add a node for the not-previously-seen nodeChar value */
253  out->resultType = spgAddNode;
254  out->result.addNode.nodeLabel = Int16GetDatum(nodeChar);
255  out->result.addNode.nodeN = i;
256  }
257 
258  PG_RETURN_VOID();
259 }
signed short int16
Definition: c.h:428
Datum datum
Definition: spgist.h:55
bool hasPrefix
Definition: spgist.h:61
#define VARDATA_ANY(PTR)
Definition: postgres.h:361
int level
Definition: spgist.h:57
#define DatumGetTextPP(X)
Definition: fmgr.h:292
#define Int16GetDatum(X)
Definition: postgres.h:495
Datum prefixDatum
Definition: spgist.h:62
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
struct spgChooseOut::@45::@47 addNode
union spgChooseOut::@45 result
#define DatumGetName(X)
Definition: postgres.h:629
struct spgChooseOut::@45::@46 matchNode
Definition: c.h:675
static bool searchChar(Datum *nodeLabels, int nNodes, int16 c, int *i)
int nNodes
Definition: spgist.h:63
uintptr_t Datum
Definition: postgres.h:411
static Datum formTextDatum(const char *data, int datalen)
spgChooseResultType resultType
Definition: spgist.h:76
#define PG_RETURN_VOID()
Definition: fmgr.h:349
static int commonPrefix(const char *a, const char *b, int lena, int lenb)
Datum * nodeLabels
Definition: spgist.h:64
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:354
void * palloc(Size size)
Definition: mcxt.c:1062
int i
#define NameStr(name)
Definition: c.h:681
bool allTheSame
Definition: spgist.h:60
Definition: c.h:621
struct spgChooseOut::@45::@48 splitTuple

◆ spgist_name_compress()

Datum spgist_name_compress ( PG_FUNCTION_ARGS  )

Definition at line 495 of file spgist_name_ops.c.

References formTextDatum(), NameStr, PG_GETARG_NAME, and PG_RETURN_DATUM.

Referenced by spgist_name_leaf_consistent().

496 {
497  Name inName = PG_GETARG_NAME(0);
498  char *inStr = NameStr(*inName);
499 
500  PG_RETURN_DATUM(formTextDatum(inStr, strlen(inStr)));
501 }
Definition: c.h:675
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
static Datum formTextDatum(const char *data, int datalen)
#define NameStr(name)
Definition: c.h:681
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278

◆ spgist_name_config()

Datum spgist_name_config ( PG_FUNCTION_ARGS  )

Definition at line 33 of file spgist_name_ops.c.

References spgConfigOut::canReturnData, spgConfigOut::labelType, spgConfigOut::leafType, spgConfigOut::longValuesOK, PG_GETARG_POINTER, PG_RETURN_VOID, and spgConfigOut::prefixType.

34 {
35  /* spgConfigIn *cfgin = (spgConfigIn *) PG_GETARG_POINTER(0); */
37 
38  cfg->prefixType = TEXTOID;
39  cfg->labelType = INT2OID;
40  cfg->leafType = TEXTOID;
41  cfg->canReturnData = true;
42  cfg->longValuesOK = true; /* suffixing will shorten long values */
44 }
bool canReturnData
Definition: spgist.h:46
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
bool longValuesOK
Definition: spgist.h:47
Oid prefixType
Definition: spgist.h:43
#define PG_RETURN_VOID()
Definition: fmgr.h:349
Oid labelType
Definition: spgist.h:44
Oid leafType
Definition: spgist.h:45

◆ spgist_name_inner_consistent()

Datum spgist_name_inner_consistent ( PG_FUNCTION_ARGS  )

Definition at line 265 of file spgist_name_ops.c.

References Assert, BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, datumCopy(), DatumGetInt16, DatumGetName, DatumGetPointer, DatumGetTextPP, elog, ERROR, spgInnerConsistentIn::hasPrefix, i, spgInnerConsistentIn::level, spgInnerConsistentOut::levelAdds, Min, NameStr, spgInnerConsistentIn::nkeys, spgInnerConsistentIn::nNodes, spgInnerConsistentOut::nNodes, spgInnerConsistentIn::nodeLabels, spgInnerConsistentOut::nodeNumbers, palloc(), PG_FUNCTION_INFO_V1(), PG_GETARG_POINTER, PG_RETURN_VOID, PointerGetDatum, spgInnerConsistentIn::prefixDatum, spgInnerConsistentIn::reconstructedValue, spgInnerConsistentOut::reconstructedValues, spgInnerConsistentIn::scankeys, SET_VARSIZE, ScanKeyData::sk_argument, ScanKeyData::sk_strategy, spgist_name_leaf_consistent(), VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.

Referenced by spgist_name_choose().

266 {
269  text *reconstructedValue;
270  text *reconstrText;
271  int maxReconstrLen;
272  text *prefixText = NULL;
273  int prefixSize = 0;
274  int i;
275 
276  /*
277  * Reconstruct values represented at this tuple, including parent data,
278  * prefix of this tuple if any, and the node label if it's non-dummy.
279  * in->level should be the length of the previously reconstructed value,
280  * and the number of bytes added here is prefixSize or prefixSize + 1.
281  *
282  * Recall that reconstructedValues are assumed to be the same type as leaf
283  * datums, so we must use "text" not "name" for them.
284  *
285  * Note: we assume that in->reconstructedValue isn't toasted and doesn't
286  * have a short varlena header. This is okay because it must have been
287  * created by a previous invocation of this routine, and we always emit
288  * long-format reconstructed values.
289  */
290  reconstructedValue = (text *) DatumGetPointer(in->reconstructedValue);
291  Assert(reconstructedValue == NULL ? in->level == 0 :
292  VARSIZE_ANY_EXHDR(reconstructedValue) == in->level);
293 
294  maxReconstrLen = in->level + 1;
295  if (in->hasPrefix)
296  {
297  prefixText = DatumGetTextPP(in->prefixDatum);
298  prefixSize = VARSIZE_ANY_EXHDR(prefixText);
299  maxReconstrLen += prefixSize;
300  }
301 
302  reconstrText = palloc(VARHDRSZ + maxReconstrLen);
303  SET_VARSIZE(reconstrText, VARHDRSZ + maxReconstrLen);
304 
305  if (in->level)
306  memcpy(VARDATA(reconstrText),
307  VARDATA(reconstructedValue),
308  in->level);
309  if (prefixSize)
310  memcpy(((char *) VARDATA(reconstrText)) + in->level,
311  VARDATA_ANY(prefixText),
312  prefixSize);
313  /* last byte of reconstrText will be filled in below */
314 
315  /*
316  * Scan the child nodes. For each one, complete the reconstructed value
317  * and see if it's consistent with the query. If so, emit an entry into
318  * the output arrays.
319  */
320  out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
321  out->levelAdds = (int *) palloc(sizeof(int) * in->nNodes);
322  out->reconstructedValues = (Datum *) palloc(sizeof(Datum) * in->nNodes);
323  out->nNodes = 0;
324 
325  for (i = 0; i < in->nNodes; i++)
326  {
327  int16 nodeChar = DatumGetInt16(in->nodeLabels[i]);
328  int thisLen;
329  bool res = true;
330  int j;
331 
332  /* If nodeChar is a dummy value, don't include it in data */
333  if (nodeChar <= 0)
334  thisLen = maxReconstrLen - 1;
335  else
336  {
337  ((unsigned char *) VARDATA(reconstrText))[maxReconstrLen - 1] = nodeChar;
338  thisLen = maxReconstrLen;
339  }
340 
341  for (j = 0; j < in->nkeys; j++)
342  {
343  StrategyNumber strategy = in->scankeys[j].sk_strategy;
344  Name inName;
345  char *inStr;
346  int inSize;
347  int r;
348 
349  inName = DatumGetName(in->scankeys[j].sk_argument);
350  inStr = NameStr(*inName);
351  inSize = strlen(inStr);
352 
353  r = memcmp(VARDATA(reconstrText), inStr,
354  Min(inSize, thisLen));
355 
356  switch (strategy)
357  {
360  if (r > 0)
361  res = false;
362  break;
364  if (r != 0 || inSize < thisLen)
365  res = false;
366  break;
369  if (r < 0)
370  res = false;
371  break;
372  default:
373  elog(ERROR, "unrecognized strategy number: %d",
374  in->scankeys[j].sk_strategy);
375  break;
376  }
377 
378  if (!res)
379  break; /* no need to consider remaining conditions */
380  }
381 
382  if (res)
383  {
384  out->nodeNumbers[out->nNodes] = i;
385  out->levelAdds[out->nNodes] = thisLen - in->level;
386  SET_VARSIZE(reconstrText, VARHDRSZ + thisLen);
387  out->reconstructedValues[out->nNodes] =
388  datumCopy(PointerGetDatum(reconstrText), false, -1);
389  out->nNodes++;
390  }
391  }
392 
393  PG_RETURN_VOID();
394 }
signed short int16
Definition: c.h:428
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
#define VARDATA_ANY(PTR)
Definition: postgres.h:361
#define VARDATA(PTR)
Definition: postgres.h:315
#define PointerGetDatum(X)
Definition: postgres.h:600
#define VARHDRSZ
Definition: c.h:627
#define DatumGetTextPP(X)
Definition: fmgr.h:292
#define Min(x, y)
Definition: c.h:986
uint16 StrategyNumber
Definition: stratnum.h:22
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
Datum reconstructedValue
Definition: spgist.h:140
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
#define DatumGetName(X)
Definition: postgres.h:629
#define ERROR
Definition: elog.h:46
StrategyNumber sk_strategy
Definition: skey.h:68
Definition: c.h:675
#define DatumGetInt16(X)
Definition: postgres.h:488
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131
uintptr_t Datum
Definition: postgres.h:411
Datum * nodeLabels
Definition: spgist.h:151
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define Assert(condition)
Definition: c.h:804
Datum * reconstructedValues
Definition: spgist.h:159
ScanKey scankeys
Definition: spgist.h:134
#define DatumGetPointer(X)
Definition: postgres.h:593
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:354
void * palloc(Size size)
Definition: mcxt.c:1062
#define elog(elevel,...)
Definition: elog.h:232
int i
#define NameStr(name)
Definition: c.h:681
Definition: c.h:621
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
#define BTLessStrategyNumber
Definition: stratnum.h:29
Datum sk_argument
Definition: skey.h:72
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32

◆ spgist_name_leaf_consistent()

Datum spgist_name_leaf_consistent ( PG_FUNCTION_ARGS  )

Definition at line 398 of file spgist_name_ops.c.

References Assert, BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, DatumGetName, DatumGetPointer, DatumGetTextPP, elog, ERROR, spgLeafConsistentIn::leafDatum, spgLeafConsistentOut::leafValue, spgLeafConsistentIn::level, Min, NAMEDATALEN, NameStr, spgLeafConsistentIn::nkeys, palloc0(), PG_FUNCTION_INFO_V1(), PG_GETARG_POINTER, PG_RETURN_BOOL, PointerGetDatum, spgLeafConsistentOut::recheck, spgLeafConsistentIn::reconstructedValue, spgLeafConsistentIn::scankeys, ScanKeyData::sk_argument, ScanKeyData::sk_strategy, spgist_name_compress(), VARDATA, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by spgist_name_inner_consistent().

399 {
402  int level = in->level;
403  text *leafValue,
404  *reconstrValue = NULL;
405  char *fullValue;
406  int fullLen;
407  bool res;
408  int j;
409 
410  /* all tests are exact */
411  out->recheck = false;
412 
413  leafValue = DatumGetTextPP(in->leafDatum);
414 
415  /* As above, in->reconstructedValue isn't toasted or short. */
417  reconstrValue = (text *) DatumGetPointer(in->reconstructedValue);
418 
419  Assert(reconstrValue == NULL ? level == 0 :
420  VARSIZE_ANY_EXHDR(reconstrValue) == level);
421 
422  /* Reconstruct the Name represented by this leaf tuple */
423  fullValue = palloc0(NAMEDATALEN);
424  fullLen = level + VARSIZE_ANY_EXHDR(leafValue);
425  Assert(fullLen < NAMEDATALEN);
426  if (VARSIZE_ANY_EXHDR(leafValue) == 0 && level > 0)
427  {
428  memcpy(fullValue, VARDATA(reconstrValue),
429  VARSIZE_ANY_EXHDR(reconstrValue));
430  }
431  else
432  {
433  if (level)
434  memcpy(fullValue, VARDATA(reconstrValue), level);
435  if (VARSIZE_ANY_EXHDR(leafValue) > 0)
436  memcpy(fullValue + level, VARDATA_ANY(leafValue),
437  VARSIZE_ANY_EXHDR(leafValue));
438  }
439  out->leafValue = PointerGetDatum(fullValue);
440 
441  /* Perform the required comparison(s) */
442  res = true;
443  for (j = 0; j < in->nkeys; j++)
444  {
445  StrategyNumber strategy = in->scankeys[j].sk_strategy;
446  Name queryName = DatumGetName(in->scankeys[j].sk_argument);
447  char *queryStr = NameStr(*queryName);
448  int queryLen = strlen(queryStr);
449  int r;
450 
451  /* Non-collation-aware comparison */
452  r = memcmp(fullValue, queryStr, Min(queryLen, fullLen));
453 
454  if (r == 0)
455  {
456  if (queryLen > fullLen)
457  r = -1;
458  else if (queryLen < fullLen)
459  r = 1;
460  }
461 
462  switch (strategy)
463  {
465  res = (r < 0);
466  break;
468  res = (r <= 0);
469  break;
471  res = (r == 0);
472  break;
474  res = (r >= 0);
475  break;
477  res = (r > 0);
478  break;
479  default:
480  elog(ERROR, "unrecognized strategy number: %d",
481  in->scankeys[j].sk_strategy);
482  res = false;
483  break;
484  }
485 
486  if (!res)
487  break; /* no need to consider remaining conditions */
488  }
489 
490  PG_RETURN_BOOL(res);
491 }
Datum reconstructedValue
Definition: spgist.h:175
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
#define VARDATA_ANY(PTR)
Definition: postgres.h:361
#define VARDATA(PTR)
Definition: postgres.h:315
#define PointerGetDatum(X)
Definition: postgres.h:600
#define DatumGetTextPP(X)
Definition: fmgr.h:292
#define Min(x, y)
Definition: c.h:986
uint16 StrategyNumber
Definition: stratnum.h:22
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
#define NAMEDATALEN
#define DatumGetName(X)
Definition: postgres.h:629
#define ERROR
Definition: elog.h:46
StrategyNumber sk_strategy
Definition: skey.h:68
ScanKey scankeys
Definition: spgist.h:169
Definition: c.h:675
void * palloc0(Size size)
Definition: mcxt.c:1093
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define Assert(condition)
Definition: c.h:804
#define DatumGetPointer(X)
Definition: postgres.h:593
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:354
#define elog(elevel,...)
Definition: elog.h:232
#define NameStr(name)
Definition: c.h:681
Definition: c.h:621
#define BTLessStrategyNumber
Definition: stratnum.h:29
Datum sk_argument
Definition: skey.h:72
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 28 of file spgist_name_ops.c.