PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_bit.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_var.h"
#include "utils/fmgrprotos.h"
#include "utils/sortsupport.h"
#include "utils/varbit.h"
#include "varatt.h"
Include dependency graph for btree_bit.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (gbt_bit_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_union)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_same)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_sortsupport)
 
 PG_FUNCTION_INFO_V1 (gbt_varbit_sortsupport)
 
static bool gbt_bitgt (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_bitge (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_biteq (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_bitle (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_bitlt (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static int32 gbt_bitcmp (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static byteagbt_bit_xfrm (VarBit *leaf)
 
static GBT_VARKEYgbt_bit_l2n (GBT_VARKEY *leaf, FmgrInfo *flinfo)
 
Datum gbt_bit_compress (PG_FUNCTION_ARGS)
 
Datum gbt_bit_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_bit_union (PG_FUNCTION_ARGS)
 
Datum gbt_bit_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_bit_same (PG_FUNCTION_ARGS)
 
Datum gbt_bit_penalty (PG_FUNCTION_ARGS)
 
static int gbt_bit_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_bit_sortsupport (PG_FUNCTION_ARGS)
 
Datum gbt_varbit_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_vinfo tinfo
 

Function Documentation

◆ gbt_bit_compress()

Datum gbt_bit_compress ( PG_FUNCTION_ARGS  )

Definition at line 155 of file btree_bit.c.

156{
157 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
158
160}
static const gbtree_vinfo tinfo
Definition btree_bit.c:136
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363

References gbt_var_compress(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_bit_consistent()

Datum gbt_bit_consistent ( PG_FUNCTION_ARGS  )

Definition at line 163 of file btree_bit.c.

164{
165 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
166 VarBit *query = PG_GETARG_VARBIT_P(1);
168#ifdef NOT_USED
169 Oid subtype = PG_GETARG_OID(3);
170#endif
171 bool *recheck = (bool *) PG_GETARG_POINTER(4);
172 bool retval;
175
176 /* All cases served by this function are exact */
177 *recheck = false;
178
179 if (GIST_LEAF(entry))
180 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
181 true, &tinfo, fcinfo->flinfo);
182 else
183 {
184 /* Must convert to internal form to compare to internal-page entries */
185 bytea *q = gbt_bit_xfrm(query);
186
187 retval = gbt_var_consistent(&r, q, strategy, PG_GET_COLLATION(),
188 false, &tinfo, fcinfo->flinfo);
189 }
190 PG_RETURN_BOOL(retval);
191}
static bytea * gbt_bit_xfrm(VarBit *leaf)
Definition btree_bit.c:101
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)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_UINT16(n)
Definition fmgr.h:272
#define PG_GET_COLLATION()
Definition fmgr.h:198
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
#define GIST_LEAF(entry)
Definition gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
unsigned int Oid
uint16 StrategyNumber
Definition stratnum.h:22
Datum key
Definition gist.h:161
Definition c.h:835
#define PG_GETARG_VARBIT_P(n)
Definition varbit.h:62

References DatumGetPointer(), gbt_bit_xfrm(), gbt_var_consistent(), gbt_var_key_readable(), GIST_LEAF, GISTENTRY::key, PG_GET_COLLATION, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_GETARG_VARBIT_P, PG_RETURN_BOOL, and tinfo.

◆ gbt_bit_l2n()

static GBT_VARKEY * gbt_bit_l2n ( GBT_VARKEY leaf,
FmgrInfo flinfo 
)
static

Definition at line 122 of file btree_bit.c.

123{
124 GBT_VARKEY *out;
126 bytea *o;
127
128 o = gbt_bit_xfrm((VarBit *) r.lower);
129 r.upper = r.lower = o;
130 out = gbt_var_key_copy(&r);
131 pfree(o);
132
133 return out;
134}
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
void pfree(void *pointer)
Definition mcxt.c:1619
static int fb(int x)

References fb(), gbt_bit_xfrm(), gbt_var_key_copy(), gbt_var_key_readable(), GBT_VARKEY_R::lower, pfree(), and GBT_VARKEY_R::upper.

◆ gbt_bit_penalty()

Datum gbt_bit_penalty ( PG_FUNCTION_ARGS  )

Definition at line 226 of file btree_bit.c.

227{
230 float *result = (float *) PG_GETARG_POINTER(2);
231
233 &tinfo, fcinfo->flinfo));
234}
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
uint32 result

References fb(), gbt_var_penalty(), PG_GET_COLLATION, PG_GETARG_POINTER, PG_RETURN_POINTER, result, and tinfo.

◆ gbt_bit_picksplit()

Datum gbt_bit_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 204 of file btree_bit.c.

205{
208
210 &tinfo, fcinfo->flinfo);
212}
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

References fb(), gbt_var_picksplit(), PG_GET_COLLATION, PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_bit_same()

Datum gbt_bit_same ( PG_FUNCTION_ARGS  )

Definition at line 215 of file btree_bit.c.

216{
217 Datum d1 = PG_GETARG_DATUM(0);
218 Datum d2 = PG_GETARG_DATUM(1);
219 bool *result = (bool *) PG_GETARG_POINTER(2);
220
221 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
223}
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
uint64_t Datum
Definition postgres.h:70

References gbt_var_same(), PG_GET_COLLATION, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, result, and tinfo.

◆ gbt_bit_sortsupport()

Datum gbt_bit_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 258 of file btree_bit.c.

259{
261
263 ssup->ssup_extra = NULL;
264
266}
static int gbt_bit_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_bit.c:237
struct SortSupportData * SortSupport
Definition execnodes.h:61
#define PG_RETURN_VOID()
Definition fmgr.h:350
int(* comparator)(Datum x, Datum y, SortSupport ssup)

References SortSupportData::comparator, fb(), gbt_bit_ssup_cmp(), PG_GETARG_POINTER, PG_RETURN_VOID, and SortSupportData::ssup_extra.

◆ gbt_bit_ssup_cmp()

static int gbt_bit_ssup_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 237 of file btree_bit.c.

238{
241
245
246 /* for leaf items we expect lower == upper, so only compare lower */
248 PointerGetDatum(arg1.lower),
249 PointerGetDatum(arg2.lower));
250
253
254 return DatumGetInt32(result);
255}
#define GBT_FREE_IF_COPY(ptr1, ptr2)
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:690
#define PG_DETOAST_DATUM(datum)
Definition fmgr.h:240
int y
Definition isn.c:76
int x
Definition isn.c:75
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
#define PointerGetDatum(X)
Definition postgres.h:354
Datum bitcmp(PG_FUNCTION_ARGS)
Definition varbit.c:949

References bitcmp(), DatumGetInt32(), DirectFunctionCall2, fb(), GBT_FREE_IF_COPY, gbt_var_key_readable(), PG_DETOAST_DATUM, PointerGetDatum, result, x, and y.

Referenced by gbt_bit_sortsupport(), and gbt_varbit_sortsupport().

◆ gbt_bit_union()

Datum gbt_bit_union ( PG_FUNCTION_ARGS  )

Definition at line 194 of file btree_bit.c.

195{
197 int32 *size = (int *) PG_GETARG_POINTER(1);
198
200 &tinfo, fcinfo->flinfo));
201}
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
int32_t int32
Definition c.h:679

References fb(), gbt_var_union(), PG_GET_COLLATION, PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_bit_xfrm()

static bytea * gbt_bit_xfrm ( VarBit leaf)
static

Definition at line 101 of file btree_bit.c.

102{
103 bytea *out;
104 int sz = VARBITBYTES(leaf) + VARHDRSZ;
105 int padded_sz = INTALIGN(sz);
106
107 out = (bytea *) palloc(padded_sz);
108 /* initialize the padding bytes to zero */
109 while (sz < padded_sz)
110 ((char *) out)[sz++] = 0;
113 return out;
114}
#define INTALIGN(LEN)
Definition c.h:952
#define VARHDRSZ
Definition c.h:840
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void * palloc(Size size)
Definition mcxt.c:1390
static char * VARDATA(const void *PTR)
Definition varatt.h:305
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432
#define VARBITBYTES(PTR)
Definition varbit.h:73
#define VARBITS(PTR)
Definition varbit.h:71

References fb(), INTALIGN, memcpy(), palloc(), SET_VARSIZE(), VARBITBYTES, VARBITS, VARDATA(), and VARHDRSZ.

Referenced by gbt_bit_consistent(), and gbt_bit_l2n().

◆ gbt_bitcmp()

static int32 gbt_bitcmp ( const void a,
const void b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 77 of file btree_bit.c.

78{
82}
Datum byteacmp(PG_FUNCTION_ARGS)
Definition bytea.c:959
int b
Definition isn.c:74
int a
Definition isn.c:73

References a, b, byteacmp(), DatumGetInt32(), DirectFunctionCall2, and PointerGetDatum.

◆ gbt_biteq()

static bool gbt_biteq ( const void a,
const void b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 49 of file btree_bit.c.

50{
54}
static bool DatumGetBool(Datum X)
Definition postgres.h:100
Datum biteq(PG_FUNCTION_ARGS)
Definition varbit.c:841

References a, b, biteq(), DatumGetBool(), DirectFunctionCall2, and PointerGetDatum.

◆ gbt_bitge()

static bool gbt_bitge ( const void a,
const void b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 41 of file btree_bit.c.

42{
46}
Datum bitge(PG_FUNCTION_ARGS)
Definition varbit.c:934

References a, b, bitge(), DatumGetBool(), DirectFunctionCall2, and PointerGetDatum.

◆ gbt_bitgt()

static bool gbt_bitgt ( const void a,
const void b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 33 of file btree_bit.c.

34{
38}
Datum bitgt(PG_FUNCTION_ARGS)
Definition varbit.c:919

References a, b, bitgt(), DatumGetBool(), DirectFunctionCall2, and PointerGetDatum.

◆ gbt_bitle()

static bool gbt_bitle ( const void a,
const void b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 57 of file btree_bit.c.

58{
62}
Datum bitle(PG_FUNCTION_ARGS)
Definition varbit.c:904

References a, b, bitle(), DatumGetBool(), DirectFunctionCall2, and PointerGetDatum.

◆ gbt_bitlt()

static bool gbt_bitlt ( const void a,
const void b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 65 of file btree_bit.c.

66{
70}
Datum bitlt(PG_FUNCTION_ARGS)
Definition varbit.c:889

References a, b, bitlt(), DatumGetBool(), DirectFunctionCall2, and PointerGetDatum.

◆ gbt_varbit_sortsupport()

Datum gbt_varbit_sortsupport ( PG_FUNCTION_ARGS  )

◆ PG_FUNCTION_INFO_V1() [1/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_compress  )

◆ PG_FUNCTION_INFO_V1() [2/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_penalty  )

◆ PG_FUNCTION_INFO_V1() [4/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_same  )

◆ PG_FUNCTION_INFO_V1() [6/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [7/8]

PG_FUNCTION_INFO_V1 ( gbt_bit_union  )

◆ PG_FUNCTION_INFO_V1() [8/8]

PG_FUNCTION_INFO_V1 ( gbt_varbit_sortsupport  )

Variable Documentation

◆ tinfo

const gbtree_vinfo tinfo
static
Initial value:
=
{
true,
}
static bool gbt_bitge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_bit.c:41
static bool gbt_bitgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_bit.c:33
static int32 gbt_bitcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_bit.c:77
static bool gbt_bitle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_bit.c:57
static bool gbt_biteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_bit.c:49
static bool gbt_bitlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_bit.c:65
static GBT_VARKEY * gbt_bit_l2n(GBT_VARKEY *leaf, FmgrInfo *flinfo)
Definition btree_bit.c:122
@ gbt_t_bit
Definition btree_gist.h:34

Definition at line 136 of file btree_bit.c.

137{
138 gbt_t_bit,
139 true, /* internal keys can be truncated */
140 gbt_bitgt,
141 gbt_bitge,
142 gbt_biteq,
143 gbt_bitle,
144 gbt_bitlt,
146 gbt_bit_l2n /* leaf to internal transformation */
147};

Referenced by binary_upgrade_set_type_oids_by_type_oid(), gbt_bit_compress(), gbt_bit_consistent(), gbt_bit_penalty(), gbt_bit_picksplit(), gbt_bit_same(), gbt_bit_union(), gbt_num_bin_union(), gbt_num_compress(), gbt_num_consistent(), gbt_num_distance(), gbt_num_fetch(), gbt_num_picksplit(), gbt_num_same(), gbt_num_union(), gbt_var_bin_union(), gbt_var_consistent(), gbt_var_leaf2node(), gbt_var_node_pf_match(), gbt_var_penalty(), gbt_var_picksplit(), gbt_var_same(), gbt_var_union(), and getConstraints().