PostgreSQL Source Code  git master
tsgistidx.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * tsgistidx.c
4  * GiST support functions for tsvector_ops
5  *
6  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
7  *
8  *
9  * IDENTIFICATION
10  * src/backend/utils/adt/tsgistidx.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres.h"
16 
17 #include "access/gist.h"
18 #include "access/heaptoast.h"
19 #include "lib/qunique.h"
20 #include "port/pg_bitutils.h"
21 #include "tsearch/ts_utils.h"
22 #include "utils/builtins.h"
23 #include "utils/pg_crc.h"
24 
25 
26 #define SIGLENINT 31 /* >121 => key will toast, so it will not work
27  * !!! */
28 
29 #define SIGLEN ( sizeof(int32) * SIGLENINT )
30 #define SIGLENBIT (SIGLEN * BITS_PER_BYTE)
31 
32 typedef char BITVEC[SIGLEN];
33 typedef char *BITVECP;
34 
35 #define LOOPBYTE \
36  for(i=0;i<SIGLEN;i++)
37 
38 #define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
39 #define GETBITBYTE(x,i) ( ((char)(x)) >> (i) & 0x01 )
40 #define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
41 #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
42 #define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
43 
44 #define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
45 #define HASH(sign, val) SETBIT((sign), HASHVAL(val))
46 
47 #define GETENTRY(vec,pos) ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))
48 
49 /*
50  * type of GiST index key
51  */
52 
53 typedef struct
54 {
55  int32 vl_len_; /* varlena header (do not touch directly!) */
57  char data[FLEXIBLE_ARRAY_MEMBER];
58 } SignTSVector;
59 
60 #define ARRKEY 0x01
61 #define SIGNKEY 0x02
62 #define ALLISTRUE 0x04
63 
64 #define ISARRKEY(x) ( ((SignTSVector*)(x))->flag & ARRKEY )
65 #define ISSIGNKEY(x) ( ((SignTSVector*)(x))->flag & SIGNKEY )
66 #define ISALLTRUE(x) ( ((SignTSVector*)(x))->flag & ALLISTRUE )
67 
68 #define GTHDRSIZE ( VARHDRSZ + sizeof(int32) )
69 #define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
70 
71 #define GETSIGN(x) ( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
72 #define GETARR(x) ( (int32*)( (char*)(x)+GTHDRSIZE ) )
73 #define ARRNELEM(x) ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )
74 
76 
77 Datum
79 {
80  ereport(ERROR,
81  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
82  errmsg("gtsvector_in not implemented")));
83  PG_RETURN_DATUM(0);
84 }
85 
86 #define SINGOUTSTR "%d true bits, %d false bits"
87 #define ARROUTSTR "%d unique words"
88 #define EXTRALEN ( 2*13 )
89 
90 static int outbuf_maxlen = 0;
91 
92 Datum
94 {
96  char *outbuf;
97 
98  if (outbuf_maxlen == 0)
99  outbuf_maxlen = 2 * EXTRALEN + Max(strlen(SINGOUTSTR), strlen(ARROUTSTR)) + 1;
100  outbuf = palloc(outbuf_maxlen);
101 
102  if (ISARRKEY(key))
103  sprintf(outbuf, ARROUTSTR, (int) ARRNELEM(key));
104  else
105  {
106  int cnttrue = (ISALLTRUE(key)) ? SIGLENBIT : sizebitvec(GETSIGN(key));
107 
108  sprintf(outbuf, SINGOUTSTR, cnttrue, (int) SIGLENBIT - cnttrue);
109  }
110 
111  PG_FREE_IF_COPY(key, 0);
112  PG_RETURN_POINTER(outbuf);
113 }
114 
115 static int
116 compareint(const void *va, const void *vb)
117 {
118  int32 a = *((const int32 *) va);
119  int32 b = *((const int32 *) vb);
120 
121  if (a == b)
122  return 0;
123  return (a > b) ? 1 : -1;
124 }
125 
126 static void
128 {
129  int32 k,
130  len = ARRNELEM(a);
131  int32 *ptr = GETARR(a);
132 
133  MemSet((void *) sign, 0, sizeof(BITVEC));
134  for (k = 0; k < len; k++)
135  HASH(sign, ptr[k]);
136 }
137 
138 Datum
140 {
141  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
142  GISTENTRY *retval = entry;
143 
144  if (entry->leafkey)
145  { /* tsvector */
146  SignTSVector *res;
147  TSVector val = DatumGetTSVector(entry->key);
148  int32 len;
149  int32 *arr;
150  WordEntry *ptr = ARRPTR(val);
151  char *words = STRPTR(val);
152 
153  len = CALCGTSIZE(ARRKEY, val->size);
154  res = (SignTSVector *) palloc(len);
155  SET_VARSIZE(res, len);
156  res->flag = ARRKEY;
157  arr = GETARR(res);
158  len = val->size;
159  while (len--)
160  {
161  pg_crc32 c;
162 
164  COMP_LEGACY_CRC32(c, words + ptr->pos, ptr->len);
165  FIN_LEGACY_CRC32(c);
166 
167  *arr = *(int32 *) &c;
168  arr++;
169  ptr++;
170  }
171 
172  qsort(GETARR(res), val->size, sizeof(int), compareint);
173  len = qunique(GETARR(res), val->size, sizeof(int), compareint);
174  if (len != val->size)
175  {
176  /*
177  * there is a collision of hash-function; len is always less than
178  * val->size
179  */
180  len = CALCGTSIZE(ARRKEY, len);
181  res = (SignTSVector *) repalloc((void *) res, len);
182  SET_VARSIZE(res, len);
183  }
184 
185  /* make signature, if array is too long */
186  if (VARSIZE(res) > TOAST_INDEX_TARGET)
187  {
188  SignTSVector *ressign;
189 
190  len = CALCGTSIZE(SIGNKEY, 0);
191  ressign = (SignTSVector *) palloc(len);
192  SET_VARSIZE(ressign, len);
193  ressign->flag = SIGNKEY;
194  makesign(GETSIGN(ressign), res);
195  res = ressign;
196  }
197 
198  retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
199  gistentryinit(*retval, PointerGetDatum(res),
200  entry->rel, entry->page,
201  entry->offset, false);
202  }
203  else if (ISSIGNKEY(DatumGetPointer(entry->key)) &&
204  !ISALLTRUE(DatumGetPointer(entry->key)))
205  {
206  int32 i,
207  len;
208  SignTSVector *res;
210 
211  LOOPBYTE
212  {
213  if ((sign[i] & 0xff) != 0xff)
214  PG_RETURN_POINTER(retval);
215  }
216 
217  len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
218  res = (SignTSVector *) palloc(len);
219  SET_VARSIZE(res, len);
220  res->flag = SIGNKEY | ALLISTRUE;
221 
222  retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
223  gistentryinit(*retval, PointerGetDatum(res),
224  entry->rel, entry->page,
225  entry->offset, false);
226  }
227  PG_RETURN_POINTER(retval);
228 }
229 
230 Datum
232 {
233  /*
234  * We need to detoast the stored value, because the other gtsvector
235  * support functions don't cope with toasted values.
236  */
237  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
239 
240  if (key != (SignTSVector *) DatumGetPointer(entry->key))
241  {
242  GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
243 
244  gistentryinit(*retval, PointerGetDatum(key),
245  entry->rel, entry->page,
246  entry->offset, false);
247 
248  PG_RETURN_POINTER(retval);
249  }
250 
251  PG_RETURN_POINTER(entry);
252 }
253 
254 typedef struct
255 {
256  int32 *arrb;
257  int32 *arre;
258 } CHKVAL;
259 
260 /*
261  * is there value 'val' in array or not ?
262  */
263 static bool
265 {
266  int32 *StopLow = ((CHKVAL *) checkval)->arrb;
267  int32 *StopHigh = ((CHKVAL *) checkval)->arre;
268  int32 *StopMiddle;
269 
270  /* Loop invariant: StopLow <= val < StopHigh */
271 
272  /*
273  * we are not able to find a prefix by hash value
274  */
275  if (val->prefix)
276  return true;
277 
278  while (StopLow < StopHigh)
279  {
280  StopMiddle = StopLow + (StopHigh - StopLow) / 2;
281  if (*StopMiddle == val->valcrc)
282  return true;
283  else if (*StopMiddle < val->valcrc)
284  StopLow = StopMiddle + 1;
285  else
286  StopHigh = StopMiddle;
287  }
288 
289  return false;
290 }
291 
292 static bool
294 {
295  /*
296  * we are not able to find a prefix in signature tree
297  */
298  if (val->prefix)
299  return true;
300  return GETBIT(checkval, HASHVAL(val->valcrc));
301 }
302 
303 Datum
305 {
306  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
307  TSQuery query = PG_GETARG_TSQUERY(1);
308 
309  /* StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); */
310  /* Oid subtype = PG_GETARG_OID(3); */
311  bool *recheck = (bool *) PG_GETARG_POINTER(4);
313 
314  /* All cases served by this function are inexact */
315  *recheck = true;
316 
317  if (!query->size)
318  PG_RETURN_BOOL(false);
319 
320  if (ISSIGNKEY(key))
321  {
322  if (ISALLTRUE(key))
323  PG_RETURN_BOOL(true);
324 
325  /* since signature is lossy, cannot specify CALC_NOT here */
327  (void *) GETSIGN(key),
330  }
331  else
332  { /* only leaf pages */
333  CHKVAL chkval;
334 
335  chkval.arrb = GETARR(key);
336  chkval.arre = chkval.arrb + ARRNELEM(key);
338  (void *) &chkval,
341  }
342 }
343 
344 static int32
346 {
347  int32 i;
348 
349  if (ISSIGNKEY(add))
350  {
351  BITVECP sadd = GETSIGN(add);
352 
353  if (ISALLTRUE(add))
354  return 1;
355 
356  LOOPBYTE
357  sbase[i] |= sadd[i];
358  }
359  else
360  {
361  int32 *ptr = GETARR(add);
362 
363  for (i = 0; i < ARRNELEM(add); i++)
364  HASH(sbase, ptr[i]);
365  }
366  return 0;
367 }
368 
369 
370 Datum
372 {
374  int *size = (int *) PG_GETARG_POINTER(1);
375  BITVEC base;
376  int32 i,
377  len;
378  int32 flag = 0;
379  SignTSVector *result;
380 
381  MemSet((void *) base, 0, sizeof(BITVEC));
382  for (i = 0; i < entryvec->n; i++)
383  {
384  if (unionkey(base, GETENTRY(entryvec, i)))
385  {
386  flag = ALLISTRUE;
387  break;
388  }
389  }
390 
391  flag |= SIGNKEY;
392  len = CALCGTSIZE(flag, 0);
393  result = (SignTSVector *) palloc(len);
394  *size = len;
395  SET_VARSIZE(result, len);
396  result->flag = flag;
397  if (!ISALLTRUE(result))
398  memcpy((void *) GETSIGN(result), (void *) base, sizeof(BITVEC));
399 
400  PG_RETURN_POINTER(result);
401 }
402 
403 Datum
405 {
408  bool *result = (bool *) PG_GETARG_POINTER(2);
409 
410  if (ISSIGNKEY(a))
411  { /* then b also ISSIGNKEY */
412  if (ISALLTRUE(a) && ISALLTRUE(b))
413  *result = true;
414  else if (ISALLTRUE(a))
415  *result = false;
416  else if (ISALLTRUE(b))
417  *result = false;
418  else
419  {
420  int32 i;
421  BITVECP sa = GETSIGN(a),
422  sb = GETSIGN(b);
423 
424  *result = true;
425  LOOPBYTE
426  {
427  if (sa[i] != sb[i])
428  {
429  *result = false;
430  break;
431  }
432  }
433  }
434  }
435  else
436  { /* a and b ISARRKEY */
437  int32 lena = ARRNELEM(a),
438  lenb = ARRNELEM(b);
439 
440  if (lena != lenb)
441  *result = false;
442  else
443  {
444  int32 *ptra = GETARR(a),
445  *ptrb = GETARR(b);
446  int32 i;
447 
448  *result = true;
449  for (i = 0; i < lena; i++)
450  if (ptra[i] != ptrb[i])
451  {
452  *result = false;
453  break;
454  }
455  }
456  }
457 
458  PG_RETURN_POINTER(result);
459 }
460 
461 static int32
463 {
464  return pg_popcount(sign, SIGLEN);
465 }
466 
467 static int
469 {
470  int i,
471  diff,
472  dist = 0;
473 
474  LOOPBYTE
475  {
476  diff = (unsigned char) (a[i] ^ b[i]);
477  /* Using the popcount functions here isn't likely to win */
478  dist += pg_number_of_ones[diff];
479  }
480  return dist;
481 }
482 
483 static int
485 {
486  if (ISALLTRUE(a))
487  {
488  if (ISALLTRUE(b))
489  return 0;
490  else
491  return SIGLENBIT - sizebitvec(GETSIGN(b));
492  }
493  else if (ISALLTRUE(b))
494  return SIGLENBIT - sizebitvec(GETSIGN(a));
495 
496  return hemdistsign(GETSIGN(a), GETSIGN(b));
497 }
498 
499 Datum
501 {
502  GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */
503  GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
504  float *penalty = (float *) PG_GETARG_POINTER(2);
505  SignTSVector *origval = (SignTSVector *) DatumGetPointer(origentry->key);
507  BITVECP orig = GETSIGN(origval);
508 
509  *penalty = 0.0;
510 
511  if (ISARRKEY(newval))
512  {
513  BITVEC sign;
514 
515  makesign(sign, newval);
516 
517  if (ISALLTRUE(origval))
518  *penalty = ((float) (SIGLENBIT - sizebitvec(sign))) / (float) (SIGLENBIT + 1);
519  else
520  *penalty = hemdistsign(sign, orig);
521  }
522  else
523  *penalty = hemdist(origval, newval);
524  PG_RETURN_POINTER(penalty);
525 }
526 
527 typedef struct
528 {
529  bool allistrue;
530  BITVEC sign;
531 } CACHESIGN;
532 
533 static void
535 {
536  item->allistrue = false;
537  if (ISARRKEY(key))
538  makesign(item->sign, key);
539  else if (ISALLTRUE(key))
540  item->allistrue = true;
541  else
542  memcpy((void *) item->sign, (void *) GETSIGN(key), sizeof(BITVEC));
543 }
544 
545 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
546 typedef struct
547 {
548  OffsetNumber pos;
549  int32 cost;
550 } SPLITCOST;
551 
552 static int
553 comparecost(const void *va, const void *vb)
554 {
555  const SPLITCOST *a = (const SPLITCOST *) va;
556  const SPLITCOST *b = (const SPLITCOST *) vb;
557 
558  if (a->cost == b->cost)
559  return 0;
560  else
561  return (a->cost > b->cost) ? 1 : -1;
562 }
563 
564 
565 static int
567 {
568  if (a->allistrue)
569  {
570  if (b->allistrue)
571  return 0;
572  else
573  return SIGLENBIT - sizebitvec(b->sign);
574  }
575  else if (b->allistrue)
576  return SIGLENBIT - sizebitvec(a->sign);
577 
578  return hemdistsign(a->sign, b->sign);
579 }
580 
581 Datum
583 {
586  OffsetNumber k,
587  j;
588  SignTSVector *datum_l,
589  *datum_r;
590  BITVECP union_l,
591  union_r;
592  int32 size_alpha,
593  size_beta;
594  int32 size_waste,
595  waste = -1;
596  int32 nbytes;
597  OffsetNumber seed_1 = 0,
598  seed_2 = 0;
599  OffsetNumber *left,
600  *right;
601  OffsetNumber maxoff;
602  BITVECP ptr;
603  int i;
604  CACHESIGN *cache;
605  SPLITCOST *costvector;
606 
607  maxoff = entryvec->n - 2;
608  nbytes = (maxoff + 2) * sizeof(OffsetNumber);
609  v->spl_left = (OffsetNumber *) palloc(nbytes);
610  v->spl_right = (OffsetNumber *) palloc(nbytes);
611 
612  cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2));
613  fillcache(&cache[FirstOffsetNumber], GETENTRY(entryvec, FirstOffsetNumber));
614 
615  for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
616  {
617  for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
618  {
619  if (k == FirstOffsetNumber)
620  fillcache(&cache[j], GETENTRY(entryvec, j));
621 
622  size_waste = hemdistcache(&(cache[j]), &(cache[k]));
623  if (size_waste > waste)
624  {
625  waste = size_waste;
626  seed_1 = k;
627  seed_2 = j;
628  }
629  }
630  }
631 
632  left = v->spl_left;
633  v->spl_nleft = 0;
634  right = v->spl_right;
635  v->spl_nright = 0;
636 
637  if (seed_1 == 0 || seed_2 == 0)
638  {
639  seed_1 = 1;
640  seed_2 = 2;
641  }
642 
643  /* form initial .. */
644  if (cache[seed_1].allistrue)
645  {
646  datum_l = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
647  SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
648  datum_l->flag = SIGNKEY | ALLISTRUE;
649  }
650  else
651  {
652  datum_l = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY, 0));
653  SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY, 0));
654  datum_l->flag = SIGNKEY;
655  memcpy((void *) GETSIGN(datum_l), (void *) cache[seed_1].sign, sizeof(BITVEC));
656  }
657  if (cache[seed_2].allistrue)
658  {
659  datum_r = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
660  SET_VARSIZE(datum_r, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
661  datum_r->flag = SIGNKEY | ALLISTRUE;
662  }
663  else
664  {
665  datum_r = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY, 0));
666  SET_VARSIZE(datum_r, CALCGTSIZE(SIGNKEY, 0));
667  datum_r->flag = SIGNKEY;
668  memcpy((void *) GETSIGN(datum_r), (void *) cache[seed_2].sign, sizeof(BITVEC));
669  }
670 
671  union_l = GETSIGN(datum_l);
672  union_r = GETSIGN(datum_r);
673  maxoff = OffsetNumberNext(maxoff);
674  fillcache(&cache[maxoff], GETENTRY(entryvec, maxoff));
675  /* sort before ... */
676  costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
677  for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
678  {
679  costvector[j - 1].pos = j;
680  size_alpha = hemdistcache(&(cache[seed_1]), &(cache[j]));
681  size_beta = hemdistcache(&(cache[seed_2]), &(cache[j]));
682  costvector[j - 1].cost = Abs(size_alpha - size_beta);
683  }
684  qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
685 
686  for (k = 0; k < maxoff; k++)
687  {
688  j = costvector[k].pos;
689  if (j == seed_1)
690  {
691  *left++ = j;
692  v->spl_nleft++;
693  continue;
694  }
695  else if (j == seed_2)
696  {
697  *right++ = j;
698  v->spl_nright++;
699  continue;
700  }
701 
702  if (ISALLTRUE(datum_l) || cache[j].allistrue)
703  {
704  if (ISALLTRUE(datum_l) && cache[j].allistrue)
705  size_alpha = 0;
706  else
707  size_alpha = SIGLENBIT - sizebitvec(
708  (cache[j].allistrue) ? GETSIGN(datum_l) : GETSIGN(cache[j].sign)
709  );
710  }
711  else
712  size_alpha = hemdistsign(cache[j].sign, GETSIGN(datum_l));
713 
714  if (ISALLTRUE(datum_r) || cache[j].allistrue)
715  {
716  if (ISALLTRUE(datum_r) && cache[j].allistrue)
717  size_beta = 0;
718  else
719  size_beta = SIGLENBIT - sizebitvec(
720  (cache[j].allistrue) ? GETSIGN(datum_r) : GETSIGN(cache[j].sign)
721  );
722  }
723  else
724  size_beta = hemdistsign(cache[j].sign, GETSIGN(datum_r));
725 
726  if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.1))
727  {
728  if (ISALLTRUE(datum_l) || cache[j].allistrue)
729  {
730  if (!ISALLTRUE(datum_l))
731  MemSet((void *) GETSIGN(datum_l), 0xff, sizeof(BITVEC));
732  }
733  else
734  {
735  ptr = cache[j].sign;
736  LOOPBYTE
737  union_l[i] |= ptr[i];
738  }
739  *left++ = j;
740  v->spl_nleft++;
741  }
742  else
743  {
744  if (ISALLTRUE(datum_r) || cache[j].allistrue)
745  {
746  if (!ISALLTRUE(datum_r))
747  MemSet((void *) GETSIGN(datum_r), 0xff, sizeof(BITVEC));
748  }
749  else
750  {
751  ptr = cache[j].sign;
752  LOOPBYTE
753  union_r[i] |= ptr[i];
754  }
755  *right++ = j;
756  v->spl_nright++;
757  }
758  }
759 
760  *right = *left = FirstOffsetNumber;
761  v->spl_ldatum = PointerGetDatum(datum_l);
762  v->spl_rdatum = PointerGetDatum(datum_r);
763 
765 }
766 
767 /*
768  * Formerly, gtsvector_consistent was declared in pg_proc.h with arguments
769  * that did not match the documented conventions for GiST support functions.
770  * We fixed that, but we still need a pg_proc entry with the old signature
771  * to support reloading pre-9.6 contrib/tsearch2 opclass declarations.
772  * This compatibility function should go away eventually.
773  */
774 Datum
776 {
777  return gtsvector_consistent(fcinfo);
778 }
Relation rel
Definition: gist.h:132
static int hemdist(SignTSVector *a, SignTSVector *b)
Definition: tsgistidx.c:484
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
Definition: tsvector_op.c:1771
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
OffsetNumber pos
Definition: hstore_gist.c:319
#define INIT_LEGACY_CRC32(crc)
Definition: pg_crc.h:79
static int compareint(const void *va, const void *vb)
Definition: tsgistidx.c:116
Datum gtsvector_penalty(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:500
#define GETARR(x)
Definition: tsgistidx.c:72
static bool checkcondition_bit(void *checkval, QueryOperand *val, ExecPhraseData *data)
Definition: tsgistidx.c:293
#define TS_EXEC_CALC_NOT
Definition: ts_utils.h:183
Datum gtsvector_same(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:404
#define ISARRKEY(x)
Definition: tsgistidx.c:64
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_TSQUERY(n)
Definition: ts_type.h:238
#define SIGLEN
Definition: tsgistidx.c:29
OffsetNumber * spl_left
Definition: gist.h:113
Datum spl_rdatum
Definition: gist.h:120
int32 n
Definition: gist.h:206
uint32 len
Definition: ts_type.h:44
int errcode(int sqlerrcode)
Definition: elog.c:608
#define MemSet(start, val, len)
Definition: c.h:962
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
int spl_nleft
Definition: gist.h:114
char * BITVECP
Definition: tsgistidx.c:33
static int comparecost(const void *va, const void *vb)
Definition: tsgistidx.c:553
#define GETQUERY(x)
Definition: _int.h:136
#define FIN_LEGACY_CRC32(crc)
Definition: pg_crc.h:80
#define LOOPBYTE
Definition: tsgistidx.c:35
signed int int32
Definition: c.h:347
uint64 pg_popcount(const char *buf, int bytes)
Definition: pg_bitutils.c:282
int32 cost
Definition: hstore_gist.c:320
uint16 OffsetNumber
Definition: off.h:24
Page page
Definition: gist.h:133
#define Abs(x)
Definition: c.h:917
int32 * arrb
Definition: _int_bool.c:227
#define WISH_F(a, b, c)
Definition: tsgistidx.c:545
#define sprintf
Definition: port.h:194
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:468
#define TOAST_INDEX_TARGET
Definition: heaptoast.h:68
#define ERROR
Definition: elog.h:43
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:127
#define CALCGTSIZE(flag, len)
Definition: tsgistidx.c:69
int spl_nright
Definition: gist.h:119
BITVEC sign
Definition: trgm_gist.c:709
char sign
Definition: informix.c:668
Datum key
Definition: gist.h:131
char * c
#define FirstOffsetNumber
Definition: off.h:27
char * flag(int b)
Definition: test-ctype.c:33
int32 size
Definition: ts_type.h:93
int32 valcrc
Definition: ts_type.h:151
int32 flag
Definition: tsgistidx.c:56
#define GETBIT(x, i)
Definition: tsgistidx.c:42
#define ARRKEY
Definition: tsgistidx.c:60
#define GETENTRY(vec, pos)
Definition: tsgistidx.c:47
#define DatumGetTSVector(X)
Definition: ts_type.h:117
#define SINGOUTSTR
Definition: tsgistidx.c:86
#define ereport(elevel, rest)
Definition: elog.h:141
static bool checkcondition_arr(void *checkval, QueryOperand *val, ExecPhraseData *data)
Definition: tsgistidx.c:264
bool leafkey
Definition: gist.h:135
#define ARROUTSTR
Definition: tsgistidx.c:87
Datum gtsvector_union(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:371
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
uintptr_t Datum
Definition: postgres.h:367
char BITVEC[SIGLEN]
Definition: tsgistidx.c:32
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
static int hemdistcache(CACHESIGN *a, CACHESIGN *b)
Definition: tsgistidx.c:566
#define EXTRALEN
Definition: tsgistidx.c:88
Datum gtsvector_consistent_oldsig(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:775
#define Max(x, y)
Definition: c.h:905
Datum spl_ldatum
Definition: gist.h:115
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:215
#define TS_EXEC_PHRASE_NO_POS
Definition: ts_utils.h:190
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
#define HASHVAL(val)
Definition: tsgistidx.c:44
#define newval
Datum gtsvector_consistent(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:304
#define ARRNELEM(x)
Definition: tsgistidx.c:73
OffsetNumber * spl_right
Definition: gist.h:118
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition: qunique.h:21
Datum gtsvectorout(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:93
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
uint32 pos
Definition: ts_type.h:44
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1069
#define SIGNKEY
Definition: tsgistidx.c:61
#define DatumGetPointer(X)
Definition: postgres.h:549
PGDLLIMPORT const uint8 pg_number_of_ones[256]
Definition: pg_bitutils.c:87
#define SIGLENBIT
Definition: tsgistidx.c:30
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
int32 * arre
Definition: _int_bool.c:228
#define STRPTR(x)
Definition: hstore.h:76
Datum gtsvector_picksplit(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:582
int32 size
Definition: ts_type.h:208
#define COMP_LEGACY_CRC32(crc, data, len)
Definition: pg_crc.h:81
int i
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:462
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:235
#define PG_FUNCTION_ARGS
Definition: fmgr.h:188
bool prefix
Definition: ts_type.h:150
#define HASH(sign, val)
Definition: tsgistidx.c:45
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * BITVECP
Definition: hstore_gist.c:19
uint32 pg_crc32
Definition: pg_crc.h:37
#define ARRPTR(x)
Definition: cube.c:24
bool allistrue
Definition: trgm_gist.c:708
#define qsort(a, b, c, d)
Definition: port.h:488
static int32 unionkey(BITVECP sbase, SignTSVector *add)
Definition: tsgistidx.c:345
OffsetNumber offset
Definition: gist.h:134
#define ISSIGNKEY(x)
Definition: tsgistidx.c:65
Datum gtsvector_compress(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:139
#define ALLISTRUE
Definition: tsgistidx.c:62
long val
Definition: informix.c:664
Datum gtsvector_decompress(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:231
static void fillcache(CACHESIGN *item, SignTSVector *key)
Definition: tsgistidx.c:534
static int outbuf_maxlen
Definition: tsgistidx.c:90
Datum gtsvectorin(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:78
int32 vl_len_
Definition: tsgistidx.c:55