PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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
79 ObjectIdGetDatum(ia->upper),
80 ObjectIdGetDatum(ib->upper)));
81 }
82
84 ObjectIdGetDatum(ia->lower),
85 ObjectIdGetDatum(ib->lower)));
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
114
115Datum
122
123Datum
125{
126 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
127 Oid query = PG_GETARG_OID(1);
129#ifdef NOT_USED
130 Oid subtype = PG_GETARG_OID(3);
131#endif
132 bool *recheck = (bool *) PG_GETARG_POINTER(4);
133 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
134 GBT_NUMKEY_R key;
135
136 /* All cases served by this function are exact */
137 *recheck = false;
138
139 key.lower = (GBT_NUMKEY *) &kkk->lower;
140 key.upper = (GBT_NUMKEY *) &kkk->upper;
141
142 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
143 GIST_LEAF(entry), &tinfo,
144 fcinfo->flinfo));
145}
146
147Datum
149{
151 void *out = palloc(sizeof(oidKEY));
152
153 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
154 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
155}
156
157Datum
159{
162 float *result = (float *) PG_GETARG_POINTER(2);
163
164 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
165
166 PG_RETURN_POINTER(result);
167}
168
169Datum
176
177Datum
179{
182 bool *result = (bool *) PG_GETARG_POINTER(2);
183
184 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
185 PG_RETURN_POINTER(result);
186}
187
188static int
190{
193
194 /* for leaf items we expect lower == upper, so only compare lower */
196 ssup->ssup_extra,
198 ObjectIdGetDatum(arg1->lower),
199 ObjectIdGetDatum(arg2->lower)));
200}
201
202Datum
204{
206 FmgrInfo *flinfo;
207
209
210 /*
211 * Since gbt_enum_ssup_cmp() uses enum_cmp() like the rest of the
212 * comparison functions, it also needs to pass flinfo when calling it. The
213 * caller to a SortSupport comparison function doesn't provide an FmgrInfo
214 * struct, so look it up now, save it in ssup_extra and use it in
215 * gbt_enum_ssup_cmp() later.
216 */
217 flinfo = MemoryContextAlloc(ssup->ssup_cxt, sizeof(FmgrInfo));
218 fmgr_info_cxt(F_ENUM_CMP, flinfo, ssup->ssup_cxt);
219 ssup->ssup_extra = flinfo;
220
222}
Datum gbt_enum_union(PG_FUNCTION_ARGS)
Definition btree_enum.c:148
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:158
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:203
Datum gbt_enum_picksplit(PG_FUNCTION_ARGS)
Definition btree_enum.c:170
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
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:178
static int gbt_enum_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_enum.c:189
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:138
Datum CallerFInfoFunctionCall2(PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition fmgr.c:1086
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_GETARG_UINT16(n)
Definition fmgr.h:272
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
#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:1232
void * palloc(Size size)
Definition mcxt.c:1387
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:342
static int32 DatumGetInt32(Datum X)
Definition postgres.h:212
#define InvalidOid
unsigned int Oid
static int fb(int x)
struct SortSupportData * SortSupport
Definition sortsupport.h:58
uint16 StrategyNumber
Definition stratnum.h:22
Datum key
Definition gist.h:161
int(* comparator)(Datum x, Datum y, SortSupport ssup)
MemoryContext ssup_cxt
Definition sortsupport.h:66
Oid upper
Definition btree_enum.c:19
Oid lower
Definition btree_enum.c:18