PostgreSQL Source Code git master
btree_float4.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/float.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

typedef struct float4key float4KEY

Function Documentation

◆ float4_dist()

Datum float4_dist ( PG_FUNCTION_ARGS  )

Definition at line 95 of file btree_float4.c.

96{
99 float4 r;
100
101 r = a - b;
102 if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
104
105 PG_RETURN_FLOAT4(fabsf(r));
106}
#define unlikely(x)
Definition: c.h:347
float float4
Definition: c.h:600
pg_noinline void float_overflow_error(void)
Definition: float.c:86
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
int b
Definition: isn.c:74
int a
Definition: isn.c:73

References a, b, float_overflow_error(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and unlikely.

◆ gbt_float4_compress()

Datum gbt_float4_compress ( PG_FUNCTION_ARGS  )

Definition at line 114 of file btree_float4.c.

115{
116 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
117
119}
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361

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

131{
132 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
133 float4 query = PG_GETARG_FLOAT4(1);
135
136 /* Oid subtype = PG_GETARG_OID(3); */
137 bool *recheck = (bool *) PG_GETARG_POINTER(4);
138 float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
140
141 /* All cases served by this function are exact */
142 *recheck = false;
143
144 key.lower = (GBT_NUMKEY *) &kkk->lower;
145 key.upper = (GBT_NUMKEY *) &kkk->upper;
146
147 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
148 GIST_LEAF(entry), &tinfo,
149 fcinfo->flinfo));
150}
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_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:161
float4 upper
Definition: btree_float4.c:14
float4 lower
Definition: btree_float4.c:13

References DatumGetPointer(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, sort-test::key, float4key::lower, PG_GETARG_FLOAT4, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, tinfo, and float4key::upper.

◆ gbt_float4_dist()

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

Definition at line 72 of file btree_float4.c.

73{
74 return GET_FLOAT_DISTANCE(float4, a, b);
75}
#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 153 of file btree_float4.c.

154{
155 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
156 float4 query = PG_GETARG_FLOAT4(1);
157
158 /* Oid subtype = PG_GETARG_OID(3); */
159 float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
161
162 key.lower = (GBT_NUMKEY *) &kkk->lower;
163 key.upper = (GBT_NUMKEY *) &kkk->upper;
164
166 &tinfo, fcinfo->flinfo));
167}
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:367

References DatumGetPointer(), gbt_num_distance(), GIST_LEAF, GISTENTRY::key, sort-test::key, float4key::lower, PG_GETARG_FLOAT4, PG_GETARG_POINTER, PG_RETURN_FLOAT8, tinfo, and float4key::upper.

◆ gbt_float4_fetch()

Datum gbt_float4_fetch ( PG_FUNCTION_ARGS  )

Definition at line 122 of file btree_float4.c.

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

181{
182 float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
184 float *result = (float *) PG_GETARG_POINTER(2);
185
186 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
187
188 PG_RETURN_POINTER(result);
189}
#define penalty_num(result, olower, oupper, nlower, nupper)

References DatumGetPointer(), sort-test::key, float4key::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and float4key::upper.

◆ gbt_float4_picksplit()

Datum gbt_float4_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 192 of file btree_float4.c.

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

201{
204 bool *result = (bool *) PG_GETARG_POINTER(2);
205
206 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
207 PG_RETURN_POINTER(result);
208}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_float4_sortsupport()

Datum gbt_float4_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 221 of file btree_float4.c.

222{
224
226 ssup->ssup_extra = NULL;
227
229}
static int gbt_float4_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_float4.c:211
#define PG_RETURN_VOID()
Definition: fmgr.h:349
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87

References SortSupportData::comparator, 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 211 of file btree_float4.c.

212{
215
216 /* for leaf items we expect lower == upper, so only compare lower */
217 return float4_cmp_internal(arg1->lower, arg2->lower);
218}
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(), float4_cmp_internal(), float4key::lower, x, and y.

Referenced by gbt_float4_sortsupport().

◆ gbt_float4_union()

Datum gbt_float4_union ( PG_FUNCTION_ARGS  )

Definition at line 170 of file btree_float4.c.

171{
173 void *out = palloc(sizeof(float4KEY));
174
175 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
176 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
177}
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:1945

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

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

References a, and b.

◆ gbt_float4ge()

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

Definition at line 34 of file btree_float4.c.

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

References a, and b.

◆ gbt_float4gt()

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

Definition at line 29 of file btree_float4.c.

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

References a, and b.

◆ gbt_float4key_cmp()

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

Definition at line 55 of file btree_float4.c.

56{
57 float4KEY *ia = (float4KEY *) (((const Nsrt *) a)->t);
58 float4KEY *ib = (float4KEY *) (((const Nsrt *) b)->t);
59
60 if (ia->lower == ib->lower)
61 {
62 if (ia->upper == ib->upper)
63 return 0;
64
65 return (ia->upper > ib->upper) ? 1 : -1;
66 }
67
68 return (ia->lower > ib->lower) ? 1 : -1;
69}

References a, b, float4key::lower, and float4key::upper.

◆ gbt_float4le()

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

Definition at line 44 of file btree_float4.c.

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

References a, and b.

◆ gbt_float4lt()

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

Definition at line 49 of file btree_float4.c.

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

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)
Definition: btree_float4.c:39
static bool gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:29
static float8 gbt_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:72
static bool gbt_float4le(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:44
static int gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:55
static bool gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:49
static bool gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:34
@ gbt_t_float4
Definition: btree_gist.h:20

Definition at line 78 of file btree_float4.c.

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