PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_oid.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_oid.c
3 */
4#include "postgres.h"
5
6#include "btree_gist.h"
7#include "btree_utils_num.h"
8#include "utils/rel.h"
9#include "utils/sortsupport.h"
10
11typedef struct
12{
13 Oid lower;
14 Oid upper;
15} oidKEY;
16
17/* GiST support functions */
27
28
29static bool
30gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
31{
32 return (*((const Oid *) a) > *((const Oid *) b));
33}
34static bool
35gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
36{
37 return (*((const Oid *) a) >= *((const Oid *) b));
38}
39static bool
40gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
41{
42 return (*((const Oid *) a) == *((const Oid *) b));
43}
44static bool
45gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
46{
47 return (*((const Oid *) a) <= *((const Oid *) b));
48}
49static bool
50gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
51{
52 return (*((const Oid *) a) < *((const Oid *) b));
53}
54
55static int
56gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
57{
58 oidKEY *ia = (oidKEY *) (((const Nsrt *) a)->t);
59 oidKEY *ib = (oidKEY *) (((const Nsrt *) b)->t);
60
61 if (ia->lower == ib->lower)
62 {
63 if (ia->upper == ib->upper)
64 return 0;
65
66 return (ia->upper > ib->upper) ? 1 : -1;
67 }
68
69 return (ia->lower > ib->lower) ? 1 : -1;
70}
71
72static float8
73gbt_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
74{
75 Oid aa = *(const Oid *) a;
76 Oid bb = *(const Oid *) b;
77
78 if (aa < bb)
79 return (float8) (bb - aa);
80 else
81 return (float8) (aa - bb);
82}
83
84
85static const gbtree_ninfo tinfo =
86{
88 sizeof(Oid),
89 8, /* sizeof(gbtreekey8) */
97};
98
99
101Datum
103{
104 Oid a = PG_GETARG_OID(0);
105 Oid b = PG_GETARG_OID(1);
106 Oid res;
107
108 if (a < b)
109 res = b - a;
110 else
111 res = a - b;
112 PG_RETURN_OID(res);
113}
114
115
116/**************************************************
117 * GiST support functions
118 **************************************************/
119
120Datum
127
128Datum
135
136Datum
138{
139 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
140 Oid query = PG_GETARG_OID(1);
142#ifdef NOT_USED
143 Oid subtype = PG_GETARG_OID(3);
144#endif
145 bool *recheck = (bool *) PG_GETARG_POINTER(4);
146 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
147 GBT_NUMKEY_R key;
148
149 /* All cases served by this function are exact */
150 *recheck = false;
151
152 key.lower = (GBT_NUMKEY *) &kkk->lower;
153 key.upper = (GBT_NUMKEY *) &kkk->upper;
154
155 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
156 GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
157}
158
159Datum
161{
162 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
163 Oid query = PG_GETARG_OID(1);
164#ifdef NOT_USED
165 Oid subtype = PG_GETARG_OID(3);
166#endif
167 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
168 GBT_NUMKEY_R key;
169
170 key.lower = (GBT_NUMKEY *) &kkk->lower;
171 key.upper = (GBT_NUMKEY *) &kkk->upper;
172
173 PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
174 &tinfo, fcinfo->flinfo));
175}
176
177Datum
179{
181 void *out = palloc(sizeof(oidKEY));
182
183 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
184 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
185}
186
187Datum
189{
192 float *result = (float *) PG_GETARG_POINTER(2);
193
194 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
195
196 PG_RETURN_POINTER(result);
197}
198
199Datum
206
207Datum
209{
212 bool *result = (bool *) PG_GETARG_POINTER(2);
213
214 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
215 PG_RETURN_POINTER(result);
216}
217
218static int
220{
223
224 /* for leaf items we expect lower == upper, so only compare lower */
225 if (arg1->lower > arg2->lower)
226 return 1;
227 else if (arg1->lower < arg2->lower)
228 return -1;
229 else
230 return 0;
231}
232
233Datum
@ gbt_t_oid
Definition btree_gist.h:25
static bool gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:50
Datum gbt_oid_penalty(PG_FUNCTION_ARGS)
Definition btree_oid.c:188
Datum oid_dist(PG_FUNCTION_ARGS)
Definition btree_oid.c:102
Datum gbt_oid_picksplit(PG_FUNCTION_ARGS)
Definition btree_oid.c:200
static bool gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:45
Datum gbt_oid_sortsupport(PG_FUNCTION_ARGS)
Definition btree_oid.c:234
static bool gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:40
static int gbt_oid_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_oid.c:219
static bool gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:35
Datum gbt_oid_compress(PG_FUNCTION_ARGS)
Definition btree_oid.c:121
static const gbtree_ninfo tinfo
Definition btree_oid.c:85
Datum gbt_oid_same(PG_FUNCTION_ARGS)
Definition btree_oid.c:208
Datum gbt_oid_consistent(PG_FUNCTION_ARGS)
Definition btree_oid.c:137
Datum gbt_oid_union(PG_FUNCTION_ARGS)
Definition btree_oid.c:178
static int gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:56
static bool gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:30
Datum gbt_oid_fetch(PG_FUNCTION_ARGS)
Definition btree_oid.c:129
Datum gbt_oid_distance(PG_FUNCTION_ARGS)
Definition btree_oid.c:160
static float8 gbt_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_oid.c:73
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
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
double float8
Definition c.h:644
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369
#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_RETURN_OID(x)
Definition fmgr.h:361
#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 * palloc(Size size)
Definition mcxt.c:1387
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
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)