Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
btree_enum.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_enum.c
3 */
4#include "postgres.h"
5
6#include "btree_gist.h"
7#include "btree_utils_num.h"
8#include "fmgr.h"
9#include "utils/fmgrprotos.h"
10#include "utils/fmgroids.h"
11#include "utils/rel.h"
12#include "utils/sortsupport.h"
13
14/* enums are really Oids, so we just use the same structure */
15
16typedef struct
17{
20} oidKEY;
21
22/* GiST support functions */
31
32
33static bool
34gbt_enumgt(const void *a, const void *b, FmgrInfo *flinfo)
35{
37 ObjectIdGetDatum(*((const Oid *) a)),
38 ObjectIdGetDatum(*((const Oid *) b))));
39}
40static bool
41gbt_enumge(const void *a, const void *b, FmgrInfo *flinfo)
42{
44 ObjectIdGetDatum(*((const Oid *) a)),
45 ObjectIdGetDatum(*((const Oid *) b))));
46}
47static bool
48gbt_enumeq(const void *a, const void *b, FmgrInfo *flinfo)
49{
50 return (*((const Oid *) a) == *((const Oid *) b));
51}
52static bool
53gbt_enumle(const void *a, const void *b, FmgrInfo *flinfo)
54{
56 ObjectIdGetDatum(*((const Oid *) a)),
57 ObjectIdGetDatum(*((const Oid *) b))));
58}
59static bool
60gbt_enumlt(const void *a, const void *b, FmgrInfo *flinfo)
61{
63 ObjectIdGetDatum(*((const Oid *) a)),
64 ObjectIdGetDatum(*((const Oid *) b))));
65}
66
67static int
68gbt_enumkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
69{
70 oidKEY *ia = (oidKEY *) (((const Nsrt *) a)->t);
71 oidKEY *ib = (oidKEY *) (((const Nsrt *) b)->t);
72
73 if (ia->lower == ib->lower)
74 {
75 if (ia->upper == ib->upper)
76 return 0;
77
81 }
82
86}
87
88static const gbtree_ninfo tinfo =
89{
91 sizeof(Oid),
92 8, /* sizeof(gbtreekey8) */
99 NULL /* no KNN support at least for now */
100};
101
102
103/**************************************************
104 * GiST support functions
105 **************************************************/
106
107Datum
109{
110 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
111
113}
114
115Datum
117{
118 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
119
121}
122
123Datum
125{
126 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
127 Oid query = PG_GETARG_OID(1);
129
130 /* Oid subtype = PG_GETARG_OID(3); */
131 bool *recheck = (bool *) PG_GETARG_POINTER(4);
132 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
134
135 /* All cases served by this function are exact */
136 *recheck = false;
137
138 key.lower = (GBT_NUMKEY *) &kkk->lower;
139 key.upper = (GBT_NUMKEY *) &kkk->upper;
140
141 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
142 GIST_LEAF(entry), &tinfo,
143 fcinfo->flinfo));
144}
145
146Datum
148{
150 void *out = palloc(sizeof(oidKEY));
151
152 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
153 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
154}
155
156Datum
158{
159 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
160 oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
161 float *result = (float *) PG_GETARG_POINTER(2);
162
163 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
164
165 PG_RETURN_POINTER(result);
166}
167
168Datum
170{
173 &tinfo, fcinfo->flinfo));
174}
175
176Datum
178{
179 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
180 oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
181 bool *result = (bool *) PG_GETARG_POINTER(2);
182
183 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
184 PG_RETURN_POINTER(result);
185}
186
187static int
189{
190 oidKEY *arg1 = (oidKEY *) DatumGetPointer(x);
191 oidKEY *arg2 = (oidKEY *) DatumGetPointer(y);
192
193 /* for leaf items we expect lower == upper, so only compare lower */
195 ssup->ssup_extra,
197 ObjectIdGetDatum(arg1->lower),
198 ObjectIdGetDatum(arg2->lower)));
199}
200
201Datum
203{
205 FmgrInfo *flinfo;
206
208
209 /*
210 * Since gbt_enum_ssup_cmp() uses enum_cmp() like the rest of the
211 * comparison functions, it also needs to pass flinfo when calling it. The
212 * caller to a SortSupport comparison function doesn't provide an FmgrInfo
213 * struct, so look it up now, save it in ssup_extra and use it in
214 * gbt_enum_ssup_cmp() later.
215 */
216 flinfo = MemoryContextAlloc(ssup->ssup_cxt, sizeof(FmgrInfo));
217 fmgr_info_cxt(F_ENUM_CMP, flinfo, ssup->ssup_cxt);
218 ssup->ssup_extra = flinfo;
219
221}
Datum gbt_enum_union(PG_FUNCTION_ARGS)
Definition: btree_enum.c:147
static bool gbt_enumeq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:48
Datum gbt_enum_penalty(PG_FUNCTION_ARGS)
Definition: btree_enum.c:157
Datum gbt_enum_compress(PG_FUNCTION_ARGS)
Definition: btree_enum.c:108
Datum gbt_enum_fetch(PG_FUNCTION_ARGS)
Definition: btree_enum.c:116
static bool gbt_enumge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:41
static bool gbt_enumlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:60
Datum gbt_enum_sortsupport(PG_FUNCTION_ARGS)
Definition: btree_enum.c:202
Datum gbt_enum_picksplit(PG_FUNCTION_ARGS)
Definition: btree_enum.c:169
static int gbt_enumkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:68
static const gbtree_ninfo tinfo
Definition: btree_enum.c:88
Datum gbt_enum_consistent(PG_FUNCTION_ARGS)
Definition: btree_enum.c:124
PG_FUNCTION_INFO_V1(gbt_enum_compress)
static bool gbt_enumgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:34
Datum gbt_enum_same(PG_FUNCTION_ARGS)
Definition: btree_enum.c:177
static int gbt_enum_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_enum.c:188
static bool gbt_enumle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:53
@ gbt_t_enum
Definition: btree_gist.h:38
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define penalty_num(result, olower, oupper, nlower, nupper)
char GBT_NUMKEY
Datum enum_gt(PG_FUNCTION_ARGS)
Definition: enum.c:351
Datum enum_lt(PG_FUNCTION_ARGS)
Definition: enum.c:306
Datum enum_cmp(PG_FUNCTION_ARGS)
Definition: enum.c:378
Datum enum_ge(PG_FUNCTION_ARGS)
Definition: enum.c:342
Datum enum_le(PG_FUNCTION_ARGS)
Definition: enum.c:315
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:137
Datum CallerFInfoFunctionCall2(PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1085
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#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
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
void * palloc(Size size)
Definition: mcxt.c:1365
static bool DatumGetBool(Datum X)
Definition: postgres.h:100
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
uint64_t Datum
Definition: postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
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
MemoryContext ssup_cxt
Definition: sortsupport.h:66
Oid upper
Definition: btree_enum.c:19
Oid lower
Definition: btree_enum.c:18