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