PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
spgtextproc.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * spgtextproc.c
4  * implementation of radix tree (compressed trie) over text
5  *
6  * In a text_ops SPGiST index, inner tuples can have a prefix which is the
7  * common prefix of all strings indexed under that tuple. The node labels
8  * represent the next byte of the string(s) after the prefix. Assuming we
9  * always use the longest possible prefix, we will get more than one node
10  * label unless the prefix length is restricted by SPGIST_MAX_PREFIX_LENGTH.
11  *
12  * To reconstruct the indexed string for any index entry, concatenate the
13  * inner-tuple prefixes and node labels starting at the root and working
14  * down to the leaf entry, then append the datum in the leaf entry.
15  * (While descending the tree, "level" is the number of bytes reconstructed
16  * so far.)
17  *
18  * However, there are two special cases for node labels: -1 indicates that
19  * there are no more bytes after the prefix-so-far, and -2 indicates that we
20  * had to split an existing allTheSame tuple (in such a case we have to create
21  * a node label that doesn't correspond to any string byte). In either case,
22  * the node label does not contribute anything to the reconstructed string.
23  *
24  * Previously, we used a node label of zero for both special cases, but
25  * this was problematic because one can't tell whether a string ending at
26  * the current level can be pushed down into such a child node. For
27  * backwards compatibility, we still support such node labels for reading;
28  * but no new entries will ever be pushed down into a zero-labeled child.
29  * No new entries ever get pushed into a -2-labeled child, either.
30  *
31  *
32  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
33  * Portions Copyright (c) 1994, Regents of the University of California
34  *
35  * IDENTIFICATION
36  * src/backend/access/spgist/spgtextproc.c
37  *
38  *-------------------------------------------------------------------------
39  */
40 #include "postgres.h"
41 
42 #include "access/spgist.h"
43 #include "catalog/pg_type.h"
44 #include "mb/pg_wchar.h"
45 #include "utils/builtins.h"
46 #include "utils/datum.h"
47 #include "utils/pg_locale.h"
48 #include "utils/varlena.h"
49 
50 
51 /*
52  * In the worst case, an inner tuple in a text radix tree could have as many
53  * as 258 nodes (one for each possible byte value, plus the two special
54  * cases). Each node can take 16 bytes on MAXALIGN=8 machines. The inner
55  * tuple must fit on an index page of size BLCKSZ. Rather than assuming we
56  * know the exact amount of overhead imposed by page headers, tuple headers,
57  * etc, we leave 100 bytes for that (the actual overhead should be no more
58  * than 56 bytes at this writing, so there is slop in this number).
59  * So we can safely create prefixes up to BLCKSZ - 258 * 16 - 100 bytes long.
60  * Unfortunately, because 258 * 16 is over 4K, there is no safe prefix length
61  * when BLCKSZ is less than 8K; it is always possible to get "SPGiST inner
62  * tuple size exceeds maximum" if there are too many distinct next-byte values
63  * at a given place in the tree. Since use of nonstandard block sizes appears
64  * to be negligible in the field, we just live with that fact for now,
65  * choosing a max prefix size of 32 bytes when BLCKSZ is configured smaller
66  * than default.
67  */
68 #define SPGIST_MAX_PREFIX_LENGTH Max((int) (BLCKSZ - 258 * 16 - 100), 32)
69 
70 /* Struct for sorting values in picksplit */
71 typedef struct spgNodePtr
72 {
74  int i;
76 } spgNodePtr;
77 
78 
79 Datum
81 {
82  /* spgConfigIn *cfgin = (spgConfigIn *) PG_GETARG_POINTER(0); */
84 
85  cfg->prefixType = TEXTOID;
86  cfg->labelType = INT2OID;
87  cfg->canReturnData = true;
88  cfg->longValuesOK = true; /* suffixing will shorten long values */
90 }
91 
92 /*
93  * Form a text datum from the given not-necessarily-null-terminated string,
94  * using short varlena header format if possible
95  */
96 static Datum
97 formTextDatum(const char *data, int datalen)
98 {
99  char *p;
100 
101  p = (char *) palloc(datalen + VARHDRSZ);
102 
103  if (datalen + VARHDRSZ_SHORT <= VARATT_SHORT_MAX)
104  {
105  SET_VARSIZE_SHORT(p, datalen + VARHDRSZ_SHORT);
106  if (datalen)
107  memcpy(p + VARHDRSZ_SHORT, data, datalen);
108  }
109  else
110  {
111  SET_VARSIZE(p, datalen + VARHDRSZ);
112  memcpy(p + VARHDRSZ, data, datalen);
113  }
114 
115  return PointerGetDatum(p);
116 }
117 
118 /*
119  * Find the length of the common prefix of a and b
120  */
121 static int
122 commonPrefix(const char *a, const char *b, int lena, int lenb)
123 {
124  int i = 0;
125 
126  while (i < lena && i < lenb && *a == *b)
127  {
128  a++;
129  b++;
130  i++;
131  }
132 
133  return i;
134 }
135 
136 /*
137  * Binary search an array of int16 datums for a match to c
138  *
139  * On success, *i gets the match location; on failure, it gets where to insert
140  */
141 static bool
142 searchChar(Datum *nodeLabels, int nNodes, int16 c, int *i)
143 {
144  int StopLow = 0,
145  StopHigh = nNodes;
146 
147  while (StopLow < StopHigh)
148  {
149  int StopMiddle = (StopLow + StopHigh) >> 1;
150  int16 middle = DatumGetInt16(nodeLabels[StopMiddle]);
151 
152  if (c < middle)
153  StopHigh = StopMiddle;
154  else if (c > middle)
155  StopLow = StopMiddle + 1;
156  else
157  {
158  *i = StopMiddle;
159  return true;
160  }
161  }
162 
163  *i = StopHigh;
164  return false;
165 }
166 
167 Datum
169 {
172  text *inText = DatumGetTextPP(in->datum);
173  char *inStr = VARDATA_ANY(inText);
174  int inSize = VARSIZE_ANY_EXHDR(inText);
175  char *prefixStr = NULL;
176  int prefixSize = 0;
177  int commonLen = 0;
178  int16 nodeChar = 0;
179  int i = 0;
180 
181  /* Check for prefix match, set nodeChar to first byte after prefix */
182  if (in->hasPrefix)
183  {
184  text *prefixText = DatumGetTextPP(in->prefixDatum);
185 
186  prefixStr = VARDATA_ANY(prefixText);
187  prefixSize = VARSIZE_ANY_EXHDR(prefixText);
188 
189  commonLen = commonPrefix(inStr + in->level,
190  prefixStr,
191  inSize - in->level,
192  prefixSize);
193 
194  if (commonLen == prefixSize)
195  {
196  if (inSize - in->level > commonLen)
197  nodeChar = *(unsigned char *) (inStr + in->level + commonLen);
198  else
199  nodeChar = -1;
200  }
201  else
202  {
203  /* Must split tuple because incoming value doesn't match prefix */
204  out->resultType = spgSplitTuple;
205 
206  if (commonLen == 0)
207  {
208  out->result.splitTuple.prefixHasPrefix = false;
209  }
210  else
211  {
212  out->result.splitTuple.prefixHasPrefix = true;
213  out->result.splitTuple.prefixPrefixDatum =
214  formTextDatum(prefixStr, commonLen);
215  }
216  out->result.splitTuple.prefixNNodes = 1;
217  out->result.splitTuple.prefixNodeLabels =
218  (Datum *) palloc(sizeof(Datum));
219  out->result.splitTuple.prefixNodeLabels[0] =
220  Int16GetDatum(*(unsigned char *) (prefixStr + commonLen));
221 
222  out->result.splitTuple.childNodeN = 0;
223 
224  if (prefixSize - commonLen == 1)
225  {
226  out->result.splitTuple.postfixHasPrefix = false;
227  }
228  else
229  {
230  out->result.splitTuple.postfixHasPrefix = true;
231  out->result.splitTuple.postfixPrefixDatum =
232  formTextDatum(prefixStr + commonLen + 1,
233  prefixSize - commonLen - 1);
234  }
235 
236  PG_RETURN_VOID();
237  }
238  }
239  else if (inSize > in->level)
240  {
241  nodeChar = *(unsigned char *) (inStr + in->level);
242  }
243  else
244  {
245  nodeChar = -1;
246  }
247 
248  /* Look up nodeChar in the node label array */
249  if (searchChar(in->nodeLabels, in->nNodes, nodeChar, &i))
250  {
251  /*
252  * Descend to existing node. (If in->allTheSame, the core code will
253  * ignore our nodeN specification here, but that's OK. We still have
254  * to provide the correct levelAdd and restDatum values, and those are
255  * the same regardless of which node gets chosen by core.)
256  */
257  int levelAdd;
258 
259  out->resultType = spgMatchNode;
260  out->result.matchNode.nodeN = i;
261  levelAdd = commonLen;
262  if (nodeChar >= 0)
263  levelAdd++;
264  out->result.matchNode.levelAdd = levelAdd;
265  if (inSize - in->level - levelAdd > 0)
266  out->result.matchNode.restDatum =
267  formTextDatum(inStr + in->level + levelAdd,
268  inSize - in->level - levelAdd);
269  else
270  out->result.matchNode.restDatum =
271  formTextDatum(NULL, 0);
272  }
273  else if (in->allTheSame)
274  {
275  /*
276  * Can't use AddNode action, so split the tuple. The upper tuple has
277  * the same prefix as before and uses a dummy node label -2 for the
278  * lower tuple. The lower tuple has no prefix and the same node
279  * labels as the original tuple.
280  *
281  * Note: it might seem tempting to shorten the upper tuple's prefix,
282  * if it has one, then use its last byte as label for the lower tuple.
283  * But that doesn't win since we know the incoming value matches the
284  * whole prefix: we'd just end up splitting the lower tuple again.
285  */
286  out->resultType = spgSplitTuple;
287  out->result.splitTuple.prefixHasPrefix = in->hasPrefix;
288  out->result.splitTuple.prefixPrefixDatum = in->prefixDatum;
289  out->result.splitTuple.prefixNNodes = 1;
290  out->result.splitTuple.prefixNodeLabels = (Datum *) palloc(sizeof(Datum));
291  out->result.splitTuple.prefixNodeLabels[0] = Int16GetDatum(-2);
292  out->result.splitTuple.childNodeN = 0;
293  out->result.splitTuple.postfixHasPrefix = false;
294  }
295  else
296  {
297  /* Add a node for the not-previously-seen nodeChar value */
298  out->resultType = spgAddNode;
299  out->result.addNode.nodeLabel = Int16GetDatum(nodeChar);
300  out->result.addNode.nodeN = i;
301  }
302 
303  PG_RETURN_VOID();
304 }
305 
306 /* qsort comparator to sort spgNodePtr structs by "c" */
307 static int
308 cmpNodePtr(const void *a, const void *b)
309 {
310  const spgNodePtr *aa = (const spgNodePtr *) a;
311  const spgNodePtr *bb = (const spgNodePtr *) b;
312 
313  return aa->c - bb->c;
314 }
315 
316 Datum
318 {
321  text *text0 = DatumGetTextPP(in->datums[0]);
322  int i,
323  commonLen;
324  spgNodePtr *nodes;
325 
326  /* Identify longest common prefix, if any */
327  commonLen = VARSIZE_ANY_EXHDR(text0);
328  for (i = 1; i < in->nTuples && commonLen > 0; i++)
329  {
330  text *texti = DatumGetTextPP(in->datums[i]);
331  int tmp = commonPrefix(VARDATA_ANY(text0),
332  VARDATA_ANY(texti),
333  VARSIZE_ANY_EXHDR(text0),
334  VARSIZE_ANY_EXHDR(texti));
335 
336  if (tmp < commonLen)
337  commonLen = tmp;
338  }
339 
340  /*
341  * Limit the prefix length, if necessary, to ensure that the resulting
342  * inner tuple will fit on a page.
343  */
344  commonLen = Min(commonLen, SPGIST_MAX_PREFIX_LENGTH);
345 
346  /* Set node prefix to be that string, if it's not empty */
347  if (commonLen == 0)
348  {
349  out->hasPrefix = false;
350  }
351  else
352  {
353  out->hasPrefix = true;
354  out->prefixDatum = formTextDatum(VARDATA_ANY(text0), commonLen);
355  }
356 
357  /* Extract the node label (first non-common byte) from each value */
358  nodes = (spgNodePtr *) palloc(sizeof(spgNodePtr) * in->nTuples);
359 
360  for (i = 0; i < in->nTuples; i++)
361  {
362  text *texti = DatumGetTextPP(in->datums[i]);
363 
364  if (commonLen < VARSIZE_ANY_EXHDR(texti))
365  nodes[i].c = *(unsigned char *) (VARDATA_ANY(texti) + commonLen);
366  else
367  nodes[i].c = -1; /* use -1 if string is all common */
368  nodes[i].i = i;
369  nodes[i].d = in->datums[i];
370  }
371 
372  /*
373  * Sort by label values so that we can group the values into nodes. This
374  * also ensures that the nodes are ordered by label value, allowing the
375  * use of binary search in searchChar.
376  */
377  qsort(nodes, in->nTuples, sizeof(*nodes), cmpNodePtr);
378 
379  /* And emit results */
380  out->nNodes = 0;
381  out->nodeLabels = (Datum *) palloc(sizeof(Datum) * in->nTuples);
382  out->mapTuplesToNodes = (int *) palloc(sizeof(int) * in->nTuples);
383  out->leafTupleDatums = (Datum *) palloc(sizeof(Datum) * in->nTuples);
384 
385  for (i = 0; i < in->nTuples; i++)
386  {
387  text *texti = DatumGetTextPP(nodes[i].d);
388  Datum leafD;
389 
390  if (i == 0 || nodes[i].c != nodes[i - 1].c)
391  {
392  out->nodeLabels[out->nNodes] = Int16GetDatum(nodes[i].c);
393  out->nNodes++;
394  }
395 
396  if (commonLen < VARSIZE_ANY_EXHDR(texti))
397  leafD = formTextDatum(VARDATA_ANY(texti) + commonLen + 1,
398  VARSIZE_ANY_EXHDR(texti) - commonLen - 1);
399  else
400  leafD = formTextDatum(NULL, 0);
401 
402  out->leafTupleDatums[nodes[i].i] = leafD;
403  out->mapTuplesToNodes[nodes[i].i] = out->nNodes - 1;
404  }
405 
406  PG_RETURN_VOID();
407 }
408 
409 Datum
411 {
414  bool collate_is_c = lc_collate_is_c(PG_GET_COLLATION());
415  text *reconstructedValue;
416  text *reconstrText;
417  int maxReconstrLen;
418  text *prefixText = NULL;
419  int prefixSize = 0;
420  int i;
421 
422  /*
423  * Reconstruct values represented at this tuple, including parent data,
424  * prefix of this tuple if any, and the node label if it's non-dummy.
425  * in->level should be the length of the previously reconstructed value,
426  * and the number of bytes added here is prefixSize or prefixSize + 1.
427  *
428  * Note: we assume that in->reconstructedValue isn't toasted and doesn't
429  * have a short varlena header. This is okay because it must have been
430  * created by a previous invocation of this routine, and we always emit
431  * long-format reconstructed values.
432  */
433  reconstructedValue = (text *) DatumGetPointer(in->reconstructedValue);
434  Assert(reconstructedValue == NULL ? in->level == 0 :
435  VARSIZE_ANY_EXHDR(reconstructedValue) == in->level);
436 
437  maxReconstrLen = in->level + 1;
438  if (in->hasPrefix)
439  {
440  prefixText = DatumGetTextPP(in->prefixDatum);
441  prefixSize = VARSIZE_ANY_EXHDR(prefixText);
442  maxReconstrLen += prefixSize;
443  }
444 
445  reconstrText = palloc(VARHDRSZ + maxReconstrLen);
446  SET_VARSIZE(reconstrText, VARHDRSZ + maxReconstrLen);
447 
448  if (in->level)
449  memcpy(VARDATA(reconstrText),
450  VARDATA(reconstructedValue),
451  in->level);
452  if (prefixSize)
453  memcpy(((char *) VARDATA(reconstrText)) + in->level,
454  VARDATA_ANY(prefixText),
455  prefixSize);
456  /* last byte of reconstrText will be filled in below */
457 
458  /*
459  * Scan the child nodes. For each one, complete the reconstructed value
460  * and see if it's consistent with the query. If so, emit an entry into
461  * the output arrays.
462  */
463  out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
464  out->levelAdds = (int *) palloc(sizeof(int) * in->nNodes);
465  out->reconstructedValues = (Datum *) palloc(sizeof(Datum) * in->nNodes);
466  out->nNodes = 0;
467 
468  for (i = 0; i < in->nNodes; i++)
469  {
470  int16 nodeChar = DatumGetInt16(in->nodeLabels[i]);
471  int thisLen;
472  bool res = true;
473  int j;
474 
475  /* If nodeChar is a dummy value, don't include it in data */
476  if (nodeChar <= 0)
477  thisLen = maxReconstrLen - 1;
478  else
479  {
480  ((unsigned char *) VARDATA(reconstrText))[maxReconstrLen - 1] = nodeChar;
481  thisLen = maxReconstrLen;
482  }
483 
484  for (j = 0; j < in->nkeys; j++)
485  {
486  StrategyNumber strategy = in->scankeys[j].sk_strategy;
487  text *inText;
488  int inSize;
489  int r;
490 
491  /*
492  * If it's a collation-aware operator, but the collation is C, we
493  * can treat it as non-collation-aware. With non-C collation we
494  * need to traverse whole tree :-( so there's no point in making
495  * any check here. (Note also that our reconstructed value may
496  * well end with a partial multibyte character, so that applying
497  * any encoding-sensitive test to it would be risky anyhow.)
498  */
499  if (strategy > 10)
500  {
501  if (collate_is_c)
502  strategy -= 10;
503  else
504  continue;
505  }
506 
507  inText = DatumGetTextPP(in->scankeys[j].sk_argument);
508  inSize = VARSIZE_ANY_EXHDR(inText);
509 
510  r = memcmp(VARDATA(reconstrText), VARDATA_ANY(inText),
511  Min(inSize, thisLen));
512 
513  switch (strategy)
514  {
517  if (r > 0)
518  res = false;
519  break;
521  if (r != 0 || inSize < thisLen)
522  res = false;
523  break;
526  if (r < 0)
527  res = false;
528  break;
529  default:
530  elog(ERROR, "unrecognized strategy number: %d",
531  in->scankeys[j].sk_strategy);
532  break;
533  }
534 
535  if (!res)
536  break; /* no need to consider remaining conditions */
537  }
538 
539  if (res)
540  {
541  out->nodeNumbers[out->nNodes] = i;
542  out->levelAdds[out->nNodes] = thisLen - in->level;
543  SET_VARSIZE(reconstrText, VARHDRSZ + thisLen);
544  out->reconstructedValues[out->nNodes] =
545  datumCopy(PointerGetDatum(reconstrText), false, -1);
546  out->nNodes++;
547  }
548  }
549 
550  PG_RETURN_VOID();
551 }
552 
553 Datum
555 {
558  int level = in->level;
559  text *leafValue,
560  *reconstrValue = NULL;
561  char *fullValue;
562  int fullLen;
563  bool res;
564  int j;
565 
566  /* all tests are exact */
567  out->recheck = false;
568 
569  leafValue = DatumGetTextPP(in->leafDatum);
570 
572  reconstrValue = DatumGetTextP(in->reconstructedValue);
573 
574  Assert(reconstrValue == NULL ? level == 0 :
575  VARSIZE_ANY_EXHDR(reconstrValue) == level);
576 
577  /* Reconstruct the full string represented by this leaf tuple */
578  fullLen = level + VARSIZE_ANY_EXHDR(leafValue);
579  if (VARSIZE_ANY_EXHDR(leafValue) == 0 && level > 0)
580  {
581  fullValue = VARDATA(reconstrValue);
582  out->leafValue = PointerGetDatum(reconstrValue);
583  }
584  else
585  {
586  text *fullText = palloc(VARHDRSZ + fullLen);
587 
588  SET_VARSIZE(fullText, VARHDRSZ + fullLen);
589  fullValue = VARDATA(fullText);
590  if (level)
591  memcpy(fullValue, VARDATA(reconstrValue), level);
592  if (VARSIZE_ANY_EXHDR(leafValue) > 0)
593  memcpy(fullValue + level, VARDATA_ANY(leafValue),
594  VARSIZE_ANY_EXHDR(leafValue));
595  out->leafValue = PointerGetDatum(fullText);
596  }
597 
598  /* Perform the required comparison(s) */
599  res = true;
600  for (j = 0; j < in->nkeys; j++)
601  {
602  StrategyNumber strategy = in->scankeys[j].sk_strategy;
603  text *query = DatumGetTextPP(in->scankeys[j].sk_argument);
604  int queryLen = VARSIZE_ANY_EXHDR(query);
605  int r;
606 
607  if (strategy > 10)
608  {
609  /* Collation-aware comparison */
610  strategy -= 10;
611 
612  /* If asserts enabled, verify encoding of reconstructed string */
613  Assert(pg_verifymbstr(fullValue, fullLen, false));
614 
615  r = varstr_cmp(fullValue, Min(queryLen, fullLen),
616  VARDATA_ANY(query), Min(queryLen, fullLen),
617  PG_GET_COLLATION());
618  }
619  else
620  {
621  /* Non-collation-aware comparison */
622  r = memcmp(fullValue, VARDATA_ANY(query), Min(queryLen, fullLen));
623  }
624 
625  if (r == 0)
626  {
627  if (queryLen > fullLen)
628  r = -1;
629  else if (queryLen < fullLen)
630  r = 1;
631  }
632 
633  switch (strategy)
634  {
636  res = (r < 0);
637  break;
639  res = (r <= 0);
640  break;
642  res = (r == 0);
643  break;
645  res = (r >= 0);
646  break;
648  res = (r > 0);
649  break;
650  default:
651  elog(ERROR, "unrecognized strategy number: %d",
652  in->scankeys[j].sk_strategy);
653  res = false;
654  break;
655  }
656 
657  if (!res)
658  break; /* no need to consider remaining conditions */
659  }
660 
661  PG_RETURN_BOOL(res);
662 }
Datum reconstructedValue
Definition: spgist.h:170
signed short int16
Definition: c.h:252
#define SET_VARSIZE_SHORT(PTR, len)
Definition: postgres.h:331
Datum datum
Definition: spgist.h:56
bool hasPrefix
Definition: spgist.h:62
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define VARDATA(PTR)
Definition: postgres.h:305
struct spgChooseOut::@41::@42 matchNode
int level
Definition: spgist.h:58
bool canReturnData
Definition: spgist.h:47
Datum * leafTupleDatums
Definition: spgist.h:127
Datum spg_text_picksplit(PG_FUNCTION_ARGS)
Definition: spgtextproc.c:317
Datum * datums
Definition: spgist.h:114
#define VARHDRSZ_SHORT
Definition: postgres.h:269
#define TEXTOID
Definition: pg_type.h:324
#define VARATT_SHORT_MAX
Definition: postgres.h:270
#define PointerGetDatum(X)
Definition: postgres.h:564
#define VARHDRSZ
Definition: c.h:441
#define DatumGetTextPP(X)
Definition: fmgr.h:249
#define Min(x, y)
Definition: c.h:802
#define Int16GetDatum(X)
Definition: postgres.h:459
struct spgNodePtr spgNodePtr
Datum prefixDatum
Definition: spgist.h:63
uint16 StrategyNumber
Definition: stratnum.h:22
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
Datum reconstructedValue
Definition: spgist.h:138
struct spgChooseOut::@41::@43 addNode
#define PG_GET_COLLATION()
Definition: fmgr.h:155
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
#define ERROR
Definition: elog.h:43
#define SPGIST_MAX_PREFIX_LENGTH
Definition: spgtextproc.c:68
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1122
Datum * nodeLabels
Definition: spgist.h:124
StrategyNumber sk_strategy
Definition: skey.h:68
ScanKey scankeys
Definition: spgist.h:167
#define INT2OID
Definition: pg_type.h:308
char * c
#define DatumGetInt16(X)
Definition: postgres.h:452
struct spgChooseOut::@41::@44 splitTuple
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:128
int nNodes
Definition: spgist.h:64
static Datum formTextDatum(const char *data, int datalen)
Definition: spgtextproc.c:97
static int cmpNodePtr(const void *a, const void *b)
Definition: spgtextproc.c:308
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
bool longValuesOK
Definition: spgist.h:48
uintptr_t Datum
Definition: postgres.h:374
Oid prefixType
Definition: spgist.h:45
Datum * nodeLabels
Definition: spgist.h:150
spgChooseResultType resultType
Definition: spgist.h:77
static int commonPrefix(const char *a, const char *b, int lena, int lenb)
Definition: spgtextproc.c:122
#define PG_RETURN_VOID()
Definition: fmgr.h:293
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
int varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
Definition: varlena.c:1384
bool hasPrefix
Definition: spgist.h:120
Datum * reconstructedValues
Definition: spgist.h:158
ScanKey scankeys
Definition: spgist.h:135
#define DatumGetTextP(X)
Definition: fmgr.h:248
#define DatumGetPointer(X)
Definition: postgres.h:557
Datum spg_text_choose(PG_FUNCTION_ARGS)
Definition: spgtextproc.c:168
Datum * nodeLabels
Definition: spgist.h:65
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
void * palloc(Size size)
Definition: mcxt.c:891
Oid labelType
Definition: spgist.h:46
int i
int * mapTuplesToNodes
Definition: spgist.h:126
union spgChooseOut::@41 result
bool allTheSame
Definition: spgist.h:61
Datum prefixDatum
Definition: spgist.h:121
Definition: c.h:435
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
Definition: wchar.c:1866
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
Datum spg_text_inner_consistent(PG_FUNCTION_ARGS)
Definition: spgtextproc.c:410
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#define elog
Definition: elog.h:219
#define qsort(a, b, c, d)
Definition: port.h:440
#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
static bool searchChar(Datum *nodeLabels, int nNodes, int16 c, int *i)
Definition: spgtextproc.c:142
Datum spg_text_config(PG_FUNCTION_ARGS)
Definition: spgtextproc.c:80
Datum spg_text_leaf_consistent(PG_FUNCTION_ARGS)
Definition: spgtextproc.c:554