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.

References Abs, float_overflow_error(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, and unlikely.

96 {
97  float4 a = PG_GETARG_FLOAT4(0);
98  float4 b = PG_GETARG_FLOAT4(1);
99  float4 r;
100 
101  r = a - b;
102  if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
104 
105  PG_RETURN_FLOAT4(Abs(r));
106 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define Abs(x)
Definition: c.h:992
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float float4
Definition: c.h:564
pg_noinline void float_overflow_error(void)
Definition: float.c:84
#define unlikely(x)
Definition: c.h:273

◆ gbt_float4_compress()

Datum gbt_float4_compress ( PG_FUNCTION_ARGS  )

Definition at line 115 of file btree_float4.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

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

◆ gbt_float4_consistent()

Datum gbt_float4_consistent ( PG_FUNCTION_ARGS  )

Definition at line 131 of file btree_float4.c.

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

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 }
#define GIST_LEAF(entry)
Definition: gist.h:170
float4 lower
Definition: btree_float4.c:12
const GBT_NUMKEY * lower
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum key
Definition: gist.h:160
char GBT_NUMKEY
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float4 upper
Definition: btree_float4.c:13
float float4
Definition: c.h:564
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define DatumGetPointer(X)
Definition: postgres.h:593
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78

◆ 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.

References GET_FLOAT_DISTANCE.

73 {
74  return GET_FLOAT_DISTANCE(float4, a, b);
75 }
float float4
Definition: c.h:564
#define GET_FLOAT_DISTANCE(t, arg1, arg2)

◆ gbt_float4_distance()

Datum gbt_float4_distance ( PG_FUNCTION_ARGS  )

Definition at line 155 of file btree_float4.c.

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

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 }
#define GIST_LEAF(entry)
Definition: gist.h:170
float4 lower
Definition: btree_float4.c:12
const GBT_NUMKEY * lower
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
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
Datum key
Definition: gist.h:160
char GBT_NUMKEY
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
float4 upper
Definition: btree_float4.c:13
float float4
Definition: c.h:564
#define DatumGetPointer(X)
Definition: postgres.h:593
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78

◆ gbt_float4_fetch()

Datum gbt_float4_fetch ( PG_FUNCTION_ARGS  )

Definition at line 123 of file btree_float4.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

124 {
125  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
126 
128 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78

◆ gbt_float4_penalty()

Datum gbt_float4_penalty ( PG_FUNCTION_ARGS  )

Definition at line 184 of file btree_float4.c.

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

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 
194 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
float4 lower
Definition: btree_float4.c:12
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define penalty_num(result, olower, oupper, nlower, nupper)
float4 upper
Definition: btree_float4.c:13
#define DatumGetPointer(X)
Definition: postgres.h:593

◆ gbt_float4_picksplit()

Datum gbt_float4_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 197 of file btree_float4.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

198 {
201  &tinfo, fcinfo->flinfo));
202 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78

◆ gbt_float4_same()

Datum gbt_float4_same ( PG_FUNCTION_ARGS  )

Definition at line 205 of file btree_float4.c.

References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

206 {
209  bool *result = (bool *) PG_GETARG_POINTER(2);
210 
211  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
212  PG_RETURN_POINTER(result);
213 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78

◆ gbt_float4_union()

Datum gbt_float4_union ( PG_FUNCTION_ARGS  )

Definition at line 173 of file btree_float4.c.

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

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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
struct float4key float4KEY
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static const gbtree_ninfo tinfo
Definition: btree_float4.c:78
void * palloc(Size size)
Definition: mcxt.c:1062
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

◆ 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 }
float float4
Definition: c.h:564

◆ 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 }
float float4
Definition: c.h:564

◆ 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 }
float float4
Definition: c.h:564

◆ 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.

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

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 }
float4 lower
Definition: btree_float4.c:12
float4 upper
Definition: btree_float4.c:13

◆ 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 }
float float4
Definition: c.h:564

◆ 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 }
float float4
Definition: c.h:564

◆ PG_FUNCTION_INFO_V1() [1/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_compress  )

◆ PG_FUNCTION_INFO_V1() [2/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_fetch  )

◆ PG_FUNCTION_INFO_V1() [3/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_union  )

◆ PG_FUNCTION_INFO_V1() [4/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_consistent  )

◆ PG_FUNCTION_INFO_V1() [6/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_distance  )

◆ PG_FUNCTION_INFO_V1() [7/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_penalty  )

◆ PG_FUNCTION_INFO_V1() [8/9]

PG_FUNCTION_INFO_V1 ( gbt_float4_same  )

◆ PG_FUNCTION_INFO_V1() [9/9]

PG_FUNCTION_INFO_V1 ( float4_dist  )

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_float4le(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:44
static bool gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:49
static bool gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:29
static int gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:55
float float4
Definition: c.h:564
static bool gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:34
static float8 gbt_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:72

Definition at line 78 of file btree_float4.c.