PostgreSQL Source Code  git master
tsgistidx.c File Reference
#include "postgres.h"
#include "access/gist.h"
#include "access/heaptoast.h"
#include "lib/qunique.h"
#include "port/pg_bitutils.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/pg_crc.h"
Include dependency graph for tsgistidx.c:

Go to the source code of this file.

Data Structures

struct  SignTSVector
 
struct  CHKVAL
 
struct  CACHESIGN
 
struct  SPLITCOST
 

Macros

#define SIGLENINT
 
#define SIGLEN   ( sizeof(int32) * SIGLENINT )
 
#define SIGLENBIT   (SIGLEN * BITS_PER_BYTE)
 
#define LOOPBYTE   for(i=0;i<SIGLEN;i++)
 
#define GETBYTE(x, i)   ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
 
#define GETBITBYTE(x, i)   ( ((char)(x)) >> (i) & 0x01 )
 
#define CLRBIT(x, i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
 
#define SETBIT(x, i)   GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
 
#define GETBIT(x, i)   ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
 
#define HASHVAL(val)   (((unsigned int)(val)) % SIGLENBIT)
 
#define HASH(sign, val)   SETBIT((sign), HASHVAL(val))
 
#define GETENTRY(vec, pos)   ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))
 
#define ARRKEY   0x01
 
#define SIGNKEY   0x02
 
#define ALLISTRUE   0x04
 
#define ISARRKEY(x)   ( ((SignTSVector*)(x))->flag & ARRKEY )
 
#define ISSIGNKEY(x)   ( ((SignTSVector*)(x))->flag & SIGNKEY )
 
#define ISALLTRUE(x)   ( ((SignTSVector*)(x))->flag & ALLISTRUE )
 
#define GTHDRSIZE   ( VARHDRSZ + sizeof(int32) )
 
#define CALCGTSIZE(flag, len)   ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
 
#define GETSIGN(x)   ( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
 
#define GETARR(x)   ( (int32*)( (char*)(x)+GTHDRSIZE ) )
 
#define ARRNELEM(x)   ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )
 
#define SINGOUTSTR   "%d true bits, %d false bits"
 
#define ARROUTSTR   "%d unique words"
 
#define EXTRALEN   ( 2*13 )
 
#define WISH_F(a, b, c)   (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
 

Typedefs

typedef char BITVEC[SIGLEN]
 
typedef char * BITVECP
 

Functions

static int32 sizebitvec (BITVECP sign)
 
Datum gtsvectorin (PG_FUNCTION_ARGS)
 
Datum gtsvectorout (PG_FUNCTION_ARGS)
 
static int compareint (const void *va, const void *vb)
 
static void makesign (BITVECP sign, SignTSVector *a)
 
Datum gtsvector_compress (PG_FUNCTION_ARGS)
 
Datum gtsvector_decompress (PG_FUNCTION_ARGS)
 
static bool checkcondition_arr (void *checkval, QueryOperand *val, ExecPhraseData *data)
 
static bool checkcondition_bit (void *checkval, QueryOperand *val, ExecPhraseData *data)
 
Datum gtsvector_consistent (PG_FUNCTION_ARGS)
 
static int32 unionkey (BITVECP sbase, SignTSVector *add)
 
Datum gtsvector_union (PG_FUNCTION_ARGS)
 
Datum gtsvector_same (PG_FUNCTION_ARGS)
 
static int hemdistsign (BITVECP a, BITVECP b)
 
static int hemdist (SignTSVector *a, SignTSVector *b)
 
Datum gtsvector_penalty (PG_FUNCTION_ARGS)
 
static void fillcache (CACHESIGN *item, SignTSVector *key)
 
static int comparecost (const void *va, const void *vb)
 
static int hemdistcache (CACHESIGN *a, CACHESIGN *b)
 
Datum gtsvector_picksplit (PG_FUNCTION_ARGS)
 
Datum gtsvector_consistent_oldsig (PG_FUNCTION_ARGS)
 

Variables

static int outbuf_maxlen = 0
 

Macro Definition Documentation

◆ ALLISTRUE

#define ALLISTRUE   0x04

Definition at line 62 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_picksplit(), and gtsvector_union().

◆ ARRKEY

#define ARRKEY   0x01

Definition at line 60 of file tsgistidx.c.

Referenced by gtsvector_compress().

◆ ARRNELEM

#define ARRNELEM (   x)    ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )

Definition at line 73 of file tsgistidx.c.

Referenced by gtsvector_consistent(), gtsvector_same(), gtsvectorout(), makesign(), and unionkey().

◆ ARROUTSTR

#define ARROUTSTR   "%d unique words"

Definition at line 87 of file tsgistidx.c.

Referenced by gtsvectorout().

◆ CALCGTSIZE

#define CALCGTSIZE (   flag,
  len 
)    ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )

Definition at line 69 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_picksplit(), and gtsvector_union().

◆ CLRBIT

#define CLRBIT (   x,
  i 
)    GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )

Definition at line 40 of file tsgistidx.c.

◆ EXTRALEN

#define EXTRALEN   ( 2*13 )

Definition at line 88 of file tsgistidx.c.

Referenced by gtsvectorout().

◆ GETARR

#define GETARR (   x)    ( (int32*)( (char*)(x)+GTHDRSIZE ) )

◆ GETBIT

#define GETBIT (   x,
  i 
)    ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )

Definition at line 42 of file tsgistidx.c.

Referenced by checkcondition_bit().

◆ GETBITBYTE

#define GETBITBYTE (   x,
  i 
)    ( ((char)(x)) >> (i) & 0x01 )

Definition at line 39 of file tsgistidx.c.

◆ GETBYTE

#define GETBYTE (   x,
  i 
)    ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )

Definition at line 38 of file tsgistidx.c.

◆ GETENTRY

#define GETENTRY (   vec,
  pos 
)    ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))

Definition at line 47 of file tsgistidx.c.

Referenced by gtsvector_picksplit(), and gtsvector_union().

◆ GETSIGN

◆ GTHDRSIZE

#define GTHDRSIZE   ( VARHDRSZ + sizeof(int32) )

Definition at line 68 of file tsgistidx.c.

◆ HASH

#define HASH (   sign,
  val 
)    SETBIT((sign), HASHVAL(val))

Definition at line 45 of file tsgistidx.c.

Referenced by makesign(), and unionkey().

◆ HASHVAL

#define HASHVAL (   val)    (((unsigned int)(val)) % SIGLENBIT)

Definition at line 44 of file tsgistidx.c.

Referenced by checkcondition_bit().

◆ ISALLTRUE

◆ ISARRKEY

#define ISARRKEY (   x)    ( ((SignTSVector*)(x))->flag & ARRKEY )

Definition at line 64 of file tsgistidx.c.

Referenced by fillcache(), gtsvector_penalty(), and gtsvectorout().

◆ ISSIGNKEY

#define ISSIGNKEY (   x)    ( ((SignTSVector*)(x))->flag & SIGNKEY )

Definition at line 65 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_consistent(), gtsvector_same(), and unionkey().

◆ LOOPBYTE

#define LOOPBYTE   for(i=0;i<SIGLEN;i++)

◆ SETBIT

#define SETBIT (   x,
  i 
)    GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )

Definition at line 41 of file tsgistidx.c.

◆ SIGLEN

#define SIGLEN   ( sizeof(int32) * SIGLENINT )

Definition at line 29 of file tsgistidx.c.

Referenced by sizebitvec().

◆ SIGLENBIT

#define SIGLENBIT   (SIGLEN * BITS_PER_BYTE)

◆ SIGLENINT

#define SIGLENINT
Value:
31 /* >121 => key will toast, so it will not work
* !!! */

Definition at line 26 of file tsgistidx.c.

◆ SIGNKEY

#define SIGNKEY   0x02

Definition at line 61 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_picksplit(), and gtsvector_union().

◆ SINGOUTSTR

#define SINGOUTSTR   "%d true bits, %d false bits"

Definition at line 86 of file tsgistidx.c.

Referenced by gtsvectorout().

◆ WISH_F

#define WISH_F (   a,
  b,
  c 
)    (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )

Definition at line 545 of file tsgistidx.c.

Referenced by gtsvector_picksplit().

Typedef Documentation

◆ BITVEC

typedef char BITVEC[SIGLEN]

Definition at line 32 of file tsgistidx.c.

◆ BITVECP

typedef char* BITVECP

Definition at line 33 of file tsgistidx.c.

Function Documentation

◆ checkcondition_arr()

static bool checkcondition_arr ( void *  checkval,
QueryOperand val,
ExecPhraseData data 
)
static

Definition at line 264 of file tsgistidx.c.

References QueryOperand::prefix, and QueryOperand::valcrc.

Referenced by gtsvector_consistent().

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 }
signed int int32
Definition: c.h:347
int32 valcrc
Definition: ts_type.h:151
bool prefix
Definition: ts_type.h:150

◆ checkcondition_bit()

static bool checkcondition_bit ( void *  checkval,
QueryOperand val,
ExecPhraseData data 
)
static

Definition at line 293 of file tsgistidx.c.

References GETBIT, HASHVAL, QueryOperand::prefix, and QueryOperand::valcrc.

Referenced by gtsvector_consistent().

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 }
int32 valcrc
Definition: ts_type.h:151
#define GETBIT(x, i)
Definition: tsgistidx.c:42
#define HASHVAL(val)
Definition: tsgistidx.c:44
bool prefix
Definition: ts_type.h:150

◆ comparecost()

static int comparecost ( const void *  va,
const void *  vb 
)
static

Definition at line 553 of file tsgistidx.c.

References SPLITCOST::cost.

Referenced by gtsvector_picksplit().

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 }
int32 cost
Definition: hstore_gist.c:320

◆ compareint()

static int compareint ( const void *  va,
const void *  vb 
)
static

Definition at line 116 of file tsgistidx.c.

Referenced by gtsvector_compress().

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 }
signed int int32
Definition: c.h:347

◆ fillcache()

static void fillcache ( CACHESIGN item,
SignTSVector key 
)
static

Definition at line 534 of file tsgistidx.c.

References CACHESIGN::allistrue, GETSIGN, ISALLTRUE, ISARRKEY, makesign(), and CACHESIGN::sign.

Referenced by gtsvector_picksplit().

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 }
#define ISARRKEY(x)
Definition: tsgistidx.c:64
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:127
BITVEC sign
Definition: trgm_gist.c:709
char BITVEC[SIGLEN]
Definition: tsgistidx.c:32
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
bool allistrue
Definition: trgm_gist.c:708

◆ gtsvector_compress()

Datum gtsvector_compress ( PG_FUNCTION_ARGS  )

Definition at line 139 of file tsgistidx.c.

References ALLISTRUE, ARRKEY, ARRPTR, CALCGTSIZE, COMP_LEGACY_CRC32, compareint(), DatumGetPointer, DatumGetTSVector, FIN_LEGACY_CRC32, SignTSVector::flag, GETARR, GETSIGN, gistentryinit, i, INIT_LEGACY_CRC32, ISALLTRUE, ISSIGNKEY, GISTENTRY::key, GISTENTRY::leafkey, WordEntry::len, LOOPBYTE, makesign(), GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, WordEntry::pos, qsort, qunique(), GISTENTRY::rel, repalloc(), SET_VARSIZE, sign, SIGNKEY, TSVectorData::size, STRPTR, TOAST_INDEX_TARGET, val, and VARSIZE.

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 }
Relation rel
Definition: gist.h:132
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define INIT_LEGACY_CRC32(crc)
Definition: pg_crc.h:79
static int compareint(const void *va, const void *vb)
Definition: tsgistidx.c:116
#define GETARR(x)
Definition: tsgistidx.c:72
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
uint32 len
Definition: ts_type.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define FIN_LEGACY_CRC32(crc)
Definition: pg_crc.h:80
#define LOOPBYTE
Definition: tsgistidx.c:35
signed int int32
Definition: c.h:347
Page page
Definition: gist.h:133
#define TOAST_INDEX_TARGET
Definition: heaptoast.h:68
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:127
#define CALCGTSIZE(flag, len)
Definition: tsgistidx.c:69
char sign
Definition: informix.c:668
Datum key
Definition: gist.h:131
char * c
int32 size
Definition: ts_type.h:93
int32 flag
Definition: tsgistidx.c:56
#define ARRKEY
Definition: tsgistidx.c:60
#define DatumGetTSVector(X)
Definition: ts_type.h:117
bool leafkey
Definition: gist.h:135
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:215
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition: qunique.h:21
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
void * palloc(Size size)
Definition: mcxt.c:949
#define STRPTR(x)
Definition: hstore.h:76
#define COMP_LEGACY_CRC32(crc, data, len)
Definition: pg_crc.h:81
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
#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
#define qsort(a, b, c, d)
Definition: port.h:491
OffsetNumber offset
Definition: gist.h:134
#define ISSIGNKEY(x)
Definition: tsgistidx.c:65
#define ALLISTRUE
Definition: tsgistidx.c:62
long val
Definition: informix.c:664

◆ gtsvector_consistent()

Datum gtsvector_consistent ( PG_FUNCTION_ARGS  )

Definition at line 304 of file tsgistidx.c.

References CHKVAL::arrb, CHKVAL::arre, ARRNELEM, checkcondition_arr(), checkcondition_bit(), DatumGetPointer, GETARR, GETQUERY, GETSIGN, ISALLTRUE, ISSIGNKEY, sort-test::key, GISTENTRY::key, PG_GETARG_POINTER, PG_GETARG_TSQUERY, PG_RETURN_BOOL, TSQueryData::size, TS_EXEC_CALC_NOT, TS_EXEC_PHRASE_NO_POS, and TS_execute().

Referenced by gtsvector_consistent_oldsig().

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 }
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
Definition: tsvector_op.c:1767
#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
#define PG_GETARG_TSQUERY(n)
Definition: ts_type.h:238
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define GETQUERY(x)
Definition: _int.h:136
int32 * arrb
Definition: _int_bool.c:227
Datum key
Definition: gist.h:131
static bool checkcondition_arr(void *checkval, QueryOperand *val, ExecPhraseData *data)
Definition: tsgistidx.c:264
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define TS_EXEC_PHRASE_NO_POS
Definition: ts_utils.h:190
#define ARRNELEM(x)
Definition: tsgistidx.c:73
#define DatumGetPointer(X)
Definition: postgres.h:549
int32 * arre
Definition: _int_bool.c:228
int32 size
Definition: ts_type.h:208
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
#define ISSIGNKEY(x)
Definition: tsgistidx.c:65

◆ gtsvector_consistent_oldsig()

Datum gtsvector_consistent_oldsig ( PG_FUNCTION_ARGS  )

Definition at line 775 of file tsgistidx.c.

References gtsvector_consistent().

776 {
777  return gtsvector_consistent(fcinfo);
778 }
Datum gtsvector_consistent(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:304

◆ gtsvector_decompress()

Datum gtsvector_decompress ( PG_FUNCTION_ARGS  )

Definition at line 231 of file tsgistidx.c.

References DatumGetPointer, gistentryinit, sort-test::key, GISTENTRY::key, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_DETOAST_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, and GISTENTRY::rel.

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 }
Relation rel
Definition: gist.h:132
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
Page page
Definition: gist.h:133
Datum key
Definition: gist.h:131
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:215
#define DatumGetPointer(X)
Definition: postgres.h:549
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:235
OffsetNumber offset
Definition: gist.h:134

◆ gtsvector_penalty()

Datum gtsvector_penalty ( PG_FUNCTION_ARGS  )

Definition at line 500 of file tsgistidx.c.

References DatumGetPointer, GETSIGN, hemdist(), hemdistsign(), ISALLTRUE, ISARRKEY, GISTENTRY::key, makesign(), newval, PG_GETARG_POINTER, PG_RETURN_POINTER, SIGLENBIT, sign, and sizebitvec().

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 }
static int hemdist(SignTSVector *a, SignTSVector *b)
Definition: tsgistidx.c:484
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define ISARRKEY(x)
Definition: tsgistidx.c:64
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:468
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:127
char sign
Definition: informix.c:668
Datum key
Definition: gist.h:131
char BITVEC[SIGLEN]
Definition: tsgistidx.c:32
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define newval
#define DatumGetPointer(X)
Definition: postgres.h:549
#define SIGLENBIT
Definition: tsgistidx.c:30
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:462
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
char * BITVECP
Definition: hstore_gist.c:19

◆ gtsvector_picksplit()

Datum gtsvector_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 582 of file tsgistidx.c.

References Abs, ALLISTRUE, CALCGTSIZE, comparecost(), SPLITCOST::cost, fillcache(), FirstOffsetNumber, SignTSVector::flag, GETENTRY, GETSIGN, hemdistcache(), hemdistsign(), i, ISALLTRUE, LOOPBYTE, MemSet, GistEntryVector::n, OffsetNumberNext, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, SPLITCOST::pos, qsort, SET_VARSIZE, SIGLENBIT, sign, CACHESIGN::sign, SIGNKEY, sizebitvec(), GIST_SPLITVEC::spl_ldatum, GIST_SPLITVEC::spl_left, GIST_SPLITVEC::spl_nleft, GIST_SPLITVEC::spl_nright, GIST_SPLITVEC::spl_rdatum, GIST_SPLITVEC::spl_right, and WISH_F.

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((cache[j].allistrue) ?
708  GETSIGN(datum_l) :
709  GETSIGN(cache[j].sign));
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((cache[j].allistrue) ?
720  GETSIGN(datum_r) :
721  GETSIGN(cache[j].sign));
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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
OffsetNumber pos
Definition: hstore_gist.c:319
#define PointerGetDatum(X)
Definition: postgres.h:556
OffsetNumber * spl_left
Definition: gist.h:113
Datum spl_rdatum
Definition: gist.h:120
int32 n
Definition: gist.h:206
#define MemSet(start, val, len)
Definition: c.h:972
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
int spl_nleft
Definition: gist.h:114
static int comparecost(const void *va, const void *vb)
Definition: tsgistidx.c:553
#define LOOPBYTE
Definition: tsgistidx.c:35
signed int int32
Definition: c.h:347
int32 cost
Definition: hstore_gist.c:320
uint16 OffsetNumber
Definition: off.h:24
#define Abs(x)
Definition: c.h:927
#define WISH_F(a, b, c)
Definition: tsgistidx.c:545
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:468
#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
#define FirstOffsetNumber
Definition: off.h:27
int32 flag
Definition: tsgistidx.c:56
#define GETENTRY(vec, pos)
Definition: tsgistidx.c:47
char BITVEC[SIGLEN]
Definition: tsgistidx.c:32
static int hemdistcache(CACHESIGN *a, CACHESIGN *b)
Definition: tsgistidx.c:566
Datum spl_ldatum
Definition: gist.h:115
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
OffsetNumber * spl_right
Definition: gist.h:118
#define SIGNKEY
Definition: tsgistidx.c:61
#define SIGLENBIT
Definition: tsgistidx.c:30
void * palloc(Size size)
Definition: mcxt.c:949
int i
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:462
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * BITVECP
Definition: hstore_gist.c:19
#define qsort(a, b, c, d)
Definition: port.h:491
#define ALLISTRUE
Definition: tsgistidx.c:62
static void fillcache(CACHESIGN *item, SignTSVector *key)
Definition: tsgistidx.c:534

◆ gtsvector_same()

Datum gtsvector_same ( PG_FUNCTION_ARGS  )

Definition at line 404 of file tsgistidx.c.

References ARRNELEM, GETARR, GETSIGN, i, ISALLTRUE, ISSIGNKEY, LOOPBYTE, PG_GETARG_POINTER, and PG_RETURN_POINTER.

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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define GETARR(x)
Definition: tsgistidx.c:72
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define LOOPBYTE
Definition: tsgistidx.c:35
signed int int32
Definition: c.h:347
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define ARRNELEM(x)
Definition: tsgistidx.c:73
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
char * BITVECP
Definition: hstore_gist.c:19
#define ISSIGNKEY(x)
Definition: tsgistidx.c:65

◆ gtsvector_union()

Datum gtsvector_union ( PG_FUNCTION_ARGS  )

Definition at line 371 of file tsgistidx.c.

References ALLISTRUE, CALCGTSIZE, flag(), SignTSVector::flag, GETENTRY, GETSIGN, i, ISALLTRUE, MemSet, GistEntryVector::n, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, SET_VARSIZE, SIGNKEY, and unionkey().

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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
int32 n
Definition: gist.h:206
#define MemSet(start, val, len)
Definition: c.h:972
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
signed int int32
Definition: c.h:347
#define CALCGTSIZE(flag, len)
Definition: tsgistidx.c:69
char * flag(int b)
Definition: test-ctype.c:33
int32 flag
Definition: tsgistidx.c:56
#define GETENTRY(vec, pos)
Definition: tsgistidx.c:47
char BITVEC[SIGLEN]
Definition: tsgistidx.c:32
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define SIGNKEY
Definition: tsgistidx.c:61
void * palloc(Size size)
Definition: mcxt.c:949
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
static int32 unionkey(BITVECP sbase, SignTSVector *add)
Definition: tsgistidx.c:345
#define ALLISTRUE
Definition: tsgistidx.c:62

◆ gtsvectorin()

Datum gtsvectorin ( PG_FUNCTION_ARGS  )

Definition at line 78 of file tsgistidx.c.

References ereport, errcode(), errmsg(), ERROR, and PG_RETURN_DATUM.

79 {
80  ereport(ERROR,
81  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
82  errmsg("gtsvector_in not implemented")));
83  PG_RETURN_DATUM(0);
84 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ gtsvectorout()

Datum gtsvectorout ( PG_FUNCTION_ARGS  )

Definition at line 93 of file tsgistidx.c.

References ARRNELEM, ARROUTSTR, EXTRALEN, GETSIGN, ISALLTRUE, ISARRKEY, sort-test::key, Max, outbuf_maxlen, palloc(), PG_DETOAST_DATUM, PG_FREE_IF_COPY, PG_GETARG_POINTER, PG_RETURN_POINTER, SIGLENBIT, SINGOUTSTR, sizebitvec(), and sprintf.

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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define ISARRKEY(x)
Definition: tsgistidx.c:64
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define sprintf
Definition: port.h:194
#define SINGOUTSTR
Definition: tsgistidx.c:86
#define ARROUTSTR
Definition: tsgistidx.c:87
#define EXTRALEN
Definition: tsgistidx.c:88
#define Max(x, y)
Definition: c.h:915
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define ARRNELEM(x)
Definition: tsgistidx.c:73
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define SIGLENBIT
Definition: tsgistidx.c:30
void * palloc(Size size)
Definition: mcxt.c:949
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
static int outbuf_maxlen
Definition: tsgistidx.c:90

◆ hemdist()

static int hemdist ( SignTSVector a,
SignTSVector b 
)
static

Definition at line 484 of file tsgistidx.c.

References GETSIGN, hemdistsign(), ISALLTRUE, SIGLENBIT, and sizebitvec().

Referenced by gtsvector_penalty().

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 }
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:468
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define SIGLENBIT
Definition: tsgistidx.c:30
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:462
#define ISALLTRUE(x)
Definition: tsgistidx.c:66

◆ hemdistcache()

static int hemdistcache ( CACHESIGN a,
CACHESIGN b 
)
static

Definition at line 566 of file tsgistidx.c.

References CACHESIGN::allistrue, hemdistsign(), SIGLENBIT, CACHESIGN::sign, and sizebitvec().

Referenced by gtsvector_picksplit().

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 }
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:468
BITVEC sign
Definition: trgm_gist.c:709
#define SIGLENBIT
Definition: tsgistidx.c:30
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:462
bool allistrue
Definition: trgm_gist.c:708

◆ hemdistsign()

static int hemdistsign ( BITVECP  a,
BITVECP  b 
)
static

Definition at line 468 of file tsgistidx.c.

References i, LOOPBYTE, and pg_number_of_ones.

Referenced by gtsvector_penalty(), gtsvector_picksplit(), hemdist(), and hemdistcache().

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 }
#define LOOPBYTE
Definition: tsgistidx.c:35
PGDLLIMPORT const uint8 pg_number_of_ones[256]
Definition: pg_bitutils.c:87
int i

◆ makesign()

static void makesign ( BITVECP  sign,
SignTSVector a 
)
static

Definition at line 127 of file tsgistidx.c.

References ARRNELEM, GETARR, HASH, and MemSet.

Referenced by fillcache(), gtsvector_compress(), and gtsvector_penalty().

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 }
#define GETARR(x)
Definition: tsgistidx.c:72
#define MemSet(start, val, len)
Definition: c.h:972
signed int int32
Definition: c.h:347
char sign
Definition: informix.c:668
char BITVEC[SIGLEN]
Definition: tsgistidx.c:32
#define ARRNELEM(x)
Definition: tsgistidx.c:73
#define HASH(sign, val)
Definition: tsgistidx.c:45

◆ sizebitvec()

static int32 sizebitvec ( BITVECP  sign)
static

Definition at line 462 of file tsgistidx.c.

References pg_popcount(), and SIGLEN.

Referenced by gtsvector_penalty(), gtsvector_picksplit(), gtsvectorout(), hemdist(), and hemdistcache().

463 {
464  return pg_popcount(sign, SIGLEN);
465 }
#define SIGLEN
Definition: tsgistidx.c:29
uint64 pg_popcount(const char *buf, int bytes)
Definition: pg_bitutils.c:282
char sign
Definition: informix.c:668

◆ unionkey()

static int32 unionkey ( BITVECP  sbase,
SignTSVector add 
)
static

Definition at line 345 of file tsgistidx.c.

References ARRNELEM, GETARR, GETSIGN, HASH, i, ISALLTRUE, ISSIGNKEY, and LOOPBYTE.

Referenced by gtsvector_union().

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 }
#define GETARR(x)
Definition: tsgistidx.c:72
#define LOOPBYTE
Definition: tsgistidx.c:35
signed int int32
Definition: c.h:347
#define GETSIGN(x)
Definition: tsgistidx.c:71
#define ARRNELEM(x)
Definition: tsgistidx.c:73
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:66
#define HASH(sign, val)
Definition: tsgistidx.c:45
char * BITVECP
Definition: hstore_gist.c:19
#define ISSIGNKEY(x)
Definition: tsgistidx.c:65

Variable Documentation

◆ outbuf_maxlen

int outbuf_maxlen = 0
static

Definition at line 90 of file tsgistidx.c.

Referenced by gtsvectorout().