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 "mb/pg_wchar.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
 

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 (GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
 

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 179 of file btree_utils_var.c.

180{
181 bool out = false;
182 int32 qlen = VARSIZE(query) - VARHDRSZ;
184
185 if (nlen <= qlen)
186 {
187 char *q = VARDATA(query);
188 char *n = VARDATA(pf);
189
190 out = (memcmp(q, n, nlen) == 0);
191 }
192
193 return out;
194}
#define VARHDRSZ
Definition c.h:723
int32_t int32
Definition c.h:554
static int fb(int x)
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 243 of file btree_utils_var.c.

245{
248
249 if (eo.lower == eo.upper) /* leaf */
250 {
251 GBT_VARKEY *tmp;
252
253 tmp = gbt_var_leaf2node(e, tinfo, flinfo);
254 if (tmp != e)
256 }
257
258 if (DatumGetPointer(*u))
259 {
261 bool update = false;
262
263 nr.lower = ro.lower;
264 nr.upper = ro.upper;
265
266 if (tinfo->f_cmp(ro.lower, eo.lower, collation, flinfo) > 0)
267 {
268 nr.lower = eo.lower;
269 update = true;
270 }
271
272 if (tinfo->f_cmp(ro.upper, eo.upper, collation, flinfo) < 0)
273 {
274 nr.upper = eo.upper;
275 update = true;
276 }
277
278 if (update)
280 }
281 else
282 {
283 nr.lower = eo.lower;
284 nr.upper = eo.upper;
286 }
287}
static const gbtree_vinfo tinfo
Definition btree_bit.c:109
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 Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
e
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)
Definition c.h:718

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 291 of file btree_utils_var.c.

292{
293 GISTENTRY *retval;
294
295 if (entry->leafkey)
296 {
297 varlena *leaf = PG_DETOAST_DATUM(entry->key);
298 GBT_VARKEY *r;
299
301
302 retval = palloc_object(GISTENTRY);
303 gistentryinit(*retval, PointerGetDatum(r),
304 entry->rel, entry->page,
305 entry->offset, true);
306 }
307 else
308 retval = entry;
309
310 return retval;
311}
static GBT_VARKEY * gbt_var_key_from_datum(const varlena *u)
#define palloc_object(type)
Definition fe_memutils.h:74
#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 ( GBT_VARKEY_R key,
const void query,
StrategyNumber  strategy,
Oid  collation,
bool  is_leaf,
const gbtree_vinfo tinfo,
FmgrInfo flinfo 
)

Definition at line 564 of file btree_utils_var.c.

571{
572 bool retval = false;
573
574 switch (strategy)
575 {
577 if (is_leaf)
578 retval = tinfo->f_ge(query, key->lower, collation, flinfo);
579 else
580 retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 0
581 || gbt_var_node_pf_match(key, query, tinfo);
582 break;
584 if (is_leaf)
585 retval = tinfo->f_gt(query, key->lower, collation, flinfo);
586 else
587 retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 0
588 || gbt_var_node_pf_match(key, query, tinfo);
589 break;
591 if (is_leaf)
592 retval = tinfo->f_eq(query, key->lower, collation, flinfo);
593 else
594 retval =
595 (tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0 &&
596 tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0) ||
597 gbt_var_node_pf_match(key, query, tinfo);
598 break;
600 if (is_leaf)
601 retval = tinfo->f_lt(query, key->upper, collation, flinfo);
602 else
603 retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0
604 || gbt_var_node_pf_match(key, query, tinfo);
605 break;
607 if (is_leaf)
608 retval = tinfo->f_le(query, key->upper, collation, flinfo);
609 else
610 retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0
611 || gbt_var_node_pf_match(key, query, tinfo);
612 break;
614 retval = !(tinfo->f_eq(query, key->lower, collation, flinfo) &&
615 tinfo->f_eq(query, key->upper, collation, flinfo));
616 break;
617 default:
618 retval = false;
619 }
620
621 return retval;
622}
#define BtreeGistNotEqualStrategyNumber
Definition btree_gist.h:10
static bool gbt_var_node_pf_match(const GBT_VARKEY_R *node, const bytea *query, const gbtree_vinfo *tinfo)
#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, gbt_var_node_pf_match(), and tinfo.

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 35 of file btree_utils_var.c.

36{
39
40 if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
41 {
43
44 gistentryinit(*retval, PointerGetDatum(key),
45 entry->rel, entry->page,
46 entry->offset, false);
47
48 PG_RETURN_POINTER(retval);
49 }
50
51 PG_RETURN_POINTER(entry);
52}
#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 89 of file btree_utils_var.c.

90{
93 GBT_VARKEY *r;
94
99
100 return r;
101}
#define INTALIGN(LEN)
Definition c.h:835
void * palloc0(Size size)
Definition mcxt.c:1417
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

References fb(), 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().

◆ gbt_var_key_from_datum()

static GBT_VARKEY * gbt_var_key_from_datum ( const varlena u)
static

Definition at line 73 of file btree_utils_var.c.

74{
76 GBT_VARKEY *r;
77
79 memcpy(VARDATA(r), u, lowersize);
81
82 return r;
83}
void * palloc(Size size)
Definition mcxt.c:1387

References fb(), 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 105 of file btree_utils_var.c.

106{
107 GBT_VARKEY *out = leaf;
108
109 if (tinfo->f_l2n)
110 out = tinfo->f_l2n(leaf, flinfo);
111
112 return out;
113}
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 123 of file btree_utils_var.c.

124{
126 int32 i = 0;
128 int32 l_total = 0;
131 int32 ml = Min(t1len, t2len);
132 char *p1 = VARDATA(r.lower);
133 char *p2 = VARDATA(r.upper);
134 const char *end1 = p1 + t1len;
135 const char *end2 = p2 + t2len;
136
137 if (ml == 0)
138 return 0;
139
140 while (i < ml)
141 {
142 if (tinfo->eml > 1 && l_left_to_match == 0)
143 {
145 if (l_total != pg_mblen_range(p2, end2))
146 {
147 return i;
148 }
150 }
151 if (*p1 != *p2)
152 {
153 if (tinfo->eml > 1)
154 {
156
157 /* end common prefix at final byte of last matching char */
158 return i - l_matched_subset;
159 }
160 else
161 {
162 return i;
163 }
164 }
165
166 p1++;
167 p2++;
169 i++;
170 }
171 return ml; /* lower == upper */
172}
#define Min(x, y)
Definition c.h:1019
int i
Definition isn.c:77
int pg_mblen_range(const char *mbstr, const char *end)
Definition mbutils.c:1084

References gbtree_vinfo::eml, fb(), gbt_var_key_readable(), i, GBT_VARKEY_R::lower, Min, pg_mblen_range(), tinfo, 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 201 of file btree_utils_var.c.

202{
203 return (tinfo->trnc &&
204 (gbt_bytea_pf_match(node->lower, query, tinfo) ||
205 gbt_bytea_pf_match(node->upper, query, tinfo)));
206}
static bool gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)

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

Referenced by gbt_var_consistent().

◆ 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 214 of file btree_utils_var.c.

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

References fb(), gbt_var_key_readable(), INTALIGN, GBT_VARKEY_R::lower, 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 388 of file btree_utils_var.c.

390{
394 nk;
395
396 *res = 0.0;
397
399 if (nk.lower == nk.upper) /* leaf */
400 {
401 GBT_VARKEY *tmp;
402
403 tmp = gbt_var_leaf2node(newe, tinfo, flinfo);
404 if (tmp != newe)
406 }
408
409 if ((VARSIZE(ok.lower) - VARHDRSZ) == 0 && (VARSIZE(ok.upper) - VARHDRSZ) == 0)
410 *res = 0.0;
411 else if (!((tinfo->f_cmp(nk.lower, ok.lower, collation, flinfo) >= 0 ||
412 gbt_bytea_pf_match(ok.lower, nk.lower, tinfo)) &&
413 (tinfo->f_cmp(nk.upper, ok.upper, collation, flinfo) <= 0 ||
414 gbt_bytea_pf_match(ok.upper, nk.upper, tinfo))))
415 {
416 Datum d = PointerGetDatum(0);
417 double dres;
418 int32 ol,
419 ul;
420
421 gbt_var_bin_union(&d, orge, collation, tinfo, flinfo);
423 gbt_var_bin_union(&d, newe, collation, tinfo, flinfo);
425
426 if (ul < ol)
427 {
428 dres = (ol - ul); /* reduction of common prefix len */
429 }
430 else
431 {
433 unsigned char tmp[4];
434
435 tmp[0] = (unsigned char) (((VARSIZE(ok.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.lower)[ul]));
436 tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
437 tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
438 tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
439 dres = abs(tmp[0] - tmp[1]) + abs(tmp[3] - tmp[2]);
440 dres /= 256.0;
441 }
442
443 *res += FLT_MIN;
444 *res += (float) (dres / ((double) (ol + 1)));
445 *res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
446 }
447
448 return res;
449}
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 468 of file btree_utils_var.c.

470{
472 maxoff = entryvec->n - 1;
473 Vsrt *arr;
474 int svcntr = 0,
475 nbytes;
476 char *cur;
477 GBT_VARKEY **sv = NULL;
479
480 arr = palloc_array(Vsrt, maxoff + 1);
481 nbytes = (maxoff + 2) * sizeof(OffsetNumber);
482 v->spl_left = (OffsetNumber *) palloc(nbytes);
483 v->spl_right = (OffsetNumber *) palloc(nbytes);
486 v->spl_nleft = 0;
487 v->spl_nright = 0;
488
489 sv = palloc_array(GBT_VARKEY *, maxoff + 1);
490
491 /* Sort entries */
492
493 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
494 {
496
497 cur = (char *) DatumGetPointer(entryvec->vector[i].key);
499 if (ro.lower == ro.upper) /* leaf */
500 {
502 arr[i].t = sv[svcntr];
503 if (sv[svcntr] != (GBT_VARKEY *) cur)
504 svcntr++;
505 }
506 else
507 arr[i].t = (GBT_VARKEY *) cur;
508 arr[i].i = i;
509 }
510
511 /* sort */
512 varg.tinfo = tinfo;
513 varg.collation = collation;
514 varg.flinfo = flinfo;
516 maxoff - FirstOffsetNumber + 1,
517 sizeof(Vsrt),
519 &varg);
520
521 /* We do simply create two parts */
522
523 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
524 {
525 if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
526 {
527 gbt_var_bin_union(&v->spl_ldatum, arr[i].t, collation, tinfo, flinfo);
528 v->spl_left[v->spl_nleft] = arr[i].i;
529 v->spl_nleft++;
530 }
531 else
532 {
533 gbt_var_bin_union(&v->spl_rdatum, arr[i].t, collation, tinfo, flinfo);
534 v->spl_right[v->spl_nright] = arr[i].i;
535 v->spl_nright++;
536 }
537 }
538
539 /* Truncate (=compress) key */
540 if (tinfo->trnc)
541 {
544 GBT_VARKEY *dl;
545 GBT_VARKEY *dr;
546
547 ll = Max(ll, lr);
548 ll++;
549
554 }
555
556 return v;
557}
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:1013
struct cursor * cur
Definition ecpg.c:29
#define palloc_array(type, count)
Definition fe_memutils.h:76
#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 371 of file btree_utils_var.c.

373{
377 r2;
378
381
382 return (tinfo->f_cmp(r1.lower, r2.lower, collation, flinfo) == 0 &&
383 tinfo->f_cmp(r1.upper, r2.upper, collation, flinfo) == 0);
384}

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 332 of file btree_utils_var.c.

334{
335 int i = 0,
336 numranges = entryvec->n;
338 Datum out;
340
341 *size = sizeof(GBT_VARKEY);
342
343 cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
346
347 for (i = 1; i < numranges; i++)
348 {
349 cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[i].key);
350 gbt_var_bin_union(&out, cur, collation, tinfo, flinfo);
351 }
352
353
354 /* Truncate (=compress) key */
355 if (tinfo->trnc)
356 {
357 int32 plen;
359
362
363 out = PointerGetDatum(trc);
364 }
365
366 return ((GBT_VARKEY *) DatumGetPointer(out));
367}
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 453 of file btree_utils_var.c.

454{
455 GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
456 GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
457 const gbt_vsrt_arg *varg = (const gbt_vsrt_arg *) arg;
458 int res;
459
460 res = varg->tinfo->f_cmp(ar.lower, br.lower, varg->collation, varg->flinfo);
461 if (res == 0)
462 return varg->tinfo->f_cmp(ar.upper, br.upper, varg->collation, varg->flinfo);
463
464 return res;
465}
Datum arg
Definition elog.c:1322
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  )