PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_utils_var.c File Reference
#include "postgres.h"
#include <limits.h>
#include <float.h>
#include "btree_gist.h"
#include "btree_utils_var.h"
#include "utils/rel.h"
#include "varatt.h"
Include dependency graph for btree_utils_var.c:

Go to the source code of this file.

Data Structures

struct  Vsrt
 
struct  gbt_vsrt_arg
 

Macros

#define lower_is_below_query()    (tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0)
 
#define upper_is_above_query()
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_var_decompress)
 
 PG_FUNCTION_INFO_V1 (gbt_var_fetch)
 
Datum gbt_var_decompress (PG_FUNCTION_ARGS)
 
GBT_VARKEY_R gbt_var_key_readable (const GBT_VARKEY *k)
 
static GBT_VARKEYgbt_var_key_from_datum (const varlena *u)
 
GBT_VARKEYgbt_var_key_copy (const GBT_VARKEY_R *u)
 
static GBT_VARKEYgbt_var_leaf2node (GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
static int32 gbt_var_node_cp_len (const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
 
static bool gbt_bytea_pf_match (const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)
 
static bool gbt_var_node_pf_match (const GBT_VARKEY_R *node, const bytea *query, const gbtree_vinfo *tinfo)
 
static GBT_VARKEYgbt_var_node_truncate (const GBT_VARKEY *node, int32 cpf_length, const gbtree_vinfo *tinfo)
 
void gbt_var_bin_union (Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
GISTENTRYgbt_var_compress (GISTENTRY *entry, const gbtree_vinfo *tinfo)
 
Datum gbt_var_fetch (PG_FUNCTION_ARGS)
 
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)
 
floatgbt_var_penalty (float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
static int gbt_vsrt_cmp (const void *a, const void *b, void *arg)
 
GIST_SPLITVECgbt_var_picksplit (const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 
bool gbt_var_consistent (const GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 

Macro Definition Documentation

◆ lower_is_below_query

#define lower_is_below_query ( )     (tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0)

◆ upper_is_above_query

#define upper_is_above_query ( )
Value:
(tinfo->f_cmp(key->upper, query, collation, flinfo) >= 0 || \
static const gbtree_vinfo tinfo
Definition btree_bit.c:136
static int fb(int x)
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)

Function Documentation

◆ gbt_bytea_pf_match()

static bool gbt_bytea_pf_match ( const bytea pf,
const bytea query,
const gbtree_vinfo tinfo 
)
static

Definition at line 167 of file btree_utils_var.c.

168{
169 bool out = false;
170 int32 qlen = VARSIZE(query) - VARHDRSZ;
172
173 if (nlen <= qlen)
174 {
175 char *q = VARDATA(query);
176 char *n = VARDATA(pf);
177
178 out = (memcmp(q, n, nlen) == 0);
179 }
180
181 return out;
182}
#define VARHDRSZ
Definition c.h:840
int32_t int32
Definition c.h:679
static Size VARSIZE(const void *PTR)
Definition varatt.h:298
static char * VARDATA(const void *PTR)
Definition varatt.h:305

References fb(), VARDATA(), VARHDRSZ, and VARSIZE().

Referenced by gbt_var_node_pf_match(), and gbt_var_penalty().

◆ gbt_var_bin_union()

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

Definition at line 239 of file btree_utils_var.c.

241{
244
245 if (eo.lower == eo.upper) /* if leaf, convert to internal form */
246 {
247 GBT_VARKEY *tmp;
248
249 tmp = gbt_var_leaf2node(e, tinfo, flinfo);
250 if (tmp != e)
252 }
253
254 if (DatumGetPointer(*u))
255 {
257 bool update = false;
258
259 nr.lower = ro.lower;
260 nr.upper = ro.upper;
261
262 if (tinfo->f_cmp(ro.lower, eo.lower, collation, flinfo) > 0)
263 {
264 nr.lower = eo.lower;
265 update = true;
266 }
267
268 if (tinfo->f_cmp(ro.upper, eo.upper, collation, flinfo) < 0)
269 {
270 nr.upper = eo.upper;
271 update = true;
272 }
273
274 if (update)
276 }
277 else
278 {
279 nr.lower = eo.lower;
280 nr.upper = eo.upper;
282 }
283}
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
static GBT_VARKEY * gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
#define PointerGetDatum(X)
Definition postgres.h:354
e
Definition c.h:835

References DatumGetPointer(), gbtree_vinfo::f_cmp, fb(), gbt_var_key_copy(), gbt_var_key_readable(), gbt_var_leaf2node(), PointerGetDatum, and tinfo.

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

◆ gbt_var_compress()

GISTENTRY * gbt_var_compress ( GISTENTRY entry,
const gbtree_vinfo tinfo 
)

Definition at line 287 of file btree_utils_var.c.

288{
289 GISTENTRY *retval;
290
291 if (entry->leafkey)
292 {
293 varlena *leaf = PG_DETOAST_DATUM(entry->key);
294 GBT_VARKEY *r;
295
297
298 retval = palloc_object(GISTENTRY);
299 gistentryinit(*retval, PointerGetDatum(r),
300 entry->rel, entry->page,
301 entry->offset, true);
302 }
303 else
304 retval = entry;
305
306 return retval;
307}
static GBT_VARKEY * gbt_var_key_from_datum(const varlena *u)
#define palloc_object(type)
Definition fe_memutils.h:89
#define PG_DETOAST_DATUM(datum)
Definition fmgr.h:240
#define gistentryinit(e, k, r, pg, o, l)
Definition gist.h:245
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

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

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

◆ gbt_var_consistent()

bool gbt_var_consistent ( const GBT_VARKEY_R key,
const void query,
StrategyNumber  strategy,
Oid  collation,
bool  is_leaf,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 560 of file btree_utils_var.c.

567{
568 bool retval;
569
570 /*
571 * On leaf pages we directly apply the check "key->lower OP query"; we
572 * need not consider key->upper since it will be equal to key->lower.
573 *
574 * On internal pages we mostly need to check "is lower bound below query?"
575 * and/or "is upper bound above query?", where we must allow equality in
576 * both cases. When checking against the upper bound we have to allow a
577 * gbt_var_node_pf_match too.
578 *
579 * Remember that f_cmp is for internal pages, f_eq etc for leaf pages.
580 */
581#define lower_is_below_query() \
582 (tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0)
583#define upper_is_above_query() \
584 (tinfo->f_cmp(key->upper, query, collation, flinfo) >= 0 || \
585 gbt_var_node_pf_match(key, query, tinfo))
586
587 switch (strategy)
588 {
590 if (is_leaf)
591 retval = tinfo->f_le(key->lower, query, collation, flinfo);
592 else
593 retval = lower_is_below_query();
594 break;
596 if (is_leaf)
597 retval = tinfo->f_lt(key->lower, query, collation, flinfo);
598 else
599 retval = lower_is_below_query();
600 break;
602 if (is_leaf)
603 retval = tinfo->f_eq(key->lower, query, collation, flinfo);
604 else
606 break;
608 if (is_leaf)
609 retval = tinfo->f_gt(key->lower, query, collation, flinfo);
610 else
611 retval = upper_is_above_query();
612 break;
614 if (is_leaf)
615 retval = tinfo->f_ge(key->lower, query, collation, flinfo);
616 else
617 retval = upper_is_above_query();
618 break;
620 if (is_leaf)
621 retval = !(tinfo->f_eq(key->lower, query, collation, flinfo));
622 else
623 {
624 /*
625 * If the upper/lower bounds are equal and not truncated, then
626 * all entries below this node must have exactly that value.
627 * So we can avoid descending if the query equals both bounds.
628 * In all other cases, we must descend.
629 */
630 retval = tinfo->trnc ||
631 !(tinfo->f_cmp(key->lower, query, collation, flinfo) == 0 &&
632 tinfo->f_cmp(key->upper, query, collation, flinfo) == 0);
633 }
634 break;
635 default:
636 retval = false;
637 }
638
639#undef lower_is_below_query
640#undef upper_is_above_query
641
642 return retval;
643}
#define BtreeGistNotEqualStrategyNumber
Definition btree_gist.h:10
#define upper_is_above_query()
#define lower_is_below_query()
#define BTGreaterStrategyNumber
Definition stratnum.h:33
#define BTLessStrategyNumber
Definition stratnum.h:29
#define BTEqualStrategyNumber
Definition stratnum.h:31
#define BTLessEqualStrategyNumber
Definition stratnum.h:30
#define BTGreaterEqualStrategyNumber
Definition stratnum.h:32
bool(* f_lt)(const void *, const void *, Oid, FmgrInfo *)
bool(* f_eq)(const void *, const void *, Oid, FmgrInfo *)
bool(* f_gt)(const void *, const void *, Oid, FmgrInfo *)
bool(* f_ge)(const void *, const void *, Oid, FmgrInfo *)
bool(* f_le)(const void *, const void *, Oid, FmgrInfo *)

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, lower_is_below_query, tinfo, gbtree_vinfo::trnc, and upper_is_above_query.

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

◆ gbt_var_decompress()

Datum gbt_var_decompress ( PG_FUNCTION_ARGS  )

Definition at line 36 of file btree_utils_var.c.

37{
40
41 /* We only need a new GISTENTRY if detoasting did something */
42 if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
43 {
45
46 gistentryinit(*retval, PointerGetDatum(key),
47 entry->rel, entry->page,
48 entry->offset, false);
49
50 PG_RETURN_POINTER(retval);
51 }
52
53 PG_RETURN_POINTER(entry);
54}
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363

References DatumGetPointer(), gistentryinit, GISTENTRY::key, GISTENTRY::offset, GISTENTRY::page, palloc_object, PG_DETOAST_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, and GISTENTRY::rel.

◆ gbt_var_fetch()

◆ gbt_var_key_copy()

GBT_VARKEY * gbt_var_key_copy ( const GBT_VARKEY_R u)

Definition at line 97 of file btree_utils_var.c.

98{
101 GBT_VARKEY *r;
102
104 memcpy(VARDATA(r), u->lower, lowersize);
107
108 return r;
109}
#define INTALIGN(LEN)
Definition c.h:952
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void * palloc0(Size size)
Definition mcxt.c:1420
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

References fb(), INTALIGN, GBT_VARKEY_R::lower, memcpy(), 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().

◆ gbt_var_key_from_datum()

static GBT_VARKEY * gbt_var_key_from_datum ( const varlena u)
static

Definition at line 78 of file btree_utils_var.c.

79{
81 GBT_VARKEY *r;
82
84 memcpy(VARDATA(r), u, lowersize);
86
87 return r;
88}
void * palloc(Size size)
Definition mcxt.c:1390

References fb(), memcpy(), palloc(), SET_VARSIZE(), VARDATA(), VARHDRSZ, and VARSIZE().

Referenced by gbt_var_compress().

◆ gbt_var_key_readable()

◆ gbt_var_leaf2node()

static GBT_VARKEY * gbt_var_leaf2node ( GBT_VARKEY leaf,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)
static

Definition at line 116 of file btree_utils_var.c.

117{
118 if (tinfo->f_l2n)
119 return tinfo->f_l2n(leaf, flinfo);
120 else
121 return leaf;
122}
GBT_VARKEY *(* f_l2n)(GBT_VARKEY *, FmgrInfo *flinfo)

References gbtree_vinfo::f_l2n, fb(), and tinfo.

Referenced by gbt_var_bin_union(), gbt_var_penalty(), and gbt_var_picksplit().

◆ gbt_var_node_cp_len()

static int32 gbt_var_node_cp_len ( const GBT_VARKEY node,
const gbtree_vinfo tinfo 
)
static

Definition at line 135 of file btree_utils_var.c.

136{
138 int32 i = 0;
141 int32 ml = Min(t1len, t2len);
142 char *p1 = VARDATA(r.lower);
143 char *p2 = VARDATA(r.upper);
144
145 if (ml == 0)
146 return 0;
147
148 while (i < ml)
149 {
150 if (*p1 != *p2)
151 return i;
152 p1++;
153 p2++;
154 i++;
155 }
156 return ml; /* lower == upper */
157}
#define Min(x, y)
Definition c.h:1131
int i
Definition isn.c:77

References fb(), gbt_var_key_readable(), i, GBT_VARKEY_R::lower, Min, GBT_VARKEY_R::upper, VARDATA(), VARHDRSZ, and VARSIZE().

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

◆ gbt_var_node_pf_match()

static bool gbt_var_node_pf_match ( const GBT_VARKEY_R node,
const bytea query,
const gbtree_vinfo tinfo 
)
static

Definition at line 195 of file btree_utils_var.c.

196{
197 return (tinfo->trnc &&
198 gbt_bytea_pf_match(node->upper, query, tinfo));
199}
static bool gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)

References gbt_bytea_pf_match(), tinfo, gbtree_vinfo::trnc, and GBT_VARKEY_R::upper.

◆ gbt_var_node_truncate()

static GBT_VARKEY * gbt_var_node_truncate ( const GBT_VARKEY node,
int32  cpf_length,
const gbtree_vinfo tinfo 
)
static

Definition at line 210 of file btree_utils_var.c.

211{
212 GBT_VARKEY *out;
214 int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
215 int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
216 int32 si;
217 char *out2;
218
219 len1 = Min(len1, (cpf_length + 1));
220 len2 = Min(len2, (cpf_length + 1));
221
222 si = 2 * VARHDRSZ + INTALIGN(len1 + VARHDRSZ) + len2;
223 out = (GBT_VARKEY *) palloc0(si);
224 SET_VARSIZE(out, si);
225
226 memcpy(VARDATA(out), r.lower, len1 + VARHDRSZ);
227 SET_VARSIZE(VARDATA(out), len1 + VARHDRSZ);
228
229 out2 = VARDATA(out) + INTALIGN(len1 + VARHDRSZ);
230 memcpy(out2, r.upper, len2 + VARHDRSZ);
231 SET_VARSIZE(out2, len2 + VARHDRSZ);
232
233 return out;
234}

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

Referenced by gbt_var_picksplit(), and gbt_var_union().

◆ gbt_var_penalty()

float * gbt_var_penalty ( float res,
const GISTENTRY o,
const GISTENTRY n,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 384 of file btree_utils_var.c.

386{
390 nk;
391
392 *res = 0.0;
393
395 if (nk.lower == nk.upper) /* if leaf, convert to internal form */
396 {
397 GBT_VARKEY *tmp;
398
399 tmp = gbt_var_leaf2node(newe, tinfo, flinfo);
400 if (tmp != newe)
402 }
404
405 if ((VARSIZE(ok.lower) - VARHDRSZ) == 0 && (VARSIZE(ok.upper) - VARHDRSZ) == 0)
406 *res = 0.0;
407 else if (!((tinfo->f_cmp(nk.lower, ok.lower, collation, flinfo) >= 0 ||
408 gbt_bytea_pf_match(ok.lower, nk.lower, tinfo)) &&
409 (tinfo->f_cmp(nk.upper, ok.upper, collation, flinfo) <= 0 ||
410 gbt_bytea_pf_match(ok.upper, nk.upper, tinfo))))
411 {
412 Datum d = PointerGetDatum(0);
413 double dres;
414 int32 ol,
415 ul;
416
417 gbt_var_bin_union(&d, orge, collation, tinfo, flinfo);
419 gbt_var_bin_union(&d, newe, collation, tinfo, flinfo);
421
422 if (ul < ol)
423 {
424 dres = (ol - ul); /* reduction of common prefix len */
425 }
426 else
427 {
429 unsigned char tmp[4];
430
431 tmp[0] = (unsigned char) (((VARSIZE(ok.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.lower)[ul]));
432 tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
433 tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
434 tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
435 dres = abs(tmp[0] - tmp[1]) + abs(tmp[3] - tmp[2]);
436 dres /= 256.0;
437 }
438
439 *res += FLT_MIN;
440 *res += (float) (dres / ((double) (ol + 1)));
441 *res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
442 }
443
444 return res;
445}
static int32 gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
uint64_t Datum
Definition postgres.h:70

References DatumGetPointer(), gbtree_vinfo::f_cmp, fb(), gbt_bytea_pf_match(), gbt_var_bin_union(), gbt_var_key_readable(), gbt_var_leaf2node(), gbt_var_node_cp_len(), GISTENTRY::key, PointerGetDatum, tinfo, VARDATA(), VARHDRSZ, and VARSIZE().

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

◆ gbt_var_picksplit()

GIST_SPLITVEC * gbt_var_picksplit ( const GistEntryVector entryvec,
GIST_SPLITVEC v,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 464 of file btree_utils_var.c.

466{
468 maxoff = entryvec->n - 1;
469 Vsrt *arr;
470 int svcntr = 0,
471 nbytes;
472 char *cur;
473 GBT_VARKEY **sv = NULL;
475
476 arr = palloc_array(Vsrt, maxoff + 1);
477 nbytes = (maxoff + 2) * sizeof(OffsetNumber);
478 v->spl_left = (OffsetNumber *) palloc(nbytes);
479 v->spl_right = (OffsetNumber *) palloc(nbytes);
482 v->spl_nleft = 0;
483 v->spl_nright = 0;
484
485 sv = palloc_array(GBT_VARKEY *, maxoff + 1);
486
487 /* Sort entries */
488
489 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
490 {
492
493 cur = (char *) DatumGetPointer(entryvec->vector[i].key);
495 if (ro.lower == ro.upper) /* leaf */
496 {
498 arr[i].t = sv[svcntr];
499 if (sv[svcntr] != (GBT_VARKEY *) cur)
500 svcntr++;
501 }
502 else
503 arr[i].t = (GBT_VARKEY *) cur;
504 arr[i].i = i;
505 }
506
507 /* sort */
508 varg.tinfo = tinfo;
509 varg.collation = collation;
510 varg.flinfo = flinfo;
512 maxoff - FirstOffsetNumber + 1,
513 sizeof(Vsrt),
515 &varg);
516
517 /* We do simply create two parts */
518
519 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
520 {
521 if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
522 {
523 gbt_var_bin_union(&v->spl_ldatum, arr[i].t, collation, tinfo, flinfo);
524 v->spl_left[v->spl_nleft] = arr[i].i;
525 v->spl_nleft++;
526 }
527 else
528 {
529 gbt_var_bin_union(&v->spl_rdatum, arr[i].t, collation, tinfo, flinfo);
530 v->spl_right[v->spl_nright] = arr[i].i;
531 v->spl_nright++;
532 }
533 }
534
535 /* Truncate (=compress) key */
536 if (tinfo->trnc)
537 {
540 GBT_VARKEY *dl;
541 GBT_VARKEY *dr;
542
543 ll = Max(ll, lr);
544 ll++;
545
550 }
551
552 return v;
553}
static GBT_VARKEY * gbt_var_node_truncate(const GBT_VARKEY *node, int32 cpf_length, const gbtree_vinfo *tinfo)
static int gbt_vsrt_cmp(const void *a, const void *b, void *arg)
#define Max(x, y)
Definition c.h:1125
struct cursor * cur
Definition ecpg.c:29
#define palloc_array(type, count)
Definition fe_memutils.h:91
#define OffsetNumberNext(offsetNumber)
Definition off.h:52
uint16 OffsetNumber
Definition off.h:24
#define FirstOffsetNumber
Definition off.h:27
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
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
GBT_VARKEY * t

References cur, DatumGetPointer(), fb(), FirstOffsetNumber, 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, Max, OffsetNumberNext, palloc(), palloc_array, 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, tinfo, and gbtree_vinfo::trnc.

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

◆ gbt_var_same()

bool gbt_var_same ( Datum  d1,
Datum  d2,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 367 of file btree_utils_var.c.

369{
373 r2;
374
377
378 return (tinfo->f_cmp(r1.lower, r2.lower, collation, flinfo) == 0 &&
379 tinfo->f_cmp(r1.upper, r2.upper, collation, flinfo) == 0);
380}

References DatumGetPointer(), gbtree_vinfo::f_cmp, fb(), gbt_var_key_readable(), and tinfo.

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

◆ gbt_var_union()

GBT_VARKEY * gbt_var_union ( const GistEntryVector entryvec,
int32 size,
Oid  collation,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 328 of file btree_utils_var.c.

330{
331 int i = 0,
332 numranges = entryvec->n;
334 Datum out;
336
337 *size = sizeof(GBT_VARKEY);
338
339 cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
342
343 for (i = 1; i < numranges; i++)
344 {
345 cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[i].key);
346 gbt_var_bin_union(&out, cur, collation, tinfo, flinfo);
347 }
348
349
350 /* Truncate (=compress) key */
351 if (tinfo->trnc)
352 {
353 int32 plen;
355
358
359 out = PointerGetDatum(trc);
360 }
361
362 return ((GBT_VARKEY *) DatumGetPointer(out));
363}
bytea GBT_VARKEY

References cur, DatumGetPointer(), fb(), gbt_var_bin_union(), gbt_var_key_copy(), gbt_var_key_readable(), gbt_var_node_cp_len(), gbt_var_node_truncate(), i, PointerGetDatum, tinfo, and gbtree_vinfo::trnc.

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

◆ gbt_vsrt_cmp()

static int gbt_vsrt_cmp ( const void a,
const void b,
void arg 
)
static

Definition at line 449 of file btree_utils_var.c.

450{
451 GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
452 GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
453 const gbt_vsrt_arg *varg = (const gbt_vsrt_arg *) arg;
454 int res;
455
456 res = varg->tinfo->f_cmp(ar.lower, br.lower, varg->collation, varg->flinfo);
457 if (res == 0)
458 return varg->tinfo->f_cmp(ar.upper, br.upper, varg->collation, varg->flinfo);
459
460 return res;
461}
Datum arg
Definition elog.c:1323
int b
Definition isn.c:74
int a
Definition isn.c:73
const gbtree_vinfo * tinfo

References a, arg, b, gbtree_vinfo::f_cmp, fb(), gbt_var_key_readable(), and gbt_vsrt_arg::tinfo.

Referenced by gbt_var_picksplit().

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( gbt_var_decompress  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( gbt_var_fetch  )