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