PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree_utils_var.c File Reference
#include "postgres.h"
#include <math.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 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 struct 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)
 
float * gbt_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 168 of file btree_utils_var.c.

169{
170 bool out = false;
171 int32 qlen = VARSIZE(query) - VARHDRSZ;
172 int32 nlen = VARSIZE(pf) - VARHDRSZ;
173
174 if (nlen <= qlen)
175 {
176 char *q = VARDATA(query);
177 char *n = VARDATA(pf);
178
179 out = (memcmp(q, n, nlen) == 0);
180 }
181
182 return out;
183}
#define VARHDRSZ
Definition: c.h:646
int32_t int32
Definition: c.h:481
#define VARDATA(PTR)
Definition: varatt.h:278
#define VARSIZE(PTR)
Definition: varatt.h:279

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

234{
236 GBT_VARKEY_R nr;
237
238 if (eo.lower == eo.upper) /* leaf */
239 {
240 GBT_VARKEY *tmp;
241
242 tmp = gbt_var_leaf2node(e, tinfo, flinfo);
243 if (tmp != e)
244 eo = gbt_var_key_readable(tmp);
245 }
246
247 if (DatumGetPointer(*u))
248 {
250 bool update = false;
251
252 nr.lower = ro.lower;
253 nr.upper = ro.upper;
254
255 if (tinfo->f_cmp(ro.lower, eo.lower, collation, flinfo) > 0)
256 {
257 nr.lower = eo.lower;
258 update = true;
259 }
260
261 if (tinfo->f_cmp(ro.upper, eo.upper, collation, flinfo) < 0)
262 {
263 nr.upper = eo.upper;
264 update = true;
265 }
266
267 if (update)
269 }
270 else
271 {
272 nr.lower = eo.lower;
273 nr.upper = eo.upper;
275 }
276}
static const gbtree_vinfo tinfo
Definition: btree_bit.c:108
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:322
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
e
Definition: preproc-init.c:82
int32(* f_cmp)(const void *, const void *, Oid, FmgrInfo *)
Definition: c.h:641

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

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

281{
282 GISTENTRY *retval;
283
284 if (entry->leafkey)
285 {
286 struct varlena *leaf = PG_DETOAST_DATUM(entry->key);
287 GBT_VARKEY *r;
288
289 r = gbt_var_key_from_datum(leaf);
290
291 retval = palloc(sizeof(GISTENTRY));
292 gistentryinit(*retval, PointerGetDatum(r),
293 entry->rel, entry->page,
294 entry->offset, true);
295 }
296 else
297 retval = entry;
298
299 return retval;
300}
static GBT_VARKEY * gbt_var_key_from_datum(const struct varlena *u)
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:244
void * palloc(Size size)
Definition: mcxt.c:1317
OffsetNumber offset
Definition: gist.h:163
Datum key
Definition: gist.h:160
Page page
Definition: gist.h:162
Relation rel
Definition: gist.h:161
bool leafkey
Definition: gist.h:164

References gbt_var_key_from_datum(), gistentryinit, GISTENTRY::key, GISTENTRY::leafkey, GISTENTRY::offset, GISTENTRY::page, palloc(), 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 553 of file btree_utils_var.c.

560{
561 bool retval = false;
562
563 switch (strategy)
564 {
566 if (is_leaf)
567 retval = tinfo->f_ge(query, key->lower, collation, flinfo);
568 else
569 retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 0
570 || gbt_var_node_pf_match(key, query, tinfo);
571 break;
573 if (is_leaf)
574 retval = tinfo->f_gt(query, key->lower, collation, flinfo);
575 else
576 retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 0
577 || gbt_var_node_pf_match(key, query, tinfo);
578 break;
580 if (is_leaf)
581 retval = tinfo->f_eq(query, key->lower, collation, flinfo);
582 else
583 retval =
584 (tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0 &&
585 tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0) ||
587 break;
589 if (is_leaf)
590 retval = tinfo->f_lt(query, key->upper, collation, flinfo);
591 else
592 retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0
593 || gbt_var_node_pf_match(key, query, tinfo);
594 break;
596 if (is_leaf)
597 retval = tinfo->f_le(query, key->upper, collation, flinfo);
598 else
599 retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0
600 || gbt_var_node_pf_match(key, query, tinfo);
601 break;
603 retval = !(tinfo->f_eq(query, key->lower, collation, flinfo) &&
604 tinfo->f_eq(query, key->upper, collation, flinfo));
605 break;
606 default:
607 retval = false;
608 }
609
610 return retval;
611}
#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(), sort-test::key, 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 {
42 GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
43
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:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361

References DatumGetPointer(), gistentryinit, GISTENTRY::key, sort-test::key, GISTENTRY::offset, GISTENTRY::page, palloc(), 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{
91 int32 lowersize = VARSIZE(u->lower);
92 int32 uppersize = VARSIZE(u->upper);
93 GBT_VARKEY *r;
94
95 r = (GBT_VARKEY *) palloc0(INTALIGN(lowersize) + uppersize + VARHDRSZ);
96 memcpy(VARDATA(r), u->lower, lowersize);
97 memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
98 SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
99
100 return r;
101}
#define INTALIGN(LEN)
Definition: c.h:762
void * palloc0(Size size)
Definition: mcxt.c:1347
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

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().

◆ gbt_var_key_from_datum()

static GBT_VARKEY * gbt_var_key_from_datum ( const struct varlena u)
static

Definition at line 73 of file btree_utils_var.c.

74{
75 int32 lowersize = VARSIZE(u);
76 GBT_VARKEY *r;
77
78 r = (GBT_VARKEY *) palloc(lowersize + VARHDRSZ);
79 memcpy(VARDATA(r), u, lowersize);
80 SET_VARSIZE(r, lowersize + VARHDRSZ);
81
82 return r;
83}

References 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, 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 120 of file btree_utils_var.c.

121{
123 int32 i = 0;
124 int32 l = 0;
125 int32 t1len = VARSIZE(r.lower) - VARHDRSZ;
126 int32 t2len = VARSIZE(r.upper) - VARHDRSZ;
127 int32 ml = Min(t1len, t2len);
128 char *p1 = VARDATA(r.lower);
129 char *p2 = VARDATA(r.upper);
130
131 if (ml == 0)
132 return 0;
133
134 while (i < ml)
135 {
136 if (tinfo->eml > 1 && l == 0)
137 {
138 if ((l = pg_mblen(p1)) != pg_mblen(p2))
139 {
140 return i;
141 }
142 }
143 if (*p1 != *p2)
144 {
145 if (tinfo->eml > 1)
146 {
147 return (i - l + 1);
148 }
149 else
150 {
151 return i;
152 }
153 }
154
155 p1++;
156 p2++;
157 l--;
158 i++;
159 }
160 return ml; /* lower == upper */
161}
#define Min(x, y)
Definition: c.h:958
int i
Definition: isn.c:72
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1023

References gbtree_vinfo::eml, gbt_var_key_readable(), i, GBT_VARKEY_R::lower, Min, p2, pg_mblen(), 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 190 of file btree_utils_var.c.

191{
192 return (tinfo->trnc &&
193 (gbt_bytea_pf_match(node->lower, query, tinfo) ||
194 gbt_bytea_pf_match(node->upper, query, tinfo)));
195}
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 203 of file btree_utils_var.c.

204{
205 GBT_VARKEY *out = NULL;
207 int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
208 int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
209 int32 si;
210 char *out2;
211
212 len1 = Min(len1, (cpf_length + 1));
213 len2 = Min(len2, (cpf_length + 1));
214
215 si = 2 * VARHDRSZ + INTALIGN(len1 + VARHDRSZ) + len2;
216 out = (GBT_VARKEY *) palloc0(si);
217 SET_VARSIZE(out, si);
218
219 memcpy(VARDATA(out), r.lower, len1 + VARHDRSZ);
220 SET_VARSIZE(VARDATA(out), len1 + VARHDRSZ);
221
222 out2 = VARDATA(out) + INTALIGN(len1 + VARHDRSZ);
223 memcpy(out2, r.upper, len2 + VARHDRSZ);
224 SET_VARSIZE(out2, len2 + VARHDRSZ);
225
226 return out;
227}

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

379{
382 GBT_VARKEY_R ok,
383 nk;
384
385 *res = 0.0;
386
387 nk = gbt_var_key_readable(newe);
388 if (nk.lower == nk.upper) /* leaf */
389 {
390 GBT_VARKEY *tmp;
391
392 tmp = gbt_var_leaf2node(newe, tinfo, flinfo);
393 if (tmp != newe)
394 nk = gbt_var_key_readable(tmp);
395 }
396 ok = gbt_var_key_readable(orge);
397
398 if ((VARSIZE(ok.lower) - VARHDRSZ) == 0 && (VARSIZE(ok.upper) - VARHDRSZ) == 0)
399 *res = 0.0;
400 else if (!((tinfo->f_cmp(nk.lower, ok.lower, collation, flinfo) >= 0 ||
402 (tinfo->f_cmp(nk.upper, ok.upper, collation, flinfo) <= 0 ||
404 {
405 Datum d = PointerGetDatum(0);
406 double dres;
407 int32 ol,
408 ul;
409
410 gbt_var_bin_union(&d, orge, collation, tinfo, flinfo);
412 gbt_var_bin_union(&d, newe, collation, tinfo, flinfo);
414
415 if (ul < ol)
416 {
417 dres = (ol - ul); /* reduction of common prefix len */
418 }
419 else
420 {
422 unsigned char tmp[4];
423
424 tmp[0] = (unsigned char) (((VARSIZE(ok.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.lower)[ul]));
425 tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
426 tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
427 tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
428 dres = abs(tmp[0] - tmp[1]) + abs(tmp[3] - tmp[2]);
429 dres /= 256.0;
430 }
431
432 *res += FLT_MIN;
433 *res += (float) (dres / ((double) (ol + 1)));
434 *res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
435 }
436
437 return res;
438}
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)
uintptr_t Datum
Definition: postgres.h:64
TupleDesc rd_att
Definition: rel.h:112

References 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, TupleDescData::natts, PointerGetDatum(), RelationData::rd_att, GISTENTRY::rel, res, tinfo, GBT_VARKEY_R::upper, 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 457 of file btree_utils_var.c.

459{
461 maxoff = entryvec->n - 1;
462 Vsrt *arr;
463 int svcntr = 0,
464 nbytes;
465 char *cur;
466 GBT_VARKEY **sv = NULL;
467 gbt_vsrt_arg varg;
468
469 arr = (Vsrt *) palloc((maxoff + 1) * sizeof(Vsrt));
470 nbytes = (maxoff + 2) * sizeof(OffsetNumber);
471 v->spl_left = (OffsetNumber *) palloc(nbytes);
472 v->spl_right = (OffsetNumber *) palloc(nbytes);
475 v->spl_nleft = 0;
476 v->spl_nright = 0;
477
478 sv = palloc(sizeof(bytea *) * (maxoff + 1));
479
480 /* Sort entries */
481
482 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
483 {
484 GBT_VARKEY_R ro;
485
486 cur = (char *) DatumGetPointer(entryvec->vector[i].key);
488 if (ro.lower == ro.upper) /* leaf */
489 {
490 sv[svcntr] = gbt_var_leaf2node((GBT_VARKEY *) cur, tinfo, flinfo);
491 arr[i].t = sv[svcntr];
492 if (sv[svcntr] != (GBT_VARKEY *) cur)
493 svcntr++;
494 }
495 else
496 arr[i].t = (GBT_VARKEY *) cur;
497 arr[i].i = i;
498 }
499
500 /* sort */
501 varg.tinfo = tinfo;
502 varg.collation = collation;
503 varg.flinfo = flinfo;
505 maxoff - FirstOffsetNumber + 1,
506 sizeof(Vsrt),
508 &varg);
509
510 /* We do simply create two parts */
511
512 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
513 {
514 if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
515 {
516 gbt_var_bin_union(&v->spl_ldatum, arr[i].t, collation, tinfo, flinfo);
517 v->spl_left[v->spl_nleft] = arr[i].i;
518 v->spl_nleft++;
519 }
520 else
521 {
522 gbt_var_bin_union(&v->spl_rdatum, arr[i].t, collation, tinfo, flinfo);
523 v->spl_right[v->spl_nright] = arr[i].i;
524 v->spl_nright++;
525 }
526 }
527
528 /* Truncate (=compress) key */
529 if (tinfo->trnc)
530 {
533 GBT_VARKEY *dl;
534 GBT_VARKEY *dr;
535
536 ll = Max(ll, lr);
537 ll++;
538
543 }
544
545 return v;
546}
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:952
struct cursor * cur
Definition: ecpg.c:29
#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:143
OffsetNumber * spl_right
Definition: gist.h:147
Datum spl_ldatum
Definition: gist.h:144
Datum spl_rdatum
Definition: gist.h:149
int spl_nright
Definition: gist.h:148
OffsetNumber * spl_left
Definition: gist.h:142
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
Definition: gist.h:236
int32 n
Definition: gist.h:235
GBT_VARKEY * t
FmgrInfo * flinfo
const gbtree_vinfo * tinfo

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, 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, tinfo, gbt_vsrt_arg::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().

◆ gbt_var_same()

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

Definition at line 360 of file btree_utils_var.c.

362{
365 GBT_VARKEY_R r1,
366 r2;
367
368 r1 = gbt_var_key_readable(t1);
369 r2 = gbt_var_key_readable(t2);
370
371 return (tinfo->f_cmp(r1.lower, r2.lower, collation, flinfo) == 0 &&
372 tinfo->f_cmp(r1.upper, r2.upper, collation, flinfo) == 0);
373}

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

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

323{
324 int i = 0,
325 numranges = entryvec->n;
327 Datum out;
328 GBT_VARKEY_R rk;
329
330 *size = sizeof(GBT_VARKEY);
331
332 cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
335
336 for (i = 1; i < numranges; i++)
337 {
338 cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[i].key);
339 gbt_var_bin_union(&out, cur, collation, tinfo, flinfo);
340 }
341
342
343 /* Truncate (=compress) key */
344 if (tinfo->trnc)
345 {
346 int32 plen;
347 GBT_VARKEY *trc = NULL;
348
350 trc = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(out), plen + 1, tinfo);
351
352 out = PointerGetDatum(trc);
353 }
354
355 return ((GBT_VARKEY *) DatumGetPointer(out));
356}
bytea GBT_VARKEY
static pg_noinline void Size size
Definition: slab.c:607

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, PointerGetDatum(), size, tinfo, gbtree_vinfo::trnc, and GistEntryVector::vector.

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

443{
444 GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
445 GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
446 const gbt_vsrt_arg *varg = (const gbt_vsrt_arg *) arg;
447 int res;
448
449 res = varg->tinfo->f_cmp(ar.lower, br.lower, varg->collation, varg->flinfo);
450 if (res == 0)
451 return varg->tinfo->f_cmp(ar.upper, br.upper, varg->collation, varg->flinfo);
452
453 return res;
454}
int b
Definition: isn.c:69
int a
Definition: isn.c:68
void * arg

References a, arg, b, gbt_vsrt_arg::collation, gbtree_vinfo::f_cmp, gbt_vsrt_arg::flinfo, gbt_var_key_readable(), GBT_VARKEY_R::lower, res, gbt_vsrt_arg::tinfo, and GBT_VARKEY_R::upper.

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  )