PostgreSQL Source Code  git master
btree_numeric.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include <math.h>
#include <float.h>
#include "btree_utils_var.h"
#include "utils/builtins.h"
#include "utils/numeric.h"
#include "utils/rel.h"
Include dependency graph for btree_numeric.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (gbt_numeric_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_numeric_union)
 
 PG_FUNCTION_INFO_V1 (gbt_numeric_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_numeric_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_numeric_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_numeric_same)
 
static bool gbt_numeric_gt (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_numeric_ge (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_numeric_eq (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_numeric_le (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_numeric_lt (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static int32 gbt_numeric_cmp (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
Datum gbt_numeric_compress (PG_FUNCTION_ARGS)
 
Datum gbt_numeric_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_numeric_union (PG_FUNCTION_ARGS)
 
Datum gbt_numeric_same (PG_FUNCTION_ARGS)
 
Datum gbt_numeric_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_numeric_picksplit (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_vinfo tinfo
 

Function Documentation

◆ gbt_numeric_cmp()

static int32 gbt_numeric_cmp ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 70 of file btree_numeric.c.

References DatumGetInt32, DirectFunctionCall2, numeric_cmp(), and PointerGetDatum.

71 {
73  PointerGetDatum(a),
74  PointerGetDatum(b)));
75 }
#define DatumGetInt32(X)
Definition: postgres.h:478
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum numeric_cmp(PG_FUNCTION_ARGS)
Definition: numeric.c:2031
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_compress()

Datum gbt_numeric_compress ( PG_FUNCTION_ARGS  )

Definition at line 99 of file btree_numeric.c.

References gbt_var_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

100 {
101  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
102 
104 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:78

◆ gbt_numeric_consistent()

Datum gbt_numeric_consistent ( PG_FUNCTION_ARGS  )

Definition at line 109 of file btree_numeric.c.

References DatumGetNumeric, DatumGetPointer, gbt_var_consistent(), gbt_var_key_readable(), GIST_LEAF, GISTENTRY::key, PG_GET_COLLATION, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_GETARG_UINT16, and PG_RETURN_BOOL.

110 {
111  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
112  void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
114 
115  /* Oid subtype = PG_GETARG_OID(3); */
116  bool *recheck = (bool *) PG_GETARG_POINTER(4);
117  bool retval;
118  GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
120 
121  /* All cases served by this function are exact */
122  *recheck = false;
123 
124  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
125  GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
126  PG_RETURN_BOOL(retval);
127 }
#define GIST_LEAF(entry)
Definition: gist.h:133
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
uint16 StrategyNumber
Definition: stratnum.h:22
bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_GET_COLLATION()
Definition: fmgr.h:163
Datum key
Definition: gist.h:123
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
#define DatumGetNumeric(X)
Definition: numeric.h:49
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
Definition: c.h:497
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:78

◆ gbt_numeric_eq()

static bool gbt_numeric_eq ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 46 of file btree_numeric.c.

References DatumGetBool, DirectFunctionCall2, numeric_eq(), and PointerGetDatum.

47 {
49  PointerGetDatum(a),
50  PointerGetDatum(b)));
51 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum numeric_eq(PG_FUNCTION_ARGS)
Definition: numeric.c:2047
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_ge()

static bool gbt_numeric_ge ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 38 of file btree_numeric.c.

References DatumGetBool, DirectFunctionCall2, numeric_ge(), and PointerGetDatum.

39 {
41  PointerGetDatum(a),
42  PointerGetDatum(b)));
43 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetBool(X)
Definition: postgres.h:399
Datum numeric_ge(PG_FUNCTION_ARGS)
Definition: numeric.c:2092
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_gt()

static bool gbt_numeric_gt ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 30 of file btree_numeric.c.

References DatumGetBool, DirectFunctionCall2, numeric_gt(), and PointerGetDatum.

31 {
33  PointerGetDatum(a),
34  PointerGetDatum(b)));
35 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum numeric_gt(PG_FUNCTION_ARGS)
Definition: numeric.c:2077
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_le()

static bool gbt_numeric_le ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 54 of file btree_numeric.c.

References DatumGetBool, DirectFunctionCall2, numeric_le(), and PointerGetDatum.

55 {
57  PointerGetDatum(a),
58  PointerGetDatum(b)));
59 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum numeric_le(PG_FUNCTION_ARGS)
Definition: numeric.c:2122
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_lt()

static bool gbt_numeric_lt ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 62 of file btree_numeric.c.

References DatumGetBool, DirectFunctionCall2, numeric_lt(), and PointerGetDatum.

63 {
65  PointerGetDatum(a),
66  PointerGetDatum(b)));
67 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetBool(X)
Definition: postgres.h:399
Datum numeric_lt(PG_FUNCTION_ARGS)
Definition: numeric.c:2107
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_penalty()

Datum gbt_numeric_penalty ( PG_FUNCTION_ARGS  )

Definition at line 155 of file btree_numeric.c.

References DatumGetFloat8, DatumGetNumeric, DatumGetPointer, DirectFunctionCall1, DirectFunctionCall2, gbt_var_bin_union(), gbt_var_key_copy(), gbt_var_key_readable(), Int32GetDatum, int4_numeric(), GISTENTRY::key, GBT_VARKEY_R::lower, numeric_div(), numeric_float8_no_overflow(), numeric_gt(), numeric_is_nan(), numeric_sub(), NumericGetDatum, PG_GET_COLLATION, PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, and GBT_VARKEY_R::upper.

156 {
159  float *result = (float *) PG_GETARG_POINTER(2);
160 
161  Numeric us,
162  os,
163  ds;
164 
165  GBT_VARKEY *org = (GBT_VARKEY *) DatumGetPointer(o->key);
166  GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
167  Datum uni;
168  GBT_VARKEY_R rk,
169  ok,
170  uk;
171 
172  rk = gbt_var_key_readable(org);
173  uni = PointerGetDatum(gbt_var_key_copy(&rk));
174  gbt_var_bin_union(&uni, newe, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
175  ok = gbt_var_key_readable(org);
177 
179  numeric_sub,
182  ));
183 
185  numeric_sub,
188  ));
189 
191  numeric_sub,
192  NumericGetDatum(us),
193  NumericGetDatum(os)
194  ));
195 
196  if (numeric_is_nan(us))
197  {
198  if (numeric_is_nan(os))
199  *result = 0.0;
200  else
201  *result = 1.0;
202  }
203  else
204  {
206 
207  *result = 0.0;
208 
210  {
211  *result += FLT_MIN;
213  numeric_div,
214  NumericGetDatum(ds),
215  NumericGetDatum(us)
216  ));
218  }
219  }
220 
221  if (*result > 0)
222  *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
223 
224  PG_RETURN_POINTER(result);
225 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PointerGetDatum(X)
Definition: postgres.h:562
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
Datum numeric_gt(PG_FUNCTION_ARGS)
Definition: numeric.c:2077
#define NumericGetDatum(X)
Definition: numeric.h:51
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
Datum numeric_div(PG_FUNCTION_ARGS)
Definition: numeric.c:2437
#define PG_GET_COLLATION()
Definition: fmgr.h:163
bool numeric_is_nan(Numeric num)
Definition: numeric.c:680
Datum key
Definition: gist.h:123
float float4
Definition: c.h:438
Datum int4_numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:2973
#define DatumGetFloat8(X)
Definition: postgres.h:734
uintptr_t Datum
Definition: postgres.h:372
Datum numeric_sub(PG_FUNCTION_ARGS)
Definition: numeric.c:2357
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
#define DatumGetNumeric(X)
Definition: numeric.h:49
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS)
Definition: numeric.c:3194
#define DatumGetPointer(X)
Definition: postgres.h:555
#define Int32GetDatum(X)
Definition: postgres.h:485
Definition: c.h:497
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:78
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_numeric_picksplit()

Datum gbt_numeric_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 230 of file btree_numeric.c.

References gbt_var_picksplit(), PG_GET_COLLATION, PG_GETARG_POINTER, and PG_RETURN_POINTER.

231 {
234 
235  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
236  &tinfo, fcinfo->flinfo);
238 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_GET_COLLATION()
Definition: fmgr.h:163
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:78

◆ gbt_numeric_same()

Datum gbt_numeric_same ( PG_FUNCTION_ARGS  )

Definition at line 143 of file btree_numeric.c.

References gbt_var_same(), PG_GET_COLLATION, PG_GETARG_DATUM, PG_GETARG_POINTER, and PG_RETURN_POINTER.

144 {
145  Datum d1 = PG_GETARG_DATUM(0);
146  Datum d2 = PG_GETARG_DATUM(1);
147  bool *result = (bool *) PG_GETARG_POINTER(2);
148 
149  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
150  PG_RETURN_POINTER(result);
151 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_GET_COLLATION()
Definition: fmgr.h:163
uintptr_t Datum
Definition: postgres.h:372
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:78

◆ gbt_numeric_union()

Datum gbt_numeric_union ( PG_FUNCTION_ARGS  )

Definition at line 132 of file btree_numeric.c.

References gbt_var_union(), PG_GET_COLLATION, PG_GETARG_POINTER, and PG_RETURN_POINTER.

133 {
135  int32 *size = (int *) PG_GETARG_POINTER(1);
136 
138  &tinfo, fcinfo->flinfo));
139 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_GET_COLLATION()
Definition: fmgr.h:163
signed int int32
Definition: c.h:294
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:78
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

◆ PG_FUNCTION_INFO_V1() [1/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_compress  )

◆ PG_FUNCTION_INFO_V1() [2/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_union  )

◆ PG_FUNCTION_INFO_V1() [3/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_picksplit  )

◆ PG_FUNCTION_INFO_V1() [4/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_consistent  )

◆ PG_FUNCTION_INFO_V1() [5/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_penalty  )

◆ PG_FUNCTION_INFO_V1() [6/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_same  )

Variable Documentation

◆ tinfo

const gbtree_vinfo tinfo
static
Initial value:
=
{
0,
false,
NULL
}
static int32 gbt_numeric_cmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:70
static bool gbt_numeric_gt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:30
static bool gbt_numeric_le(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:54
static bool gbt_numeric_eq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:46
static bool gbt_numeric_ge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:38
static bool gbt_numeric_lt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:62

Definition at line 78 of file btree_numeric.c.