PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ltree_gist.c
Go to the documentation of this file.
1 /*
2  * GiST support for ltree
3  * Teodor Sigaev <teodor@stack.net>
4  * contrib/ltree/ltree_gist.c
5  */
6 #include "postgres.h"
7 
8 #include "access/gist.h"
9 #include "access/stratnum.h"
10 #include "crc32.h"
11 #include "ltree.h"
12 
13 #define NEXTVAL(x) ( (lquery*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
14 
17 
18 Datum
20 {
21  ereport(ERROR,
22  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
23  errmsg("ltree_gist_in() not implemented")));
24  PG_RETURN_DATUM(0);
25 }
26 
27 Datum
29 {
30  ereport(ERROR,
31  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
32  errmsg("ltree_gist_out() not implemented")));
33  PG_RETURN_DATUM(0);
34 }
35 
43 
44 #define ISEQ(a,b) ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 )
45 #define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))
46 
47 Datum
49 {
50  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
51  GISTENTRY *retval = entry;
52 
53  if (entry->leafkey)
54  { /* ltree */
55  ltree_gist *key;
57  int32 len = LTG_HDRSIZE + VARSIZE(val);
58 
59  key = (ltree_gist *) palloc0(len);
60  SET_VARSIZE(key, len);
61  key->flag = LTG_ONENODE;
62  memcpy((void *) LTG_NODE(key), (void *) val, VARSIZE(val));
63 
64  retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
65  gistentryinit(*retval, PointerGetDatum(key),
66  entry->rel, entry->page,
67  entry->offset, FALSE);
68  }
69  PG_RETURN_POINTER(retval);
70 }
71 
72 Datum
74 {
75  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
77 
78  if (PointerGetDatum(key) != entry->key)
79  {
80  GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
81 
82  gistentryinit(*retval, PointerGetDatum(key),
83  entry->rel, entry->page,
84  entry->offset, FALSE);
85  PG_RETURN_POINTER(retval);
86  }
87  PG_RETURN_POINTER(entry);
88 }
89 
90 Datum
92 {
95  bool *result = (bool *) PG_GETARG_POINTER(2);
96 
97  *result = false;
98  if (LTG_ISONENODE(a) != LTG_ISONENODE(b))
99  PG_RETURN_POINTER(result);
100 
101  if (LTG_ISONENODE(a))
102  *result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false;
103  else
104  {
105  int32 i;
106  BITVECP sa = LTG_SIGN(a),
107  sb = LTG_SIGN(b);
108 
109  if (LTG_ISALLTRUE(a) != LTG_ISALLTRUE(b))
110  PG_RETURN_POINTER(result);
111 
112  if (!ISEQ(LTG_LNODE(a), LTG_LNODE(b)))
113  PG_RETURN_POINTER(result);
114  if (!ISEQ(LTG_RNODE(a), LTG_RNODE(b)))
115  PG_RETURN_POINTER(result);
116 
117  *result = true;
118  if (!LTG_ISALLTRUE(a))
119  {
120  LOOPBYTE
121  {
122  if (sa[i] != sb[i])
123  {
124  *result = false;
125  break;
126  }
127  }
128  }
129  }
130 
131  PG_RETURN_POINTER(result);
132 }
133 
134 static void
136 {
137  int tlen = t->numlevel;
139  int hash;
140 
141  while (tlen > 0)
142  {
143  hash = ltree_crc32_sz(cur->name, cur->len);
144  HASH(sign, hash);
145  cur = LEVEL_NEXT(cur);
146  tlen--;
147  }
148 }
149 
150 Datum
152 {
154  int *size = (int *) PG_GETARG_POINTER(1);
155  BITVEC base;
156  int32 i,
157  j;
159  *cur;
160  ltree *left = NULL,
161  *right = NULL,
162  *curtree;
163  bool isalltrue = false;
164  bool isleqr;
165 
166  MemSet((void *) base, 0, sizeof(BITVEC));
167  for (j = 0; j < entryvec->n; j++)
168  {
169  cur = GETENTRY(entryvec, j);
170  if (LTG_ISONENODE(cur))
171  {
172  curtree = LTG_NODE(cur);
173  hashing(base, curtree);
174  if (!left || ltree_compare(left, curtree) > 0)
175  left = curtree;
176  if (!right || ltree_compare(right, curtree) < 0)
177  right = curtree;
178  }
179  else
180  {
181  if (isalltrue || LTG_ISALLTRUE(cur))
182  isalltrue = true;
183  else
184  {
185  BITVECP sc = LTG_SIGN(cur);
186 
187  LOOPBYTE
188  ((unsigned char *) base)[i] |= sc[i];
189  }
190 
191  curtree = LTG_LNODE(cur);
192  if (!left || ltree_compare(left, curtree) > 0)
193  left = curtree;
194  curtree = LTG_RNODE(cur);
195  if (!right || ltree_compare(right, curtree) < 0)
196  right = curtree;
197  }
198  }
199 
200  if (isalltrue == false)
201  {
202  isalltrue = true;
203  LOOPBYTE
204  {
205  if (((unsigned char *) base)[i] != 0xff)
206  {
207  isalltrue = false;
208  break;
209  }
210  }
211  }
212 
213  isleqr = (left == right || ISEQ(left, right)) ? true : false;
214  *size = LTG_HDRSIZE + ((isalltrue) ? 0 : SIGLEN) + VARSIZE(left) + ((isleqr) ? 0 : VARSIZE(right));
215 
216  result = (ltree_gist *) palloc0(*size);
217  SET_VARSIZE(result, *size);
218  result->flag = 0;
219 
220  if (isalltrue)
221  result->flag |= LTG_ALLTRUE;
222  else
223  memcpy((void *) LTG_SIGN(result), base, SIGLEN);
224 
225  memcpy((void *) LTG_LNODE(result), (void *) left, VARSIZE(left));
226  if (isleqr)
227  result->flag |= LTG_NORIGHT;
228  else
229  memcpy((void *) LTG_RNODE(result), (void *) right, VARSIZE(right));
230 
231  PG_RETURN_POINTER(result);
232 }
233 
234 Datum
236 {
237  ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
239  float *penalty = (float *) PG_GETARG_POINTER(2);
240  int32 cmpr,
241  cmpl;
242 
243  cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval));
244  cmpr = ltree_compare(LTG_GETRNODE(newval), LTG_GETRNODE(origval));
245 
246  *penalty = Max(cmpl, 0) + Max(cmpr, 0);
247 
248  PG_RETURN_POINTER(penalty);
249 }
250 
251 /* used for sorting */
252 typedef struct rix
253 {
254  int index;
256 } RIX;
257 
258 static int
259 treekey_cmp(const void *a, const void *b)
260 {
261  return ltree_compare(
262  ((const RIX *) a)->r,
263  ((const RIX *) b)->r
264  );
265 }
266 
267 
268 Datum
270 {
273  OffsetNumber j;
274  int32 i;
275  RIX *array;
276  OffsetNumber maxoff;
277  int nbytes;
278  int size;
279  ltree *lu_l,
280  *lu_r,
281  *ru_l,
282  *ru_r;
283  ltree_gist *lu,
284  *ru;
285  BITVEC ls,
286  rs;
287  bool lisat = false,
288  risat = false,
289  isleqr;
290 
291  memset((void *) ls, 0, sizeof(BITVEC));
292  memset((void *) rs, 0, sizeof(BITVEC));
293  maxoff = entryvec->n - 1;
294  nbytes = (maxoff + 2) * sizeof(OffsetNumber);
295  v->spl_left = (OffsetNumber *) palloc(nbytes);
296  v->spl_right = (OffsetNumber *) palloc(nbytes);
297  v->spl_nleft = 0;
298  v->spl_nright = 0;
299  array = (RIX *) palloc(sizeof(RIX) * (maxoff + 1));
300 
301  /* copy the data into RIXes, and sort the RIXes */
302  for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
303  {
304  array[j].index = j;
305  lu = GETENTRY(entryvec, j); /* use as tmp val */
306  array[j].r = LTG_GETLNODE(lu);
307  }
308 
309  qsort((void *) &array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1,
310  sizeof(RIX), treekey_cmp);
311 
312  lu_l = lu_r = ru_l = ru_r = NULL;
313  for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
314  {
315  lu = GETENTRY(entryvec, array[j].index); /* use as tmp val */
316  if (j <= (maxoff - FirstOffsetNumber + 1) / 2)
317  {
318  v->spl_left[v->spl_nleft] = array[j].index;
319  v->spl_nleft++;
320  if (lu_r == NULL || ltree_compare(LTG_GETRNODE(lu), lu_r) > 0)
321  lu_r = LTG_GETRNODE(lu);
322  if (LTG_ISONENODE(lu))
323  hashing(ls, LTG_NODE(lu));
324  else
325  {
326  if (lisat || LTG_ISALLTRUE(lu))
327  lisat = true;
328  else
329  {
330  BITVECP sc = LTG_SIGN(lu);
331 
332  LOOPBYTE
333  ((unsigned char *) ls)[i] |= sc[i];
334  }
335  }
336  }
337  else
338  {
339  v->spl_right[v->spl_nright] = array[j].index;
340  v->spl_nright++;
341  if (ru_r == NULL || ltree_compare(LTG_GETRNODE(lu), ru_r) > 0)
342  ru_r = LTG_GETRNODE(lu);
343  if (LTG_ISONENODE(lu))
344  hashing(rs, LTG_NODE(lu));
345  else
346  {
347  if (risat || LTG_ISALLTRUE(lu))
348  risat = true;
349  else
350  {
351  BITVECP sc = LTG_SIGN(lu);
352 
353  LOOPBYTE
354  ((unsigned char *) rs)[i] |= sc[i];
355  }
356  }
357  }
358  }
359 
360  if (lisat == false)
361  {
362  lisat = true;
363  LOOPBYTE
364  {
365  if (((unsigned char *) ls)[i] != 0xff)
366  {
367  lisat = false;
368  break;
369  }
370  }
371  }
372 
373  if (risat == false)
374  {
375  risat = true;
376  LOOPBYTE
377  {
378  if (((unsigned char *) rs)[i] != 0xff)
379  {
380  risat = false;
381  break;
382  }
383  }
384  }
385 
386  lu_l = LTG_GETLNODE(GETENTRY(entryvec, array[FirstOffsetNumber].index));
387  isleqr = (lu_l == lu_r || ISEQ(lu_l, lu_r)) ? true : false;
388  size = LTG_HDRSIZE + ((lisat) ? 0 : SIGLEN) + VARSIZE(lu_l) + ((isleqr) ? 0 : VARSIZE(lu_r));
389  lu = (ltree_gist *) palloc0(size);
390  SET_VARSIZE(lu, size);
391  lu->flag = 0;
392  if (lisat)
393  lu->flag |= LTG_ALLTRUE;
394  else
395  memcpy((void *) LTG_SIGN(lu), ls, SIGLEN);
396  memcpy((void *) LTG_LNODE(lu), (void *) lu_l, VARSIZE(lu_l));
397  if (isleqr)
398  lu->flag |= LTG_NORIGHT;
399  else
400  memcpy((void *) LTG_RNODE(lu), (void *) lu_r, VARSIZE(lu_r));
401 
402 
403  ru_l = LTG_GETLNODE(GETENTRY(entryvec, array[1 + ((maxoff - FirstOffsetNumber + 1) / 2)].index));
404  isleqr = (ru_l == ru_r || ISEQ(ru_l, ru_r)) ? true : false;
405  size = LTG_HDRSIZE + ((risat) ? 0 : SIGLEN) + VARSIZE(ru_l) + ((isleqr) ? 0 : VARSIZE(ru_r));
406  ru = (ltree_gist *) palloc0(size);
407  SET_VARSIZE(ru, size);
408  ru->flag = 0;
409  if (risat)
410  ru->flag |= LTG_ALLTRUE;
411  else
412  memcpy((void *) LTG_SIGN(ru), rs, SIGLEN);
413  memcpy((void *) LTG_LNODE(ru), (void *) ru_l, VARSIZE(ru_l));
414  if (isleqr)
415  ru->flag |= LTG_NORIGHT;
416  else
417  memcpy((void *) LTG_RNODE(ru), (void *) ru_r, VARSIZE(ru_r));
418 
419  v->spl_ldatum = PointerGetDatum(lu);
420  v->spl_rdatum = PointerGetDatum(ru);
421 
423 }
424 
425 static bool
427 {
428  int32 numlevel = query->numlevel;
429  int i;
430 
431  for (i = query->numlevel; i >= 0; i--)
432  {
433  query->numlevel = i;
434  if (ltree_compare(query, LTG_GETLNODE(key)) >= 0 && ltree_compare(query, LTG_GETRNODE(key)) <= 0)
435  {
436  query->numlevel = numlevel;
437  return true;
438  }
439  }
440 
441  query->numlevel = numlevel;
442  return false;
443 }
444 
445 static ltree *
447 {
448  ltree *dst = (ltree *) palloc0(VARSIZE(src));
449 
450  memcpy(dst, src, VARSIZE(src));
451  return dst;
452 }
453 
454 static bool
456 {
457  ltree *left = copy_ltree(LTG_GETLNODE(key));
458  ltree *right = copy_ltree(LTG_GETRNODE(key));
459  bool res = true;
460 
461  if (left->numlevel > query->numlevel)
462  left->numlevel = query->numlevel;
463 
464  if (ltree_compare(query, left) < 0)
465  res = false;
466 
467  if (right->numlevel > query->numlevel)
468  right->numlevel = query->numlevel;
469 
470  if (res && ltree_compare(query, right) > 0)
471  res = false;
472 
473  pfree(left);
474  pfree(right);
475 
476  return res;
477 }
478 
479 static bool
480 gist_qe(ltree_gist *key, lquery *query)
481 {
482  lquery_level *curq = LQUERY_FIRST(query);
483  BITVECP sign = LTG_SIGN(key);
484  int qlen = query->numlevel;
485 
486  if (LTG_ISALLTRUE(key))
487  return true;
488 
489  while (qlen > 0)
490  {
491  if (curq->numvar && LQL_CANLOOKSIGN(curq))
492  {
493  bool isexist = false;
494  int vlen = curq->numvar;
495  lquery_variant *curv = LQL_FIRST(curq);
496 
497  while (vlen > 0)
498  {
499  if (GETBIT(sign, HASHVAL(curv->val)))
500  {
501  isexist = true;
502  break;
503  }
504  curv = LVAR_NEXT(curv);
505  vlen--;
506  }
507  if (!isexist)
508  return false;
509  }
510 
511  curq = LQL_NEXT(curq);
512  qlen--;
513  }
514 
515  return true;
516 }
517 
518 static int
520 {
521  ltree_level *al = LTREE_FIRST(t);
522  lquery_level *ql = LQUERY_FIRST(q);
523  lquery_variant *bl;
524  int an = t->numlevel;
525  int bn = q->firstgood;
526  int res = 0;
527 
528  while (an > 0 && bn > 0)
529  {
530  bl = LQL_FIRST(ql);
531  if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
532  {
533  if (al->len != bl->len)
534  return al->len - bl->len;
535  }
536  else
537  return res;
538  an--;
539  bn--;
540  al = LEVEL_NEXT(al);
541  ql = LQL_NEXT(ql);
542  }
543 
544  return Min(t->numlevel, q->firstgood) - q->firstgood;
545 }
546 
547 static bool
549 {
550  if (query->firstgood == 0)
551  return true;
552 
553  if (gist_tqcmp(LTG_GETLNODE(key), query) > 0)
554  return false;
555 
556  if (gist_tqcmp(LTG_GETRNODE(key), query) < 0)
557  return false;
558 
559  return true;
560 }
561 
562 static bool
563 checkcondition_bit(void *checkval, ITEM *val)
564 {
565  return (FLG_CANLOOKSIGN(val->flag)) ? GETBIT(checkval, HASHVAL(val->val)) : true;
566 }
567 
568 static bool
570 {
571  if (LTG_ISALLTRUE(key))
572  return true;
573 
574  return ltree_execute(
575  GETQUERY(query),
576  (void *) LTG_SIGN(key), false,
578  );
579 }
580 
581 static bool
583 {
584  lquery *query = (lquery *) ARR_DATA_PTR(_query);
585  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
586 
587  if (ARR_NDIM(_query) > 1)
588  ereport(ERROR,
589  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
590  errmsg("array must be one-dimensional")));
591  if (array_contains_nulls(_query))
592  ereport(ERROR,
593  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
594  errmsg("array must not contain nulls")));
595 
596  while (num > 0)
597  {
598  if (gist_qe(key, query) && gist_between(key, query))
599  return true;
600  num--;
601  query = NEXTVAL(query);
602  }
603  return false;
604 }
605 
606 Datum
608 {
609  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
611 
612  /* Oid subtype = PG_GETARG_OID(3); */
613  bool *recheck = (bool *) PG_GETARG_POINTER(4);
614  ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
615  void *query = NULL;
616  bool res = false;
617 
618  /* All cases served by this function are exact */
619  *recheck = false;
620 
621  switch (strategy)
622  {
624  query = PG_GETARG_LTREE(1);
625  res = (GIST_LEAF(entry)) ?
626  (ltree_compare((ltree *) query, LTG_NODE(key)) > 0)
627  :
628  (ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0);
629  break;
631  query = PG_GETARG_LTREE(1);
632  res = (ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0);
633  break;
635  query = PG_GETARG_LTREE(1);
636  if (GIST_LEAF(entry))
637  res = (ltree_compare((ltree *) query, LTG_NODE(key)) == 0);
638  else
639  res = (
640  ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0
641  &&
642  ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0
643  );
644  break;
646  query = PG_GETARG_LTREE(1);
647  res = (ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0);
648  break;
650  query = PG_GETARG_LTREE(1);
651  res = (GIST_LEAF(entry)) ?
652  (ltree_compare((ltree *) query, LTG_GETRNODE(key)) < 0)
653  :
654  (ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0);
655  break;
656  case 10:
657  query = PG_GETARG_LTREE_COPY(1);
658  res = (GIST_LEAF(entry)) ?
659  inner_isparent((ltree *) query, LTG_NODE(key))
660  :
661  gist_isparent(key, (ltree *) query);
662  break;
663  case 11:
664  query = PG_GETARG_LTREE(1);
665  res = (GIST_LEAF(entry)) ?
666  inner_isparent(LTG_NODE(key), (ltree *) query)
667  :
668  gist_ischild(key, (ltree *) query);
669  break;
670  case 12:
671  case 13:
672  query = PG_GETARG_LQUERY(1);
673  if (GIST_LEAF(entry))
676  PointerGetDatum((lquery *) query)
677  ));
678  else
679  res = (gist_qe(key, (lquery *) query) && gist_between(key, (lquery *) query));
680  break;
681  case 14:
682  case 15:
683  query = PG_GETARG_LQUERY(1);
684  if (GIST_LEAF(entry))
687  PointerGetDatum((lquery *) query)
688  ));
689  else
690  res = gist_qtxt(key, (ltxtquery *) query);
691  break;
692  case 16:
693  case 17:
695  if (GIST_LEAF(entry))
698  PointerGetDatum((ArrayType *) query)
699  ));
700  else
701  res = arrq_cons(key, (ArrayType *) query);
702  break;
703  default:
704  /* internal error */
705  elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
706  }
707 
708  PG_FREE_IF_COPY(query, 1);
709  PG_RETURN_BOOL(res);
710 }
uint16 firstgood
Definition: ltree.h:73
#define GIST_LEAF(entry)
Definition: gist.h:133
Relation rel
Definition: gist.h:124
static void hashing(BITVECP sign, ltree *t)
Definition: ltree_gist.c:135
Definition: _int.h:125
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Datum ltree_same(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:91
ltree * r
Definition: ltree_gist.c:255
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:13
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
Datum ltree_consistent(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:607
Datum ltree_gist_out(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:28
Datum ltree_compress(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:48
#define LQUERY_FIRST(x)
Definition: ltree.h:79
uint16 len
Definition: ltree.h:35
uint16 len
Definition: ltree.h:12
#define LTG_ISALLTRUE(x)
Definition: ltree.h:222
#define VARSIZE(PTR)
Definition: postgres.h:304
#define PointerGetDatum(X)
Definition: postgres.h:562
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:136
Definition: ltree.h:69
#define LTG_SIGN(x)
Definition: ltree.h:219
Datum ltree_picksplit(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:269
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:37
uint32 flag
Definition: ltree.h:210
#define Min(x, y)
Definition: c.h:806
#define LQL_FIRST(x)
Definition: ltree.h:59
#define LQL_NEXT(x)
Definition: ltree.h:58
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
static bool gist_ischild(ltree_gist *key, ltree *query)
Definition: ltree_gist.c:455
OffsetNumber * spl_left
Definition: gist.h:105
Datum spl_rdatum
Definition: gist.h:112
int32 n
Definition: gist.h:160
struct cursor * cur
Definition: ecpg.c:28
uint16 StrategyNumber
Definition: stratnum.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
#define LTG_NODE(x)
Definition: ltree.h:220
#define LTG_RNODE(x)
Definition: ltree.h:226
#define MemSet(start, val, len)
Definition: c.h:857
return result
Definition: formatting.c:1632
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define HASH(sign, val)
Definition: hstore_gist.c:38
#define LTG_NORIGHT
Definition: ltree.h:216
int spl_nleft
Definition: gist.h:106
uint8 flag
Definition: ltree.h:96
#define LVAR_NEXT(x)
Definition: ltree.h:41
unsigned int ltree_crc32_sz(char *buf, int size)
Definition: crc32.c:23
#define GETQUERY(x)
Definition: _int.h:142
static bool gist_isparent(ltree_gist *key, ltree *query)
Definition: ltree_gist.c:426
signed int int32
Definition: c.h:256
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
uint16 OffsetNumber
Definition: off.h:24
Page page
Definition: gist.h:125
Definition: type.h:90
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
void pfree(void *pointer)
Definition: mcxt.c:950
#define GETBIT(x, i)
Definition: blutils.c:34
static bool arrq_cons(ltree_gist *key, ArrayType *_query)
Definition: ltree_gist.c:582
#define ERROR
Definition: elog.h:43
Datum ltree_gist_in(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:19
static ltree * copy_ltree(ltree *src)
Definition: ltree_gist.c:446
#define LTG_GETRNODE(x)
Definition: ltree.h:229
#define FALSE
Definition: c.h:221
int spl_nright
Definition: gist.h:111
#define ARR_DIMS(a)
Definition: array.h:275
#define LTG_GETLNODE(x)
Definition: ltree.h:228
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:303
char BITVEC[SIGLEN]
Definition: hstore_gist.c:19
char sign
Definition: informix.c:693
Datum key
Definition: gist.h:123
#define ARR_DATA_PTR(a)
Definition: array.h:303
#define PG_GETARG_LQUERY(x)
Definition: ltree.h:170
static int gist_tqcmp(ltree *t, lquery *q)
Definition: ltree_gist.c:519
#define FirstOffsetNumber
Definition: off.h:27
#define LTG_ALLTRUE
Definition: ltree.h:215
struct rix RIX
#define DatumGetBool(X)
Definition: postgres.h:399
static int treekey_cmp(const void *a, const void *b)
Definition: ltree_gist.c:259
Datum ltree_union(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:151
int32 val
Definition: _int.h:129
#define HASHVAL(val)
Definition: hstore_gist.c:37
#define LEVEL_NEXT(x)
Definition: ltree.h:17
#define ereport(elevel, rest)
Definition: elog.h:122
#define GETENTRY(vec, pos)
Definition: ltree_gist.c:45
Definition: ltree.h:19
bool leafkey
Definition: gist.h:127
Datum lt_q_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:339
#define ISEQ(a, b)
Definition: ltree_gist.c:44
uint16 numlevel
Definition: ltree.h:22
static bool gist_qe(ltree_gist *key, lquery *query)
Definition: ltree_gist.c:480
void * palloc0(Size size)
Definition: mcxt.c:878
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Datum ltree_penalty(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:235
static bool gist_between(ltree_gist *key, lquery *query)
Definition: ltree_gist.c:548
int32 val
Definition: ltree.h:34
#define LTG_LNODE(x)
Definition: ltree.h:224
#define Max(x, y)
Definition: c.h:800
#define LTG_ISONENODE(x)
Definition: ltree.h:221
Datum spl_ldatum
Definition: gist.h:107
#define NULL
Definition: c.h:229
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
uint16 numlevel
Definition: ltree.h:72
#define NEXTVAL(x)
Definition: ltree_gist.c:13
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:87
uint16 numvar
Definition: ltree.h:51
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
#define newval
OffsetNumber * spl_right
Definition: gist.h:110
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define FLG_CANLOOKSIGN(x)
Definition: ltree.h:65
#define ARR_NDIM(a)
Definition: array.h:271
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
PG_FUNCTION_INFO_V1(ltree_gist_in)
#define LOOPBYTE
Definition: hstore_gist.c:25
#define LTREE_FIRST(x)
Definition: ltree.h:27
static bool gist_qtxt(ltree_gist *key, ltxtquery *query)
Definition: ltree_gist.c:569
int i
#define SIGLEN
Definition: hstore_gist.c:16
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:205
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
#define PG_GETARG_LTREE_COPY(x)
Definition: ltree.h:169
#define LTG_ONENODE
Definition: ltree.h:214
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
char * BITVECP
Definition: hstore_gist.c:20
#define elog
Definition: elog.h:219
#define qsort(a, b, c, d)
Definition: port.h:440
#define LTG_HDRSIZE
Definition: ltree.h:218
#define BTLessStrategyNumber
Definition: stratnum.h:29
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3542
OffsetNumber offset
Definition: gist.h:126
static unsigned hash(unsigned *uv, int n)
Definition: rege_dfa.c:541
Datum ltree_decompress(PG_FUNCTION_ARGS)
Definition: ltree_gist.c:73
int index
Definition: ltree_gist.c:254
long val
Definition: informix.c:689
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32
#define LQL_CANLOOKSIGN(x)
Definition: ltree.h:67
static bool checkcondition_bit(void *checkval, ITEM *val)
Definition: ltree_gist.c:563