PostgreSQL Source Code  git master
btree_float8.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/float.h"
Include dependency graph for btree_float8.c:

Go to the source code of this file.

Data Structures

struct  float8key
 

Typedefs

typedef struct float8key float8KEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_float8_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_union)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_same)
 
static bool gbt_float8gt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8ge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8eq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8le (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8lt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_float8key_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_float8_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (float8_dist)
 
Datum float8_dist (PG_FUNCTION_ARGS)
 
Datum gbt_float8_compress (PG_FUNCTION_ARGS)
 
Datum gbt_float8_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_float8_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_float8_distance (PG_FUNCTION_ARGS)
 
Datum gbt_float8_union (PG_FUNCTION_ARGS)
 
Datum gbt_float8_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_float8_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_float8_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Typedef Documentation

◆ float8KEY

typedef struct float8key float8KEY

Function Documentation

◆ float8_dist()

Datum float8_dist ( PG_FUNCTION_ARGS  )

Definition at line 103 of file btree_float8.c.

104 {
107  float8 r;
108 
109  r = a - b;
110  if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
112 
113  PG_RETURN_FLOAT8(fabs(r));
114 }
double float8
Definition: c.h:630
#define unlikely(x)
Definition: c.h:311
pg_noinline void float_overflow_error(void)
Definition: float.c:79
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
int b
Definition: isn.c:70
int a
Definition: isn.c:69

References a, b, float_overflow_error(), PG_GETARG_FLOAT8, PG_RETURN_FLOAT8, and unlikely.

◆ gbt_float8_compress()

Datum gbt_float8_compress ( PG_FUNCTION_ARGS  )

Definition at line 122 of file btree_float8.c.

123 {
124  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
125 
127 }
static const gbtree_ninfo tinfo
Definition: btree_float8.c:86
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_float8_consistent()

Datum gbt_float8_consistent ( PG_FUNCTION_ARGS  )

Definition at line 138 of file btree_float8.c.

139 {
140  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
141  float8 query = PG_GETARG_FLOAT8(1);
143 
144  /* Oid subtype = PG_GETARG_OID(3); */
145  bool *recheck = (bool *) PG_GETARG_POINTER(4);
146  float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
148 
149  /* All cases served by this function are exact */
150  *recheck = false;
151 
152  key.lower = (GBT_NUMKEY *) &kkk->lower;
153  key.upper = (GBT_NUMKEY *) &kkk->upper;
154 
155  PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
156  GIST_LEAF(entry), &tinfo,
157  fcinfo->flinfo));
158 }
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
float8 upper
Definition: btree_float8.c:13
float8 lower
Definition: btree_float8.c:12

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

◆ gbt_float8_dist()

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

Definition at line 73 of file btree_float8.c.

74 {
75  float8 arg1 = *(const float8 *) a;
76  float8 arg2 = *(const float8 *) b;
77  float8 r;
78 
79  r = arg1 - arg2;
80  if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2))
82  return fabs(r);
83 }

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

◆ gbt_float8_distance()

Datum gbt_float8_distance ( PG_FUNCTION_ARGS  )

Definition at line 162 of file btree_float8.c.

163 {
164  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
165  float8 query = PG_GETARG_FLOAT8(1);
166 
167  /* Oid subtype = PG_GETARG_OID(3); */
168  float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
170 
171  key.lower = (GBT_NUMKEY *) &kkk->lower;
172  key.upper = (GBT_NUMKEY *) &kkk->upper;
173 
174  PG_RETURN_FLOAT8(gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry),
175  &tinfo, fcinfo->flinfo));
176 }
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_float8_fetch()

Datum gbt_float8_fetch ( PG_FUNCTION_ARGS  )

Definition at line 130 of file btree_float8.c.

131 {
132  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
133 
135 }
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

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

◆ gbt_float8_penalty()

Datum gbt_float8_penalty ( PG_FUNCTION_ARGS  )

Definition at line 191 of file btree_float8.c.

192 {
193  float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
195  float *result = (float *) PG_GETARG_POINTER(2);
196 
197  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
198 
199  PG_RETURN_POINTER(result);
200 }
#define penalty_num(result, olower, oupper, nlower, nupper)

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

◆ gbt_float8_picksplit()

Datum gbt_float8_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 203 of file btree_float8.c.

204 {
207  &tinfo, fcinfo->flinfo));
208 }
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_float8_same()

Datum gbt_float8_same ( PG_FUNCTION_ARGS  )

Definition at line 211 of file btree_float8.c.

212 {
215  bool *result = (bool *) PG_GETARG_POINTER(2);
216 
217  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
218  PG_RETURN_POINTER(result);
219 }
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_float8_union()

Datum gbt_float8_union ( PG_FUNCTION_ARGS  )

Definition at line 180 of file btree_float8.c.

181 {
183  void *out = palloc(sizeof(float8KEY));
184 
185  *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
186  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
187 }
struct float8key float8KEY
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_float8eq()

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

Definition at line 40 of file btree_float8.c.

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

References a, and b.

◆ gbt_float8ge()

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

Definition at line 35 of file btree_float8.c.

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

References a, and b.

◆ gbt_float8gt()

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

Definition at line 30 of file btree_float8.c.

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

References a, and b.

◆ gbt_float8key_cmp()

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

Definition at line 56 of file btree_float8.c.

57 {
58  float8KEY *ia = (float8KEY *) (((const Nsrt *) a)->t);
59  float8KEY *ib = (float8KEY *) (((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, float8key::lower, and float8key::upper.

◆ gbt_float8le()

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

Definition at line 45 of file btree_float8.c.

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

References a, and b.

◆ gbt_float8lt()

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

Definition at line 50 of file btree_float8.c.

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

References a, and b.

◆ PG_FUNCTION_INFO_V1() [1/9]

PG_FUNCTION_INFO_V1 ( float8_dist  )

◆ PG_FUNCTION_INFO_V1() [2/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_compress  )

◆ PG_FUNCTION_INFO_V1() [3/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_consistent  )

◆ PG_FUNCTION_INFO_V1() [4/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_distance  )

◆ PG_FUNCTION_INFO_V1() [5/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_fetch  )

◆ PG_FUNCTION_INFO_V1() [6/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_penalty  )

◆ PG_FUNCTION_INFO_V1() [7/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_picksplit  )

◆ PG_FUNCTION_INFO_V1() [8/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_same  )

◆ PG_FUNCTION_INFO_V1() [9/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_union  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(float8),
16,
}
static bool gbt_float8eq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:40
static bool gbt_float8gt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:30
static float8 gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:73
static bool gbt_float8le(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:45
static bool gbt_float8ge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:35
static int gbt_float8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:56
static bool gbt_float8lt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:50
@ gbt_t_float8
Definition: btree_gist.h:21

Definition at line 86 of file btree_float8.c.

Referenced by gbt_float8_compress(), gbt_float8_consistent(), gbt_float8_distance(), gbt_float8_fetch(), gbt_float8_picksplit(), gbt_float8_same(), and gbt_float8_union().