PostgreSQL Source Code git master
btree_bit.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_bit.c
3 */
4#include "postgres.h"
5
6#include "btree_gist.h"
7#include "btree_utils_var.h"
8#include "utils/fmgrprotos.h"
9#include "utils/varbit.h"
10
11
12/*
13** Bit ops
14*/
21
22
23/* define for comparison */
24
25static bool
26gbt_bitgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
27{
31}
32
33static bool
34gbt_bitge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
35{
39}
40
41static bool
42gbt_biteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
43{
47}
48
49static bool
50gbt_bitle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
51{
55}
56
57static bool
58gbt_bitlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
59{
63}
64
65static int32
66gbt_bitcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
67{
71}
72
73
74static bytea *
76{
77 bytea *out = leaf;
78 int sz = VARBITBYTES(leaf) + VARHDRSZ;
79 int padded_sz = INTALIGN(sz);
80
81 out = (bytea *) palloc(padded_sz);
82 /* initialize the padding bytes to zero */
83 while (sz < padded_sz)
84 ((char *) out)[sz++] = 0;
85 SET_VARSIZE(out, padded_sz);
86 memcpy(VARDATA(out), VARBITS(leaf), VARBITBYTES(leaf));
87 return out;
88}
89
90
91
92
93static GBT_VARKEY *
95{
96 GBT_VARKEY *out = leaf;
98 bytea *o;
99
100 o = gbt_bit_xfrm(r.lower);
101 r.upper = r.lower = o;
102 out = gbt_var_key_copy(&r);
103 pfree(o);
104
105 return out;
106}
107
108static const gbtree_vinfo tinfo =
109{
110 gbt_t_bit,
111 0,
112 true,
113 gbt_bitgt,
114 gbt_bitge,
115 gbt_biteq,
116 gbt_bitle,
117 gbt_bitlt,
120};
121
122
123/**************************************************
124 * Bit ops
125 **************************************************/
126
127Datum
129{
130 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
131
133}
134
135Datum
137{
138 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139 void *query = DatumGetByteaP(PG_GETARG_DATUM(1));
141
142 /* Oid subtype = PG_GETARG_OID(3); */
143 bool *recheck = (bool *) PG_GETARG_POINTER(4);
144 bool retval;
147
148 /* All cases served by this function are exact */
149 *recheck = false;
150
151 if (GIST_LEAF(entry))
152 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
153 true, &tinfo, fcinfo->flinfo);
154 else
155 {
156 bytea *q = gbt_bit_xfrm((bytea *) query);
157
158 retval = gbt_var_consistent(&r, q, strategy, PG_GET_COLLATION(),
159 false, &tinfo, fcinfo->flinfo);
160 }
161 PG_RETURN_BOOL(retval);
162}
163
164
165
166Datum
168{
170 int32 *size = (int *) PG_GETARG_POINTER(1);
171
173 &tinfo, fcinfo->flinfo));
174}
175
176
177Datum
179{
182
183 gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
184 &tinfo, fcinfo->flinfo);
186}
187
188Datum
190{
191 Datum d1 = PG_GETARG_DATUM(0);
192 Datum d2 = PG_GETARG_DATUM(1);
193 bool *result = (bool *) PG_GETARG_POINTER(2);
194
195 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
196 PG_RETURN_POINTER(result);
197}
198
199
200Datum
202{
205 float *result = (float *) PG_GETARG_POINTER(2);
206
208 &tinfo, fcinfo->flinfo));
209}
static bool gbt_bitge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:34
Datum gbt_bit_same(PG_FUNCTION_ARGS)
Definition: btree_bit.c:189
static bool gbt_bitgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:26
static int32 gbt_bitcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:66
PG_FUNCTION_INFO_V1(gbt_bit_compress)
static bool gbt_bitle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:50
static const gbtree_vinfo tinfo
Definition: btree_bit.c:108
Datum gbt_bit_consistent(PG_FUNCTION_ARGS)
Definition: btree_bit.c:136
Datum gbt_bit_penalty(PG_FUNCTION_ARGS)
Definition: btree_bit.c:201
Datum gbt_bit_compress(PG_FUNCTION_ARGS)
Definition: btree_bit.c:128
static bool gbt_biteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:42
static bool gbt_bitlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:58
static GBT_VARKEY * gbt_bit_l2n(GBT_VARKEY *leaf, FmgrInfo *flinfo)
Definition: btree_bit.c:94
Datum gbt_bit_union(PG_FUNCTION_ARGS)
Definition: btree_bit.c:167
static bytea * gbt_bit_xfrm(bytea *leaf)
Definition: btree_bit.c:75
Datum gbt_bit_picksplit(PG_FUNCTION_ARGS)
Definition: btree_bit.c:178
@ gbt_t_bit
Definition: btree_gist.h:34
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, 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)
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define INTALIGN(LEN)
Definition: c.h:765
#define VARHDRSZ
Definition: c.h:649
int32_t int32
Definition: c.h:484
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_GET_COLLATION()
Definition: fmgr.h:198
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define DatumGetByteaP(X)
Definition: fmgr.h:331
#define GIST_LEAF(entry)
Definition: gist.h:171
int b
Definition: isn.c:69
int a
Definition: isn.c:68
void pfree(void *pointer)
Definition: mcxt.c:1521
void * palloc(Size size)
Definition: mcxt.c:1317
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
uintptr_t Datum
Definition: postgres.h:69
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
unsigned int Oid
Definition: postgres_ext.h:32
static pg_noinline void Size size
Definition: slab.c:607
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:161
Definition: c.h:644
#define VARDATA(PTR)
Definition: varatt.h:278
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
Datum bitge(PG_FUNCTION_ARGS)
Definition: varbit.c:934
Datum bitle(PG_FUNCTION_ARGS)
Definition: varbit.c:904
Datum biteq(PG_FUNCTION_ARGS)
Definition: varbit.c:841
Datum bitlt(PG_FUNCTION_ARGS)
Definition: varbit.c:889
Datum bitgt(PG_FUNCTION_ARGS)
Definition: varbit.c:919
#define VARBITBYTES(PTR)
Definition: varbit.h:73
#define VARBITS(PTR)
Definition: varbit.h:71
Datum byteacmp(PG_FUNCTION_ARGS)
Definition: varlena.c:3913