PostgreSQL Source Code git master
btree_int8.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_int8.c
3 */
4#include "postgres.h"
5
6#include "btree_gist.h"
7#include "btree_utils_num.h"
8#include "common/int.h"
9
10typedef struct int64key
11{
15
16/*
17** int64 ops
18*/
27
28
29static bool
30gbt_int8gt(const void *a, const void *b, FmgrInfo *flinfo)
31{
32 return (*((const int64 *) a) > *((const int64 *) b));
33}
34static bool
35gbt_int8ge(const void *a, const void *b, FmgrInfo *flinfo)
36{
37 return (*((const int64 *) a) >= *((const int64 *) b));
38}
39static bool
40gbt_int8eq(const void *a, const void *b, FmgrInfo *flinfo)
41{
42 return (*((const int64 *) a) == *((const int64 *) b));
43}
44static bool
45gbt_int8le(const void *a, const void *b, FmgrInfo *flinfo)
46{
47 return (*((const int64 *) a) <= *((const int64 *) b));
48}
49static bool
50gbt_int8lt(const void *a, const void *b, FmgrInfo *flinfo)
51{
52 return (*((const int64 *) a) < *((const int64 *) b));
53}
54
55static int
56gbt_int8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
57{
58 int64KEY *ia = (int64KEY *) (((const Nsrt *) a)->t);
59 int64KEY *ib = (int64KEY *) (((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_int8_dist(const void *a, const void *b, FmgrInfo *flinfo)
74{
75 return GET_FLOAT_DISTANCE(int64, a, b);
76}
77
78
79static const gbtree_ninfo tinfo =
80{
82 sizeof(int64),
83 16, /* sizeof(gbtreekey16) */
91};
92
93
97{
100 int64 r;
101 int64 ra;
102
103 if (pg_sub_s64_overflow(a, b, &r) ||
104 r == PG_INT64_MIN)
106 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
107 errmsg("bigint out of range")));
108
109 ra = i64abs(r);
110
111 PG_RETURN_INT64(ra);
112}
113
114
115/**************************************************
116 * int64 ops
117 **************************************************/
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 int64 query = PG_GETARG_INT64(1);
142
143 /* Oid subtype = PG_GETARG_OID(3); */
144 bool *recheck = (bool *) PG_GETARG_POINTER(4);
145 int64KEY *kkk = (int64KEY *) 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
158
159Datum
161{
162 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
163 int64 query = PG_GETARG_INT64(1);
164
165 /* Oid subtype = PG_GETARG_OID(3); */
166 int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
168
169 key.lower = (GBT_NUMKEY *) &kkk->lower;
170 key.upper = (GBT_NUMKEY *) &kkk->upper;
171
173 &tinfo, fcinfo->flinfo));
174}
175
176
177Datum
179{
181 void *out = palloc(sizeof(int64KEY));
182
183 *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
184 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
185}
186
187
188Datum
190{
191 int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
193 float *result = (float *) PG_GETARG_POINTER(2);
194
195 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
196
197 PG_RETURN_POINTER(result);
198}
199
200Datum
202{
205 &tinfo, fcinfo->flinfo));
206}
207
208Datum
210{
213 bool *result = (bool *) PG_GETARG_POINTER(2);
214
215 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
216 PG_RETURN_POINTER(result);
217}
@ gbt_t_int8
Definition: btree_gist.h:19
static bool gbt_int8lt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:50
Datum gbt_int8_picksplit(PG_FUNCTION_ARGS)
Definition: btree_int8.c:201
Datum gbt_int8_consistent(PG_FUNCTION_ARGS)
Definition: btree_int8.c:137
Datum gbt_int8_union(PG_FUNCTION_ARGS)
Definition: btree_int8.c:178
static float8 gbt_int8_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:73
Datum gbt_int8_distance(PG_FUNCTION_ARGS)
Definition: btree_int8.c:160
Datum gbt_int8_penalty(PG_FUNCTION_ARGS)
Definition: btree_int8.c:189
static bool gbt_int8eq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:40
static int gbt_int8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:56
static const gbtree_ninfo tinfo
Definition: btree_int8.c:79
struct int64key int64KEY
Datum gbt_int8_compress(PG_FUNCTION_ARGS)
Definition: btree_int8.c:121
Datum gbt_int8_fetch(PG_FUNCTION_ARGS)
Definition: btree_int8.c:129
static bool gbt_int8ge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:35
Datum gbt_int8_same(PG_FUNCTION_ARGS)
Definition: btree_int8.c:209
static bool gbt_int8gt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:30
PG_FUNCTION_INFO_V1(gbt_int8_compress)
static bool gbt_int8le(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_int8.c:45
Datum int8_dist(PG_FUNCTION_ARGS)
Definition: btree_int8.c:96
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)
#define GET_FLOAT_DISTANCE(t, arg1, arg2)
char GBT_NUMKEY
int64_t int64
Definition: c.h:485
double float8
Definition: c.h:587
#define PG_INT64_MIN
Definition: c.h:548
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#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
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:262
int b
Definition: isn.c:69
int a
Definition: isn.c:68
void * palloc(Size size)
Definition: mcxt.c:1317
uintptr_t Datum
Definition: postgres.h:69
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:161
int64 lower
Definition: btree_int8.c:12
int64 upper
Definition: btree_int8.c:13