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 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)
 
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)
 

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:311
float float4
Definition: c.h:629
pg_noinline void float_overflow_error(void)
Definition: float.c:79
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
int b
Definition: isn.c:70
int a
Definition: isn.c:69

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

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

132 {
133  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
134  float4 query = PG_GETARG_FLOAT4(1);
136 
137  /* Oid subtype = PG_GETARG_OID(3); */
138  bool *recheck = (bool *) PG_GETARG_POINTER(4);
139  float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
141 
142  /* All cases served by this function are exact */
143  *recheck = false;
144 
145  key.lower = (GBT_NUMKEY *) &kkk->lower;
146  key.upper = (GBT_NUMKEY *) &kkk->upper;
147 
148  PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
149  GIST_LEAF(entry), &tinfo,
150  fcinfo->flinfo));
151 }
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:170
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:160
float4 upper
Definition: btree_float4.c:13
float4 lower
Definition: btree_float4.c:12

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

156 {
157  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
158  float4 query = PG_GETARG_FLOAT4(1);
159 
160  /* Oid subtype = PG_GETARG_OID(3); */
161  float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
163 
164  key.lower = (GBT_NUMKEY *) &kkk->lower;
165  key.upper = (GBT_NUMKEY *) &kkk->upper;
166 
167  PG_RETURN_FLOAT8(gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry),
168  &tinfo, fcinfo->flinfo));
169 }
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 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 184 of file btree_float4.c.

185 {
186  float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
188  float *result = (float *) PG_GETARG_POINTER(2);
189 
190  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
191 
192  PG_RETURN_POINTER(result);
193 }
#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 196 of file btree_float4.c.

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

205 {
208  bool *result = (bool *) PG_GETARG_POINTER(2);
209 
210  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
211  PG_RETURN_POINTER(result);
212 }
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_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((void *) 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:1316

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/9]

PG_FUNCTION_INFO_V1 ( float4_dist  )

◆ PG_FUNCTION_INFO_V1() [2/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_compress  )

◆ PG_FUNCTION_INFO_V1() [3/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_consistent  )

◆ PG_FUNCTION_INFO_V1() [4/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_distance  )

◆ PG_FUNCTION_INFO_V1() [5/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_fetch  )

◆ PG_FUNCTION_INFO_V1() [6/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_penalty  )

◆ PG_FUNCTION_INFO_V1() [7/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_picksplit  )

◆ PG_FUNCTION_INFO_V1() [8/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_same  )

◆ PG_FUNCTION_INFO_V1() [9/9]

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().