PostgreSQL Source Code git master
btree_bytea.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_bytea.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/sortsupport.h"
10
11/* GiST support functions */
19
20
21/* define for comparison */
22
23static bool
24gbt_byteagt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
25{
29}
30
31static bool
32gbt_byteage(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
33{
37}
38
39static bool
40gbt_byteaeq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
41{
45}
46
47static bool
48gbt_byteale(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
49{
53}
54
55static bool
56gbt_bytealt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
57{
61}
62
63static int32
64gbt_byteacmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
65{
69}
70
71static const gbtree_vinfo tinfo =
72{
74 0,
75 true,
82 NULL
83};
84
85
86/**************************************************
87 * GiST support functions
88 **************************************************/
89
92{
94
96}
97
100{
101 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
102 void *query = DatumGetByteaP(PG_GETARG_DATUM(1));
104
105 /* Oid subtype = PG_GETARG_OID(3); */
106 bool *recheck = (bool *) PG_GETARG_POINTER(4);
107 bool retval;
110
111 /* All cases served by this function are exact */
112 *recheck = false;
113
114 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
115 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
116 PG_RETURN_BOOL(retval);
117}
118
119Datum
121{
123 int32 *size = (int *) PG_GETARG_POINTER(1);
124
126 &tinfo, fcinfo->flinfo));
127}
128
129Datum
131{
134
135 gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
136 &tinfo, fcinfo->flinfo);
138}
139
140Datum
142{
143 Datum d1 = PG_GETARG_DATUM(0);
144 Datum d2 = PG_GETARG_DATUM(1);
145 bool *result = (bool *) PG_GETARG_POINTER(2);
146
147 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
148 PG_RETURN_POINTER(result);
149}
150
151Datum
153{
156 float *result = (float *) PG_GETARG_POINTER(2);
157
159 &tinfo, fcinfo->flinfo));
160}
161
162static int
164{
167
170 Datum result;
171
172 /* for leaf items we expect lower == upper, so only compare lower */
175 PointerGetDatum(ykey.lower));
176
177 GBT_FREE_IF_COPY(key1, x);
178 GBT_FREE_IF_COPY(key2, y);
179
180 return DatumGetInt32(result);
181}
182
183Datum
185{
187
189 ssup->ssup_extra = NULL;
190
192}
static bool gbt_byteagt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bytea.c:24
Datum gbt_bytea_sortsupport(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:184
static bool gbt_byteage(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bytea.c:32
Datum gbt_bytea_consistent(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:99
Datum gbt_bytea_compress(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:91
Datum gbt_bytea_union(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:120
Datum gbt_bytea_penalty(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:152
static const gbtree_vinfo tinfo
Definition: btree_bytea.c:71
static bool gbt_byteaeq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bytea.c:40
static int gbt_bytea_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_bytea.c:163
Datum gbt_bytea_same(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:141
static int32 gbt_byteacmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bytea.c:64
PG_FUNCTION_INFO_V1(gbt_bytea_compress)
static bool gbt_byteale(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bytea.c:48
Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:130
static bool gbt_bytealt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bytea.c:56
@ gbt_t_bytea
Definition: btree_gist.h:33
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)
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define GBT_FREE_IF_COPY(ptr1, ptr2)
int32_t int32
Definition: c.h:498
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:684
#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_DETOAST_DATUM(datum)
Definition: fmgr.h:240
#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 y
Definition: isn.c:76
int b
Definition: isn.c:74
int x
Definition: isn.c:75
int a
Definition: isn.c:73
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:30
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:161
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87
Definition: c.h:658
Datum byteaeq(PG_FUNCTION_ARGS)
Definition: varlena.c:3862
Datum byteagt(PG_FUNCTION_ARGS)
Definition: varlena.c:3966
Datum byteage(PG_FUNCTION_ARGS)
Definition: varlena.c:3986
Datum byteacmp(PG_FUNCTION_ARGS)
Definition: varlena.c:4006
Datum byteale(PG_FUNCTION_ARGS)
Definition: varlena.c:3946
Datum bytealt(PG_FUNCTION_ARGS)
Definition: varlena.c:3926