PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_float4.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_float4.c:

Go to the source code of this file.

Data Structures

struct  float4key
 

Typedefs

typedef struct float4key float4KEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_float4_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_union)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_same)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_sortsupport)
 
static bool gbt_float4gt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4ge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4eq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4le (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4lt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_float4key_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_float4_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (float4_dist)
 
Datum float4_dist (PG_FUNCTION_ARGS)
 
Datum gbt_float4_compress (PG_FUNCTION_ARGS)
 
Datum gbt_float4_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_float4_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_float4_distance (PG_FUNCTION_ARGS)
 
Datum gbt_float4_union (PG_FUNCTION_ARGS)
 
Datum gbt_float4_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_float4_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_float4_same (PG_FUNCTION_ARGS)
 
static int gbt_float4_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_float4_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Typedef Documentation

◆ float4KEY

Function Documentation

◆ float4_dist()

Datum float4_dist ( PG_FUNCTION_ARGS  )

Definition at line 113 of file btree_float4.c.

114{
117 float4 r;
118
119 r = a - b;
120 if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
122 if (unlikely(isnan(r)))
123 {
124 if (isnan(a) && isnan(b))
125 r = 0.0; /* treat NaNs as equal */
126 else if (isnan(a) || isnan(b))
127 r = get_float4_infinity(); /* max dist for NaN vs non-NaN */
128 else
129 r = 0.0; /* must be Inf - Inf case */
130 }
132}
#define unlikely(x)
Definition c.h:497
float float4
Definition c.h:772
pg_noinline void float_overflow_error(void)
Definition float.c:103
static float4 get_float4_infinity(void)
Definition float.h:61
#define PG_GETARG_FLOAT4(n)
Definition fmgr.h:282
#define PG_RETURN_FLOAT4(x)
Definition fmgr.h:368
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_float4_infinity(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and unlikely.

◆ gbt_float4_compress()

Datum gbt_float4_compress ( PG_FUNCTION_ARGS  )

Definition at line 140 of file btree_float4.c.

141{
142 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
143
145}
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_float4_consistent()

Datum gbt_float4_consistent ( PG_FUNCTION_ARGS  )

Definition at line 156 of file btree_float4.c.

157{
158 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
159 float4 query = PG_GETARG_FLOAT4(1);
161#ifdef NOT_USED
162 Oid subtype = PG_GETARG_OID(3);
163#endif
164 bool *recheck = (bool *) PG_GETARG_POINTER(4);
167
168 /* All cases served by this function are exact */
169 *recheck = false;
170
171 key.lower = (GBT_NUMKEY *) &kkk->lower;
172 key.upper = (GBT_NUMKEY *) &kkk->upper;
173
174 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, strategy,
175 GIST_LEAF(entry), &tinfo,
176 fcinfo->flinfo));
177}
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_FLOAT4, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, and tinfo.

◆ gbt_float4_dist()

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

Definition at line 75 of file btree_float4.c.

76{
77 float8 arg1 = *(const float4 *) a;
78 float8 arg2 = *(const float4 *) b;
79 float8 r;
80
81 r = arg1 - arg2;
82 /* needn't consider isinf case here, must be due to input infinity */
83 if (unlikely(isnan(r)))
84 {
85 if (isnan(arg1) && isnan(arg2))
86 r = 0.0; /* treat NaNs as equal */
87 else if (isnan(arg1) || isnan(arg2))
88 r = get_float8_infinity(); /* max dist for NaN vs non-NaN */
89 else
90 r = 0.0; /* must be Inf - Inf case */
91 }
92 return fabs(r);
93}
double float8
Definition c.h:773
static float8 get_float8_infinity(void)
Definition float.h:68

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

◆ gbt_float4_distance()

Datum gbt_float4_distance ( PG_FUNCTION_ARGS  )

Definition at line 180 of file btree_float4.c.

181{
182 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
183 float4 query = PG_GETARG_FLOAT4(1);
184#ifdef NOT_USED
185 Oid subtype = PG_GETARG_OID(3);
186#endif
189
190 key.lower = (GBT_NUMKEY *) &kkk->lower;
191 key.upper = (GBT_NUMKEY *) &kkk->upper;
192
193 PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
194 &tinfo, fcinfo->flinfo));
195}
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369

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

◆ gbt_float4_fetch()

Datum gbt_float4_fetch ( PG_FUNCTION_ARGS  )

Definition at line 148 of file btree_float4.c.

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

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

◆ gbt_float4_penalty()

Datum gbt_float4_penalty ( PG_FUNCTION_ARGS  )

Definition at line 208 of file btree_float4.c.

209{
212 float *result = (float *) PG_GETARG_POINTER(2);
213
214 float_penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
215
217}
#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_float4_picksplit()

Datum gbt_float4_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 220 of file btree_float4.c.

221{
224 &tinfo, fcinfo->flinfo));
225}
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_float4_same()

Datum gbt_float4_same ( PG_FUNCTION_ARGS  )

Definition at line 228 of file btree_float4.c.

229{
232 bool *result = (bool *) PG_GETARG_POINTER(2);
233
234 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
236}
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_float4_sortsupport()

Datum gbt_float4_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 249 of file btree_float4.c.

250{
252
254 ssup->ssup_extra = NULL;
255
257}
static int gbt_float4_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_float4_ssup_cmp(), PG_GETARG_POINTER, PG_RETURN_VOID, and SortSupportData::ssup_extra.

◆ gbt_float4_ssup_cmp()

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

Definition at line 239 of file btree_float4.c.

240{
243
244 /* for leaf items we expect lower == upper, so only compare lower */
245 return float4_cmp_internal(arg1->lower, arg2->lower);
246}
int float4_cmp_internal(float4 a, float4 b)
Definition float.c:857
int y
Definition isn.c:76
int x
Definition isn.c:75

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

Referenced by gbt_float4_sortsupport().

◆ gbt_float4_union()

Datum gbt_float4_union ( PG_FUNCTION_ARGS  )

Definition at line 198 of file btree_float4.c.

199{
201 void *out = palloc(sizeof(float4KEY));
202
203 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
204 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
205}
struct float4key float4KEY
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_float4eq()

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

Definition at line 46 of file btree_float4.c.

47{
48 return float4_eq(*((const float4 *) a), *((const float4 *) b));
49}
static bool float4_eq(const float4 val1, const float4 val2)
Definition float.h:244

References a, b, and float4_eq().

◆ gbt_float4ge()

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

Definition at line 41 of file btree_float4.c.

42{
43 return float4_ge(*((const float4 *) a), *((const float4 *) b));
44}
static bool float4_ge(const float4 val1, const float4 val2)
Definition float.h:304

References a, b, and float4_ge().

◆ gbt_float4gt()

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

Definition at line 36 of file btree_float4.c.

37{
38 return float4_gt(*((const float4 *) a), *((const float4 *) b));
39}
static bool float4_gt(const float4 val1, const float4 val2)
Definition float.h:292

References a, b, and float4_gt().

◆ gbt_float4key_cmp()

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

Definition at line 62 of file btree_float4.c.

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

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

◆ gbt_float4le()

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

Definition at line 51 of file btree_float4.c.

52{
53 return float4_le(*((const float4 *) a), *((const float4 *) b));
54}
static bool float4_le(const float4 val1, const float4 val2)
Definition float.h:280

References a, b, and float4_le().

◆ gbt_float4lt()

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

Definition at line 56 of file btree_float4.c.

57{
58 return float4_lt(*((const float4 *) a), *((const float4 *) b));
59}
static bool float4_lt(const float4 val1, const float4 val2)
Definition float.h:268

References a, b, and float4_lt().

◆ PG_FUNCTION_INFO_V1() [1/10]

PG_FUNCTION_INFO_V1 ( float4_dist  )

◆ PG_FUNCTION_INFO_V1() [2/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_compress  )

◆ PG_FUNCTION_INFO_V1() [3/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_consistent  )

◆ PG_FUNCTION_INFO_V1() [4/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_distance  )

◆ PG_FUNCTION_INFO_V1() [5/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_fetch  )

◆ PG_FUNCTION_INFO_V1() [6/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_penalty  )

◆ PG_FUNCTION_INFO_V1() [7/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_picksplit  )

◆ PG_FUNCTION_INFO_V1() [8/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_same  )

◆ PG_FUNCTION_INFO_V1() [9/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [10/10]

PG_FUNCTION_INFO_V1 ( gbt_float4_union  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(float4),
8,
}
static bool gbt_float4eq(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
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 int gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
static bool gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
@ gbt_t_float4
Definition btree_gist.h:20

Definition at line 96 of file btree_float4.c.

97{
99 sizeof(float4),
100 8, /* sizeof(gbtreekey8) */
108};

Referenced by gbt_float4_compress(), gbt_float4_consistent(), gbt_float4_distance(), gbt_float4_fetch(), gbt_float4_picksplit(), gbt_float4_same(), and gbt_float4_union().