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

PostgreSQL Source Code git master
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
122{
123 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
124
126}
127
128Datum
130{
131 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
132
134}
135
136Datum
138{
139 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
140 Oid query = PG_GETARG_OID(1);
142
143 /* Oid subtype = PG_GETARG_OID(3); */
144 bool *recheck = (bool *) PG_GETARG_POINTER(4);
145 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
147
148 /* All cases served by this function are exact */
149 *recheck = false;
150
151 key.lower = (GBT_NUMKEY *) &kkk->lower;
152 key.upper = (GBT_NUMKEY *) &kkk->upper;
153
154 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
155 GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
156}
157
158Datum
160{
161 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
162 Oid query = PG_GETARG_OID(1);
163
164 /* Oid subtype = PG_GETARG_OID(3); */
165 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
167
168 key.lower = (GBT_NUMKEY *) &kkk->lower;
169 key.upper = (GBT_NUMKEY *) &kkk->upper;
170
172 &tinfo, fcinfo->flinfo));
173}
174
175Datum
177{
179 void *out = palloc(sizeof(oidKEY));
180
181 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
182 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
183}
184
185Datum
187{
188 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
189 oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
190 float *result = (float *) PG_GETARG_POINTER(2);
191
192 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
193
194 PG_RETURN_POINTER(result);
195}
196
197Datum
199{
202 &tinfo, fcinfo->flinfo));
203}
204
205Datum
207{
208 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
209 oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
210 bool *result = (bool *) PG_GETARG_POINTER(2);
211
212 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
213 PG_RETURN_POINTER(result);
214}
215
216static int
218{
219 oidKEY *arg1 = (oidKEY *) DatumGetPointer(x);
220 oidKEY *arg2 = (oidKEY *) DatumGetPointer(y);
221
222 /* for leaf items we expect lower == upper, so only compare lower */
223 if (arg1->lower > arg2->lower)
224 return 1;
225 else if (arg1->lower < arg2->lower)
226 return -1;
227 else
228 return 0;
229}
230
231Datum
233{
235
237 ssup->ssup_extra = NULL;
238
240}
@ 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:186
Datum oid_dist(PG_FUNCTION_ARGS)
Definition: btree_oid.c:102
Datum gbt_oid_picksplit(PG_FUNCTION_ARGS)
Definition: btree_oid.c:198
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:232
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:217
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:206
Datum gbt_oid_consistent(PG_FUNCTION_ARGS)
Definition: btree_oid.c:137
Datum gbt_oid_union(PG_FUNCTION_ARGS)
Definition: btree_oid.c:176
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
PG_FUNCTION_INFO_V1(gbt_oid_compress)
Datum gbt_oid_fetch(PG_FUNCTION_ARGS)
Definition: btree_oid.c:129
Datum gbt_oid_distance(PG_FUNCTION_ARGS)
Definition: btree_oid.c:159
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:636
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#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_RETURN_OID(x)
Definition: fmgr.h:360
#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 * palloc(Size size)
Definition: mcxt.c:1365
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:49
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:80
uint64_t Datum
Definition: postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
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
Oid upper
Definition: btree_enum.c:19
Oid lower
Definition: btree_enum.c:18