PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_float8.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/float.h"
#include "utils/rel.h"
#include "utils/sortsupport.h"
Include dependency graph for btree_float8.c:

Go to the source code of this file.

Data Structures

struct  float8key
 

Typedefs

typedef struct float8key float8KEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_float8_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_union)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_same)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_sortsupport)
 
static bool gbt_float8gt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8ge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8eq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8le (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8lt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_float8key_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_float8_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (float8_dist)
 
Datum float8_dist (PG_FUNCTION_ARGS)
 
Datum gbt_float8_compress (PG_FUNCTION_ARGS)
 
Datum gbt_float8_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_float8_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_float8_distance (PG_FUNCTION_ARGS)
 
Datum gbt_float8_union (PG_FUNCTION_ARGS)
 
Datum gbt_float8_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_float8_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_float8_same (PG_FUNCTION_ARGS)
 
static int gbt_float8_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_float8_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Typedef Documentation

◆ float8KEY

Function Documentation

◆ float8_dist()

Datum float8_dist ( PG_FUNCTION_ARGS  )

Definition at line 115 of file btree_float8.c.

116{
119 float8 r;
120
121 r = a - b;
122 if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
124 if (unlikely(isnan(r)))
125 {
126 if (isnan(a) && isnan(b))
127 r = 0.0; /* treat NaNs as equal */
128 else if (isnan(a) || isnan(b))
129 r = get_float8_infinity(); /* max dist for NaN vs non-NaN */
130 else
131 r = 0.0; /* must be Inf - Inf case */
132 }
134}
double float8
Definition c.h:773
#define unlikely(x)
Definition c.h:497
pg_noinline void float_overflow_error(void)
Definition float.c:103
static float8 get_float8_infinity(void)
Definition float.h:68
#define PG_GETARG_FLOAT8(n)
Definition fmgr.h:283
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369
int b
Definition isn.c:74
int a
Definition isn.c:73
static int fb(int x)

References a, b, fb(), float_overflow_error(), get_float8_infinity(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

◆ gbt_float8_compress()

Datum gbt_float8_compress ( PG_FUNCTION_ARGS  )

Definition at line 142 of file btree_float8.c.

143{
144 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
145
147}
static const gbtree_ninfo tinfo
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363

References gbt_num_compress(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_float8_consistent()

Datum gbt_float8_consistent ( PG_FUNCTION_ARGS  )

Definition at line 158 of file btree_float8.c.

159{
160 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
161 float8 query = PG_GETARG_FLOAT8(1);
163#ifdef NOT_USED
164 Oid subtype = PG_GETARG_OID(3);
165#endif
166 bool *recheck = (bool *) PG_GETARG_POINTER(4);
169
170 /* All cases served by this function are exact */
171 *recheck = false;
172
173 key.lower = (GBT_NUMKEY *) &kkk->lower;
174 key.upper = (GBT_NUMKEY *) &kkk->upper;
175
176 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, strategy,
177 GIST_LEAF(entry), &tinfo,
178 fcinfo->flinfo));
179}
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, StrategyNumber strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
char GBT_NUMKEY
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_UINT16(n)
Definition fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
#define GIST_LEAF(entry)
Definition gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
unsigned int Oid
uint16 StrategyNumber
Definition stratnum.h:22
Datum key
Definition gist.h:161

References DatumGetPointer(), fb(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, PG_GETARG_FLOAT8, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, and tinfo.

◆ gbt_float8_dist()

static float8 gbt_float8_dist ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 76 of file btree_float8.c.

77{
78 float8 arg1 = *(const float8 *) a;
79 float8 arg2 = *(const float8 *) b;
80 float8 r;
81
82 r = arg1 - arg2;
83 if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2))
85 if (unlikely(isnan(r)))
86 {
87 if (isnan(arg1) && isnan(arg2))
88 r = 0.0; /* treat NaNs as equal */
89 else if (isnan(arg1) || isnan(arg2))
90 r = get_float8_infinity(); /* max dist for NaN vs non-NaN */
91 else
92 r = 0.0; /* must be Inf - Inf case */
93 }
94 return fabs(r);
95}

References a, b, fb(), float_overflow_error(), get_float8_infinity(), and unlikely.

◆ gbt_float8_distance()

Datum gbt_float8_distance ( PG_FUNCTION_ARGS  )

Definition at line 182 of file btree_float8.c.

183{
184 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
185 float8 query = PG_GETARG_FLOAT8(1);
186#ifdef NOT_USED
187 Oid subtype = PG_GETARG_OID(3);
188#endif
191
192 key.lower = (GBT_NUMKEY *) &kkk->lower;
193 key.upper = (GBT_NUMKEY *) &kkk->upper;
194
195 PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
196 &tinfo, fcinfo->flinfo));
197}
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

References DatumGetPointer(), fb(), gbt_num_distance(), GIST_LEAF, GISTENTRY::key, PG_GETARG_FLOAT8, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_FLOAT8, and tinfo.

◆ gbt_float8_fetch()

Datum gbt_float8_fetch ( PG_FUNCTION_ARGS  )

Definition at line 150 of file btree_float8.c.

151{
152 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
153
155}
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

References gbt_num_fetch(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_float8_penalty()

Datum gbt_float8_penalty ( PG_FUNCTION_ARGS  )

Definition at line 210 of file btree_float8.c.

211{
214 float *result = (float *) PG_GETARG_POINTER(2);
215
216 float_penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
217
219}
#define float_penalty_num(result, olower, oupper, nlower, nupper)
uint32 result

References DatumGetPointer(), fb(), float_penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and result.

◆ gbt_float8_picksplit()

Datum gbt_float8_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 222 of file btree_float8.c.

223{
226 &tinfo, fcinfo->flinfo));
227}
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

References gbt_num_picksplit(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_float8_same()

Datum gbt_float8_same ( PG_FUNCTION_ARGS  )

Definition at line 230 of file btree_float8.c.

231{
234 bool *result = (bool *) PG_GETARG_POINTER(2);
235
236 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
238}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

References fb(), gbt_num_same(), PG_GETARG_POINTER, PG_RETURN_POINTER, result, and tinfo.

◆ gbt_float8_sortsupport()

Datum gbt_float8_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 251 of file btree_float8.c.

252{
254
256 ssup->ssup_extra = NULL;
257
259}
static int gbt_float8_ssup_cmp(Datum x, Datum y, SortSupport ssup)
struct SortSupportData * SortSupport
Definition execnodes.h:61
#define PG_RETURN_VOID()
Definition fmgr.h:350
int(* comparator)(Datum x, Datum y, SortSupport ssup)

References SortSupportData::comparator, fb(), gbt_float8_ssup_cmp(), PG_GETARG_POINTER, PG_RETURN_VOID, and SortSupportData::ssup_extra.

◆ gbt_float8_ssup_cmp()

static int gbt_float8_ssup_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 241 of file btree_float8.c.

242{
245
246 /* for leaf items we expect lower == upper, so only compare lower */
247 return float8_cmp_internal(arg1->lower, arg2->lower);
248}
int float8_cmp_internal(float8 a, float8 b)
Definition float.c:951
int y
Definition isn.c:76
int x
Definition isn.c:75

References DatumGetPointer(), fb(), float8_cmp_internal(), x, and y.

Referenced by gbt_float8_sortsupport().

◆ gbt_float8_union()

Datum gbt_float8_union ( PG_FUNCTION_ARGS  )

Definition at line 200 of file btree_float8.c.

201{
203 void *out = palloc(sizeof(float8KEY));
204
205 *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
206 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
207}
struct float8key float8KEY
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * palloc(Size size)
Definition mcxt.c:1390

References fb(), gbt_num_union(), palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_float8eq()

static bool gbt_float8eq ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 47 of file btree_float8.c.

48{
49 return float8_eq(*((const float8 *) a), *((const float8 *) b));
50}
static bool float8_eq(const float8 val1, const float8 val2)
Definition float.h:250

References a, b, and float8_eq().

◆ gbt_float8ge()

static bool gbt_float8ge ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 42 of file btree_float8.c.

43{
44 return float8_ge(*((const float8 *) a), *((const float8 *) b));
45}
static bool float8_ge(const float8 val1, const float8 val2)
Definition float.h:310

References a, b, and float8_ge().

◆ gbt_float8gt()

static bool gbt_float8gt ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 37 of file btree_float8.c.

38{
39 return float8_gt(*((const float8 *) a), *((const float8 *) b));
40}
static bool float8_gt(const float8 val1, const float8 val2)
Definition float.h:298

References a, b, and float8_gt().

◆ gbt_float8key_cmp()

static int gbt_float8key_cmp ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 63 of file btree_float8.c.

64{
65 float8KEY *ia = (float8KEY *) (((const Nsrt *) a)->t);
66 float8KEY *ib = (float8KEY *) (((const Nsrt *) b)->t);
67 int res;
68
69 res = float8_cmp_internal(ia->lower, ib->lower);
70 if (res != 0)
71 return res;
72 return float8_cmp_internal(ia->upper, ib->upper);
73}

References a, b, fb(), and float8_cmp_internal().

◆ gbt_float8le()

static bool gbt_float8le ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 52 of file btree_float8.c.

53{
54 return float8_le(*((const float8 *) a), *((const float8 *) b));
55}
static bool float8_le(const float8 val1, const float8 val2)
Definition float.h:286

References a, b, and float8_le().

◆ gbt_float8lt()

static bool gbt_float8lt ( const void a,
const void b,
FmgrInfo flinfo 
)
static

Definition at line 57 of file btree_float8.c.

58{
59 return float8_lt(*((const float8 *) a), *((const float8 *) b));
60}
static bool float8_lt(const float8 val1, const float8 val2)
Definition float.h:274

References a, b, and float8_lt().

◆ PG_FUNCTION_INFO_V1() [1/10]

PG_FUNCTION_INFO_V1 ( float8_dist  )

◆ PG_FUNCTION_INFO_V1() [2/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_compress  )

◆ PG_FUNCTION_INFO_V1() [3/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_consistent  )

◆ PG_FUNCTION_INFO_V1() [4/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_distance  )

◆ PG_FUNCTION_INFO_V1() [5/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_fetch  )

◆ PG_FUNCTION_INFO_V1() [6/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_penalty  )

◆ PG_FUNCTION_INFO_V1() [7/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_picksplit  )

◆ PG_FUNCTION_INFO_V1() [8/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_same  )

◆ PG_FUNCTION_INFO_V1() [9/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [10/10]

PG_FUNCTION_INFO_V1 ( gbt_float8_union  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(float8),
16,
}
static bool gbt_float8eq(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float8gt(const void *a, const void *b, FmgrInfo *flinfo)
static float8 gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float8le(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float8ge(const void *a, const void *b, FmgrInfo *flinfo)
static int gbt_float8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float8lt(const void *a, const void *b, FmgrInfo *flinfo)
@ gbt_t_float8
Definition btree_gist.h:21

Definition at line 98 of file btree_float8.c.

99{
101 sizeof(float8),
102 16, /* sizeof(gbtreekey16) */
110};

Referenced by gbt_float8_compress(), gbt_float8_consistent(), gbt_float8_distance(), gbt_float8_fetch(), gbt_float8_picksplit(), gbt_float8_same(), and gbt_float8_union().