PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_float4.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_float4.c
3 */
4#include "postgres.h"
5
6#include "btree_gist.h"
7#include "btree_utils_num.h"
8#include "utils/float.h"
9#include "utils/rel.h"
10#include "utils/sortsupport.h"
11
17
18/* GiST support functions */
28
29static bool
30gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
31{
32 return (*((const float4 *) a) > *((const float4 *) b));
33}
34static bool
35gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
36{
37 return (*((const float4 *) a) >= *((const float4 *) b));
38}
39static bool
40gbt_float4eq(const void *a, const void *b, FmgrInfo *flinfo)
41{
42 return (*((const float4 *) a) == *((const float4 *) b));
43}
44static bool
45gbt_float4le(const void *a, const void *b, FmgrInfo *flinfo)
46{
47 return (*((const float4 *) a) <= *((const float4 *) b));
48}
49static bool
50gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
51{
52 return (*((const float4 *) a) < *((const float4 *) b));
53}
54
55static int
56gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
57{
58 float4KEY *ia = (float4KEY *) (((const Nsrt *) a)->t);
59 float4KEY *ib = (float4KEY *) (((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_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
74{
75 return GET_FLOAT_DISTANCE(float4, a, b);
76}
77
78
79static const gbtree_ninfo tinfo =
80{
82 sizeof(float4),
83 8, /* sizeof(gbtreekey8) */
91};
92
93
97{
100 float4 r;
101
102 r = a - b;
103 if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
105
107}
108
109
110/**************************************************
111 * GiST support functions
112 **************************************************/
113
114Datum
121
122Datum
129
130Datum
132{
133 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
134 float4 query = PG_GETARG_FLOAT4(1);
136#ifdef NOT_USED
137 Oid subtype = PG_GETARG_OID(3);
138#endif
139 bool *recheck = (bool *) PG_GETARG_POINTER(4);
141 GBT_NUMKEY_R key;
142
143 /* All cases served by this function are exact */
144 *recheck = false;
145
146 key.lower = (GBT_NUMKEY *) &kkk->lower;
147 key.upper = (GBT_NUMKEY *) &kkk->upper;
148
149 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
150 GIST_LEAF(entry), &tinfo,
151 fcinfo->flinfo));
152}
153
154Datum
156{
157 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
158 float4 query = PG_GETARG_FLOAT4(1);
159#ifdef NOT_USED
160 Oid subtype = PG_GETARG_OID(3);
161#endif
163 GBT_NUMKEY_R key;
164
165 key.lower = (GBT_NUMKEY *) &kkk->lower;
166 key.upper = (GBT_NUMKEY *) &kkk->upper;
167
168 PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
169 &tinfo, fcinfo->flinfo));
170}
171
172Datum
174{
176 void *out = palloc(sizeof(float4KEY));
177
178 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
179 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
180}
181
182Datum
184{
187 float *result = (float *) PG_GETARG_POINTER(2);
188
189 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
190
191 PG_RETURN_POINTER(result);
192}
193
194Datum
201
202Datum
204{
207 bool *result = (bool *) PG_GETARG_POINTER(2);
208
209 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
210 PG_RETURN_POINTER(result);
211}
212
213static int
215{
218
219 /* for leaf items we expect lower == upper, so only compare lower */
220 return float4_cmp_internal(arg1->lower, arg2->lower);
221}
222
223Datum
static bool gbt_float4eq(const void *a, const void *b, FmgrInfo *flinfo)
Datum gbt_float4_compress(PG_FUNCTION_ARGS)
Datum gbt_float4_same(PG_FUNCTION_ARGS)
Datum gbt_float4_union(PG_FUNCTION_ARGS)
Datum gbt_float4_picksplit(PG_FUNCTION_ARGS)
static bool gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
Datum gbt_float4_sortsupport(PG_FUNCTION_ARGS)
Datum gbt_float4_penalty(PG_FUNCTION_ARGS)
Datum gbt_float4_fetch(PG_FUNCTION_ARGS)
static float8 gbt_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float4le(const void *a, const void *b, FmgrInfo *flinfo)
static const gbtree_ninfo tinfo
struct float4key float4KEY
Datum gbt_float4_distance(PG_FUNCTION_ARGS)
Datum float4_dist(PG_FUNCTION_ARGS)
static int gbt_float4_ssup_cmp(Datum x, Datum y, SortSupport ssup)
static int gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
Datum gbt_float4_consistent(PG_FUNCTION_ARGS)
static bool gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
@ gbt_t_float4
Definition btree_gist.h:20
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
double float8
Definition c.h:644
#define unlikely(x)
Definition c.h:412
float float4
Definition c.h:643
pg_noinline void float_overflow_error(void)
Definition float.c:86
int float4_cmp_internal(float4 a, float4 b)
Definition float.c:816
#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_GETARG_FLOAT4(n)
Definition fmgr.h:282
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define PG_RETURN_FLOAT4(x)
Definition fmgr.h:368
#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
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)
float4 upper
float4 lower