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 96 of file btree_float4.c.

97{
100 float4 r;
101
102 r = a - b;
103 if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
105
107}
#define unlikely(x)
Definition c.h:412
float float4
Definition c.h:643
pg_noinline void float_overflow_error(void)
Definition float.c:86
#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(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and unlikely.

◆ gbt_float4_compress()

Datum gbt_float4_compress ( PG_FUNCTION_ARGS  )

Definition at line 115 of file btree_float4.c.

116{
117 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
118
120}
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 131 of file btree_float4.c.

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);
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}
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const 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:342
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 73 of file btree_float4.c.

74{
75 return GET_FLOAT_DISTANCE(float4, a, b);
76}
#define GET_FLOAT_DISTANCE(t, arg1, arg2)

References a, b, and GET_FLOAT_DISTANCE.

◆ gbt_float4_distance()

Datum gbt_float4_distance ( PG_FUNCTION_ARGS  )

Definition at line 155 of file btree_float4.c.

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
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}
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 123 of file btree_float4.c.

124{
125 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
126
128}
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 183 of file btree_float4.c.

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}
#define penalty_num(result, olower, oupper, nlower, nupper)

References DatumGetPointer(), fb(), penalty_num, PG_GETARG_POINTER, and PG_RETURN_POINTER.

◆ gbt_float4_picksplit()

Datum gbt_float4_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 195 of file btree_float4.c.

196{
199 &tinfo, fcinfo->flinfo));
200}
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 203 of file btree_float4.c.

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}
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, and tinfo.

◆ gbt_float4_sortsupport()

Datum gbt_float4_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 224 of file btree_float4.c.

225{
227
229 ssup->ssup_extra = NULL;
230
232}
static int gbt_float4_ssup_cmp(Datum x, Datum y, SortSupport ssup)
#define PG_RETURN_VOID()
Definition fmgr.h:350
struct SortSupportData * SortSupport
Definition sortsupport.h:58
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 214 of file btree_float4.c.

215{
218
219 /* for leaf items we expect lower == upper, so only compare lower */
220 return float4_cmp_internal(arg1->lower, arg2->lower);
221}
int float4_cmp_internal(float4 a, float4 b)
Definition float.c:816
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 173 of file btree_float4.c.

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}
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:1387

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 40 of file btree_float4.c.

41{
42 return (*((const float4 *) a) == *((const float4 *) b));
43}

References a, and b.

◆ gbt_float4ge()

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

Definition at line 35 of file btree_float4.c.

36{
37 return (*((const float4 *) a) >= *((const float4 *) b));
38}

References a, and b.

◆ gbt_float4gt()

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

Definition at line 30 of file btree_float4.c.

31{
32 return (*((const float4 *) a) > *((const float4 *) b));
33}

References a, and b.

◆ gbt_float4key_cmp()

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

Definition at line 56 of file btree_float4.c.

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}

References a, b, and fb().

◆ gbt_float4le()

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

Definition at line 45 of file btree_float4.c.

46{
47 return (*((const float4 *) a) <= *((const float4 *) b));
48}

References a, and b.

◆ gbt_float4lt()

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

Definition at line 50 of file btree_float4.c.

51{
52 return (*((const float4 *) a) < *((const float4 *) b));
53}

References a, and b.

◆ 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 79 of file btree_float4.c.

80{
82 sizeof(float4),
83 8, /* sizeof(gbtreekey8) */
91};

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