24 #include "utils/fmgrprotos.h"
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 : \
41 #define SIGLENBIT(siglen) ((siglen) * BITS_PER_BYTE)
45 #define LOOPBYTE(siglen) \
46 for (i = 0; i < siglen; i++)
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 )
54 #define HASHVAL(val, siglen) (((unsigned int)(val)) % SIGLENBIT(siglen))
55 #define HASH(sign, val, siglen) SETBIT((sign), HASHVAL(val, siglen))
57 #define GETENTRY(vec,pos) ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))
72 #define ALLISTRUE 0x04
74 #define ISARRKEY(x) ( ((SignTSVector*)(x))->flag & ARRKEY )
75 #define ISSIGNKEY(x) ( ((SignTSVector*)(x))->flag & SIGNKEY )
76 #define ISALLTRUE(x) ( ((SignTSVector*)(x))->flag & ALLISTRUE )
78 #define GTHDRSIZE ( VARHDRSZ + sizeof(int32) )
79 #define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : (len)) ) )
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) )
93 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
94 errmsg(
"cannot accept a value of type %s",
"gtsvector")));
110 outbuf =
pstrdup(
"all true bits");
116 outbuf =
psprintf(
"%d true bits, %d false bits",
117 cnttrue, (
int)
SIGLENBIT(siglen) - cnttrue);
142 for (k = 0; k <
len; k++)
229 if ((
sign[
i] & 0xff) != 0xff)
290 while (StopLow < StopHigh)
292 StopMiddle = StopLow + (StopHigh - StopLow) / 2;
293 if (*StopMiddle ==
val->valcrc)
295 else if (*StopMiddle < val->valcrc)
296 StopLow = StopMiddle + 1;
298 StopHigh = StopMiddle;
386 HASH(sbase, ptr[
i], siglen);
402 memset(base, 0, siglen);
404 for (
i = 0;
i < entryvec->
n;
i++)
468 for (
i = 0;
i < lena;
i++)
469 if (ptra[
i] != ptrb[
i])
495 diff = (
unsigned char) (
a[
i] ^
b[
i]);
518 Assert(siglena == siglenb);
548 (
float) (siglenbit + 1);
578 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
605 else if (
b->allistrue)
639 maxoff = entryvec->
n - 2;
645 cache_sign =
palloc(siglen * (maxoff + 2));
647 for (
j = 0;
j < maxoff + 2;
j++)
648 cache[
j].
sign = &cache_sign[siglen *
j];
661 if (size_waste > waste)
675 if (seed_1 == 0 || seed_2 == 0)
683 siglen, cache[seed_1].
sign);
685 siglen, cache[seed_2].
sign);
694 costvector[
j - 1].
pos =
j;
695 size_alpha =
hemdistcache(&(cache[seed_1]), &(cache[
j]), siglen);
696 size_beta =
hemdistcache(&(cache[seed_2]), &(cache[
j]), siglen);
697 costvector[
j - 1].
cost = abs(size_alpha - size_beta);
701 for (k = 0; k < maxoff; k++)
703 j = costvector[k].
pos;
710 else if (
j == seed_2)
750 memset(
GETSIGN(datum_l), 0xff, siglen);
756 union_l[
i] |= ptr[
i];
766 memset(
GETSIGN(datum_r), 0xff, siglen);
772 union_r[
i] |= ptr[
i];
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_DATUM(n)
#define PG_DETOAST_DATUM(datum)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
#define gistentryinit(e, k, r, pg, o, l)
#define TOAST_INDEX_TARGET
static int pg_cmp_s32(int32 a, int32 b)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * repalloc(void *pointer, Size size)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
PGDLLIMPORT const uint8 pg_number_of_ones[256]
static uint64 pg_popcount(const char *buf, int bytes)
#define INIT_LEGACY_CRC32(crc)
#define COMP_LEGACY_CRC32(crc, data, len)
#define FIN_LEGACY_CRC32(crc)
#define qsort(a, b, c, d)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
char * psprintf(const char *fmt,...)
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)
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)
static pg_noinline void Size size
static TSVector DatumGetTSVector(Datum X)
#define PG_GETARG_TSQUERY(n)
#define TS_EXEC_PHRASE_NO_POS
static int32 unionkey(BITVECP sbase, SignTSVector *add, int siglen)
#define HASHVAL(val, siglen)
static int hemdistcache(CACHESIGN *a, CACHESIGN *b, int siglen)
Datum gtsvector_penalty(PG_FUNCTION_ARGS)
static int hemdist(SignTSVector *a, SignTSVector *b)
static TSTernaryValue checkcondition_arr(void *checkval, QueryOperand *val, ExecPhraseData *data)
static int32 sizebitvec(BITVECP sign, int siglen)
static int hemdistsign(BITVECP a, BITVECP b, int siglen)
Datum gtsvector_same(PG_FUNCTION_ARGS)
static SignTSVector * gtsvector_alloc(int flag, int len, BITVECP sign)
#define GETENTRY(vec, pos)
Datum gtsvector_picksplit(PG_FUNCTION_ARGS)
static void fillcache(CACHESIGN *item, SignTSVector *key, int siglen)
static int comparecost(const void *va, const void *vb)
Datum gtsvectorin(PG_FUNCTION_ARGS)
Datum gtsvector_compress(PG_FUNCTION_ARGS)
#define CALCGTSIZE(flag, len)
Datum gtsvector_decompress(PG_FUNCTION_ARGS)
Datum gtsvector_consistent(PG_FUNCTION_ARGS)
static void makesign(BITVECP sign, SignTSVector *a, int siglen)
Datum gtsvector_options(PG_FUNCTION_ARGS)
Datum gtsvector_union(PG_FUNCTION_ARGS)
Datum gtsvectorout(PG_FUNCTION_ARGS)
#define SIGLENBIT(siglen)
static int compareint(const void *va, const void *vb)
static TSTernaryValue checkcondition_bit(void *checkval, QueryOperand *val, ExecPhraseData *data)
#define HASH(sign, val, siglen)
Datum gtsvector_consistent_oldsig(PG_FUNCTION_ARGS)
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
#define SET_VARSIZE(PTR, len)