PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_utils_var.h File Reference
#include "btree_gist.h"
#include "access/gist.h"
#include "mb/pg_wchar.h"
Include dependency graph for btree_utils_var.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GBT_VARKEY_R
 
struct  gbtree_vinfo
 

Typedefs

typedef bytea GBT_VARKEY
 

Functions

GBT_VARKEY_R gbt_var_key_readable (const GBT_VARKEY *k)
 
GBT_VARKEYgbt_var_key_copy (const GBT_VARKEY_R *u)
 
GISTENTRYgbt_var_compress (GISTENTRY *entry, const gbtree_vinfo *tinfo)
 
GBT_VARKEYgbt_var_union (const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
bool gbt_var_same (Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
float * gbt_var_penalty (float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
bool gbt_var_consistent (GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
GIST_SPLITVECgbt_var_picksplit (const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
void gbt_var_bin_union (Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 

Typedef Documentation

Definition at line 13 of file btree_utils_var.h.

Function Documentation

void gbt_var_bin_union ( Datum u,
GBT_VARKEY e,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 235 of file btree_utils_var.c.

References DatumGetPointer, gbtree_vinfo::f_cmp, gbt_var_key_copy(), gbt_var_key_readable(), gbt_var_leaf2node(), GBT_VARKEY_R::lower, PointerGetDatum, and GBT_VARKEY_R::upper.

Referenced by gbt_numeric_penalty(), gbt_var_penalty(), gbt_var_picksplit(), and gbt_var_union().

237 {
239  GBT_VARKEY_R nr;
240 
241  if (eo.lower == eo.upper) /* leaf */
242  {
243  GBT_VARKEY *tmp;
244 
245  tmp = gbt_var_leaf2node(e, tinfo, flinfo);
246  if (tmp != e)
247  eo = gbt_var_key_readable(tmp);
248  }
249 
250  if (DatumGetPointer(*u))
251  {
253  bool update = false;
254 
255  nr.lower = ro.lower;
256  nr.upper = ro.upper;
257 
258  if ((*tinfo->f_cmp) (ro.lower, eo.lower, collation, flinfo) > 0)
259  {
260  nr.lower = eo.lower;
261  update = true;
262  }
263 
264  if ((*tinfo->f_cmp) (ro.upper, eo.upper, collation, flinfo) < 0)
265  {
266  nr.upper = eo.upper;
267  update = true;
268  }
269 
270  if (update)
272  }
273  else
274  {
275  nr.lower = eo.lower;
276  nr.upper = eo.upper;
278  }
279 }
static GBT_VARKEY * gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PointerGetDatum(X)
Definition: postgres.h:562
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
#define DatumGetPointer(X)
Definition: postgres.h:555
Definition: c.h:439
GISTENTRY* gbt_var_compress ( GISTENTRY entry,
const gbtree_vinfo tinfo 
)

Definition at line 283 of file btree_utils_var.c.

References gbt_var_key_from_datum(), gistentryinit, GISTENTRY::key, GISTENTRY::leafkey, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_DETOAST_DATUM, PointerGetDatum, GISTENTRY::rel, and TRUE.

Referenced by gbt_bit_compress(), gbt_bpchar_compress(), gbt_bytea_compress(), gbt_numeric_compress(), and gbt_text_compress().

284 {
285  GISTENTRY *retval;
286 
287  if (entry->leafkey)
288  {
289  struct varlena *leaf = PG_DETOAST_DATUM(entry->key);
290  GBT_VARKEY *r;
291 
292  r = gbt_var_key_from_datum(leaf);
293 
294  retval = palloc(sizeof(GISTENTRY));
295  gistentryinit(*retval, PointerGetDatum(r),
296  entry->rel, entry->page,
297  entry->offset, TRUE);
298  }
299  else
300  retval = entry;
301 
302  return (retval);
303 }
Relation rel
Definition: gist.h:124
#define PointerGetDatum(X)
Definition: postgres.h:562
static GBT_VARKEY * gbt_var_key_from_datum(const struct varlena *u)
Page page
Definition: gist.h:125
Datum key
Definition: gist.h:123
bool leafkey
Definition: gist.h:127
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
void * palloc(Size size)
Definition: mcxt.c:849
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:197
Definition: c.h:439
#define TRUE
Definition: c.h:217
OffsetNumber offset
Definition: gist.h:126
bool gbt_var_consistent ( GBT_VARKEY_R key,
const void *  query,
StrategyNumber  strategy,
Oid  collation,
bool  is_leaf,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 556 of file btree_utils_var.c.

References BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, BtreeGistNotEqualStrategyNumber, gbtree_vinfo::f_cmp, gbtree_vinfo::f_eq, gbtree_vinfo::f_ge, gbtree_vinfo::f_gt, gbtree_vinfo::f_le, gbtree_vinfo::f_lt, FALSE, gbt_var_node_pf_match(), GBT_VARKEY_R::lower, and GBT_VARKEY_R::upper.

Referenced by gbt_bit_consistent(), gbt_bpchar_consistent(), gbt_bytea_consistent(), gbt_numeric_consistent(), and gbt_text_consistent().

563 {
564  bool retval = FALSE;
565 
566  switch (strategy)
567  {
569  if (is_leaf)
570  retval = (*tinfo->f_ge) (query, key->lower, collation, flinfo);
571  else
572  retval = (*tinfo->f_cmp) (query, key->lower, collation, flinfo) >= 0
573  || gbt_var_node_pf_match(key, query, tinfo);
574  break;
576  if (is_leaf)
577  retval = (*tinfo->f_gt) (query, key->lower, collation, flinfo);
578  else
579  retval = (*tinfo->f_cmp) (query, key->lower, collation, flinfo) >= 0
580  || gbt_var_node_pf_match(key, query, tinfo);
581  break;
583  if (is_leaf)
584  retval = (*tinfo->f_eq) (query, key->lower, collation, flinfo);
585  else
586  retval =
587  ((*tinfo->f_cmp) (key->lower, query, collation, flinfo) <= 0 &&
588  (*tinfo->f_cmp) (query, key->upper, collation, flinfo) <= 0) ||
589  gbt_var_node_pf_match(key, query, tinfo);
590  break;
592  if (is_leaf)
593  retval = (*tinfo->f_lt) (query, key->upper, collation, flinfo);
594  else
595  retval = (*tinfo->f_cmp) (query, key->upper, collation, flinfo) <= 0
596  || gbt_var_node_pf_match(key, query, tinfo);
597  break;
599  if (is_leaf)
600  retval = (*tinfo->f_le) (query, key->upper, collation, flinfo);
601  else
602  retval = (*tinfo->f_cmp) (query, key->upper, collation, flinfo) <= 0
603  || gbt_var_node_pf_match(key, query, tinfo);
604  break;
606  retval = !((*tinfo->f_eq) (query, key->lower, collation, flinfo) &&
607  (*tinfo->f_eq) (query, key->upper, collation, flinfo));
608  break;
609  default:
610  retval = FALSE;
611  }
612 
613  return retval;
614 }
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
static bool gbt_var_node_pf_match(const GBT_VARKEY_R *node, const bytea *query, const gbtree_vinfo *tinfo)
bool(* f_lt)(const void *, const void *, Oid, FmgrInfo *)
bool(* f_gt)(const void *, const void *, Oid, FmgrInfo *)
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
bool(* f_le)(const void *, const void *, Oid, FmgrInfo *)
bool(* f_ge)(const void *, const void *, Oid, FmgrInfo *)
#define FALSE
Definition: c.h:221
bool(* f_eq)(const void *, const void *, Oid, FmgrInfo *)
#define BtreeGistNotEqualStrategyNumber
Definition: btree_gist.h:10
#define BTLessStrategyNumber
Definition: stratnum.h:29
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32
GBT_VARKEY* gbt_var_key_copy ( const GBT_VARKEY_R u)

Definition at line 91 of file btree_utils_var.c.

References INTALIGN, GBT_VARKEY_R::lower, palloc0(), SET_VARSIZE, GBT_VARKEY_R::upper, VARDATA, VARHDRSZ, and VARSIZE.

Referenced by gbt_bit_l2n(), gbt_numeric_penalty(), gbt_var_bin_union(), and gbt_var_union().

92 {
93  int32 lowersize = VARSIZE(u->lower);
94  int32 uppersize = VARSIZE(u->upper);
95  GBT_VARKEY *r;
96 
97  r = (GBT_VARKEY *) palloc0(INTALIGN(lowersize) + uppersize + VARHDRSZ);
98  memcpy(VARDATA(r), u->lower, lowersize);
99  memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
100  SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
101 
102  return r;
103 }
#define VARDATA(PTR)
Definition: postgres.h:303
#define VARSIZE(PTR)
Definition: postgres.h:304
#define VARHDRSZ
Definition: c.h:445
#define INTALIGN(LEN)
Definition: c.h:585
signed int int32
Definition: c.h:256
void * palloc0(Size size)
Definition: mcxt.c:878
Definition: c.h:439
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
GBT_VARKEY_R gbt_var_key_readable ( const GBT_VARKEY k)

Definition at line 58 of file btree_utils_var.c.

References INTALIGN, GBT_VARKEY_R::lower, GBT_VARKEY_R::upper, VARHDRSZ, and VARSIZE.

Referenced by gbt_bit_consistent(), gbt_bit_l2n(), gbt_bpchar_consistent(), gbt_bytea_consistent(), gbt_numeric_consistent(), gbt_numeric_penalty(), gbt_text_consistent(), gbt_var_bin_union(), gbt_var_fetch(), gbt_var_node_cp_len(), gbt_var_node_truncate(), gbt_var_penalty(), gbt_var_picksplit(), gbt_var_same(), gbt_var_union(), and gbt_vsrt_cmp().

59 {
60  GBT_VARKEY_R r;
61 
62  r.lower = (bytea *) &(((char *) k)[VARHDRSZ]);
63  if (VARSIZE(k) > (VARHDRSZ + (VARSIZE(r.lower))))
64  r.upper = (bytea *) &(((char *) k)[VARHDRSZ + INTALIGN(VARSIZE(r.lower))]);
65  else
66  r.upper = r.lower;
67  return r;
68 }
#define VARSIZE(PTR)
Definition: postgres.h:304
#define VARHDRSZ
Definition: c.h:445
#define INTALIGN(LEN)
Definition: c.h:585
Definition: c.h:439
float* gbt_var_penalty ( float *  res,
const GISTENTRY o,
const GISTENTRY n,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 380 of file btree_utils_var.c.

References Abs, DatumGetPointer, gbtree_vinfo::f_cmp, gbt_bytea_pf_match(), gbt_var_bin_union(), gbt_var_key_readable(), gbt_var_leaf2node(), gbt_var_node_cp_len(), GISTENTRY::key, GBT_VARKEY_R::lower, tupleDesc::natts, PointerGetDatum, RelationData::rd_att, GISTENTRY::rel, GBT_VARKEY_R::upper, VARDATA, VARHDRSZ, and VARSIZE.

Referenced by gbt_bit_penalty(), gbt_bytea_penalty(), and gbt_text_penalty().

382 {
383  GBT_VARKEY *orge = (GBT_VARKEY *) DatumGetPointer(o->key);
384  GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
385  GBT_VARKEY_R ok,
386  nk;
387 
388  *res = 0.0;
389 
390  nk = gbt_var_key_readable(newe);
391  if (nk.lower == nk.upper) /* leaf */
392  {
393  GBT_VARKEY *tmp;
394 
395  tmp = gbt_var_leaf2node(newe, tinfo, flinfo);
396  if (tmp != newe)
397  nk = gbt_var_key_readable(tmp);
398  }
399  ok = gbt_var_key_readable(orge);
400 
401  if ((VARSIZE(ok.lower) - VARHDRSZ) == 0 && (VARSIZE(ok.upper) - VARHDRSZ) == 0)
402  *res = 0.0;
403  else if (!(((*tinfo->f_cmp) (nk.lower, ok.lower, collation, flinfo) >= 0 ||
404  gbt_bytea_pf_match(ok.lower, nk.lower, tinfo)) &&
405  ((*tinfo->f_cmp) (nk.upper, ok.upper, collation, flinfo) <= 0 ||
406  gbt_bytea_pf_match(ok.upper, nk.upper, tinfo))))
407  {
408  Datum d = PointerGetDatum(0);
409  double dres;
410  int32 ol,
411  ul;
412 
413  gbt_var_bin_union(&d, orge, collation, tinfo, flinfo);
414  ol = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(d), tinfo);
415  gbt_var_bin_union(&d, newe, collation, tinfo, flinfo);
416  ul = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(d), tinfo);
417 
418  if (ul < ol)
419  {
420  dres = (ol - ul); /* reduction of common prefix len */
421  }
422  else
423  {
425  unsigned char tmp[4];
426 
427  tmp[0] = (unsigned char) (((VARSIZE(ok.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.lower)[ul]));
428  tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
429  tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
430  tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
431  dres = Abs(tmp[0] - tmp[1]) + Abs(tmp[3] - tmp[2]);
432  dres /= 256.0;
433  }
434 
435  *res += FLT_MIN;
436  *res += (float) (dres / ((double) (ol + 1)));
437  *res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
438  }
439 
440  return res;
441 }
Relation rel
Definition: gist.h:124
static GBT_VARKEY * gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define VARDATA(PTR)
Definition: postgres.h:303
#define VARSIZE(PTR)
Definition: postgres.h:304
#define PointerGetDatum(X)
Definition: postgres.h:562
#define VARHDRSZ
Definition: c.h:445
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)
static int32 gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
int natts
Definition: tupdesc.h:73
signed int int32
Definition: c.h:256
#define Abs(x)
Definition: c.h:812
Datum key
Definition: gist.h:123
static bool gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)
uintptr_t Datum
Definition: postgres.h:372
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
TupleDesc rd_att
Definition: rel.h:115
#define DatumGetPointer(X)
Definition: postgres.h:555
Definition: c.h:439
GIST_SPLITVEC* gbt_var_picksplit ( const GistEntryVector entryvec,
GIST_SPLITVEC v,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 460 of file btree_utils_var.c.

References gbt_vsrt_arg::collation, cur, DatumGetPointer, FirstOffsetNumber, gbt_vsrt_arg::flinfo, gbt_var_bin_union(), gbt_var_key_readable(), gbt_var_leaf2node(), gbt_var_node_cp_len(), gbt_var_node_truncate(), gbt_vsrt_cmp(), Vsrt::i, i, GISTENTRY::key, GBT_VARKEY_R::lower, Max, GistEntryVector::n, NULL, OffsetNumberNext, palloc(), PointerGetDatum, qsort_arg(), GIST_SPLITVEC::spl_ldatum, GIST_SPLITVEC::spl_left, GIST_SPLITVEC::spl_nleft, GIST_SPLITVEC::spl_nright, GIST_SPLITVEC::spl_rdatum, GIST_SPLITVEC::spl_right, Vsrt::t, gbt_vsrt_arg::tinfo, tinfo, gbtree_vinfo::trnc, GBT_VARKEY_R::upper, and GistEntryVector::vector.

Referenced by gbt_bit_picksplit(), gbt_bytea_picksplit(), gbt_numeric_picksplit(), and gbt_text_picksplit().

462 {
463  OffsetNumber i,
464  maxoff = entryvec->n - 1;
465  Vsrt *arr;
466  int svcntr = 0,
467  nbytes;
468  char *cur;
469  GBT_VARKEY **sv = NULL;
470  gbt_vsrt_arg varg;
471 
472  arr = (Vsrt *) palloc((maxoff + 1) * sizeof(Vsrt));
473  nbytes = (maxoff + 2) * sizeof(OffsetNumber);
474  v->spl_left = (OffsetNumber *) palloc(nbytes);
475  v->spl_right = (OffsetNumber *) palloc(nbytes);
476  v->spl_ldatum = PointerGetDatum(0);
477  v->spl_rdatum = PointerGetDatum(0);
478  v->spl_nleft = 0;
479  v->spl_nright = 0;
480 
481  sv = palloc(sizeof(bytea *) * (maxoff + 1));
482 
483  /* Sort entries */
484 
485  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
486  {
487  GBT_VARKEY_R ro;
488 
489  cur = (char *) DatumGetPointer(entryvec->vector[i].key);
490  ro = gbt_var_key_readable((GBT_VARKEY *) cur);
491  if (ro.lower == ro.upper) /* leaf */
492  {
493  sv[svcntr] = gbt_var_leaf2node((GBT_VARKEY *) cur, tinfo, flinfo);
494  arr[i].t = sv[svcntr];
495  if (sv[svcntr] != (GBT_VARKEY *) cur)
496  svcntr++;
497  }
498  else
499  arr[i].t = (GBT_VARKEY *) cur;
500  arr[i].i = i;
501  }
502 
503  /* sort */
504  varg.tinfo = tinfo;
505  varg.collation = collation;
506  varg.flinfo = flinfo;
507  qsort_arg((void *) &arr[FirstOffsetNumber],
508  maxoff - FirstOffsetNumber + 1,
509  sizeof(Vsrt),
510  gbt_vsrt_cmp,
511  (void *) &varg);
512 
513  /* We do simply create two parts */
514 
515  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
516  {
517  if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
518  {
519  gbt_var_bin_union(&v->spl_ldatum, arr[i].t, collation, tinfo, flinfo);
520  v->spl_left[v->spl_nleft] = arr[i].i;
521  v->spl_nleft++;
522  }
523  else
524  {
525  gbt_var_bin_union(&v->spl_rdatum, arr[i].t, collation, tinfo, flinfo);
526  v->spl_right[v->spl_nright] = arr[i].i;
527  v->spl_nright++;
528  }
529  }
530 
531  /* Truncate (=compress) key */
532  if (tinfo->trnc)
533  {
536  GBT_VARKEY *dl;
537  GBT_VARKEY *dr;
538 
539  ll = Max(ll, lr);
540  ll++;
541 
544  v->spl_ldatum = PointerGetDatum(dl);
545  v->spl_rdatum = PointerGetDatum(dr);
546  }
547 
548  return v;
549 }
static GBT_VARKEY * gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PointerGetDatum(X)
Definition: postgres.h:562
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
OffsetNumber * spl_left
Definition: gist.h:105
Datum spl_rdatum
Definition: gist.h:112
int32 n
Definition: gist.h:160
struct cursor * cur
Definition: ecpg.c:28
static int gbt_vsrt_cmp(const void *a, const void *b, void *arg)
static int32 gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
int spl_nleft
Definition: gist.h:106
signed int int32
Definition: c.h:256
uint16 OffsetNumber
Definition: off.h:24
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
Definition: gist.h:161
int spl_nright
Definition: gist.h:111
Datum key
Definition: gist.h:123
#define FirstOffsetNumber
Definition: off.h:27
GBT_VARKEY * t
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
Definition: qsort_arg.c:113
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
static GBT_VARKEY * gbt_var_node_truncate(const GBT_VARKEY *node, int32 cpf_length, const gbtree_vinfo *tinfo)
#define Max(x, y)
Definition: c.h:800
Datum spl_ldatum
Definition: gist.h:107
#define NULL
Definition: c.h:229
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
OffsetNumber * spl_right
Definition: gist.h:110
#define DatumGetPointer(X)
Definition: postgres.h:555
FmgrInfo * flinfo
void * palloc(Size size)
Definition: mcxt.c:849
int i
const gbtree_vinfo * tinfo
Definition: c.h:439
bool gbt_var_same ( Datum  d1,
Datum  d2,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 363 of file btree_utils_var.c.

References DatumGetPointer, gbtree_vinfo::f_cmp, gbt_var_key_readable(), GBT_VARKEY_R::lower, and GBT_VARKEY_R::upper.

Referenced by gbt_bit_same(), gbt_bytea_same(), gbt_numeric_same(), and gbt_text_same().

365 {
366  GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(d1);
367  GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer(d2);
368  GBT_VARKEY_R r1,
369  r2;
370 
371  r1 = gbt_var_key_readable(t1);
372  r2 = gbt_var_key_readable(t2);
373 
374  return ((*tinfo->f_cmp) (r1.lower, r2.lower, collation, flinfo) == 0 &&
375  (*tinfo->f_cmp) (r1.upper, r2.upper, collation, flinfo) == 0);
376 }
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
#define DatumGetPointer(X)
Definition: postgres.h:555
Definition: c.h:439
GBT_VARKEY* gbt_var_union ( const GistEntryVector entryvec,
int32 size,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 324 of file btree_utils_var.c.

References cur, DatumGetPointer, gbt_var_bin_union(), gbt_var_key_copy(), gbt_var_key_readable(), gbt_var_node_cp_len(), gbt_var_node_truncate(), i, GISTENTRY::key, GistEntryVector::n, NULL, PointerGetDatum, gbtree_vinfo::trnc, and GistEntryVector::vector.

Referenced by gbt_bit_union(), gbt_bytea_union(), gbt_numeric_union(), and gbt_text_union().

326 {
327  int i = 0,
328  numranges = entryvec->n;
329  GBT_VARKEY *cur;
330  Datum out;
331  GBT_VARKEY_R rk;
332 
333  *size = sizeof(GBT_VARKEY);
334 
335  cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
336  rk = gbt_var_key_readable(cur);
337  out = PointerGetDatum(gbt_var_key_copy(&rk));
338 
339  for (i = 1; i < numranges; i++)
340  {
341  cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[i].key);
342  gbt_var_bin_union(&out, cur, collation, tinfo, flinfo);
343  }
344 
345 
346  /* Truncate (=compress) key */
347  if (tinfo->trnc)
348  {
349  int32 plen;
350  GBT_VARKEY *trc = NULL;
351 
352  plen = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(out), tinfo);
353  trc = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(out), plen + 1, tinfo);
354 
355  out = PointerGetDatum(trc);
356  }
357 
358  return ((GBT_VARKEY *) DatumGetPointer(out));
359 }
#define PointerGetDatum(X)
Definition: postgres.h:562
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
int32 n
Definition: gist.h:160
struct cursor * cur
Definition: ecpg.c:28
bytea GBT_VARKEY
static int32 gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
signed int int32
Definition: c.h:256
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
Definition: gist.h:161
Datum key
Definition: gist.h:123
uintptr_t Datum
Definition: postgres.h:372
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
static GBT_VARKEY * gbt_var_node_truncate(const GBT_VARKEY *node, int32 cpf_length, const gbtree_vinfo *tinfo)
#define NULL
Definition: c.h:229
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
#define DatumGetPointer(X)
Definition: postgres.h:555
int i
Definition: c.h:439