PostgreSQL Source Code  git master
btree_numeric.c File Reference
#include "postgres.h"
#include <math.h>
#include <float.h>
#include "btree_gist.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 69 of file btree_numeric.c.

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

70 {
72  PointerGetDatum(a),
73  PointerGetDatum(b)));
74 }
#define DatumGetInt32(X)
Definition: postgres.h:472
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum numeric_cmp(PG_FUNCTION_ARGS)
Definition: numeric.c:2042
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_compress()

Datum gbt_numeric_compress ( PG_FUNCTION_ARGS  )

Definition at line 98 of file btree_numeric.c.

References gbt_var_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

99 {
100  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
101 
103 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:77

◆ gbt_numeric_consistent()

Datum gbt_numeric_consistent ( PG_FUNCTION_ARGS  )

Definition at line 108 of file btree_numeric.c.

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

109 {
110  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
111  void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
113 
114  /* Oid subtype = PG_GETARG_OID(3); */
115  bool *recheck = (bool *) PG_GETARG_POINTER(4);
116  bool retval;
119 
120  /* All cases served by this function are exact */
121  *recheck = false;
122 
123  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
124  GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
125  PG_RETURN_BOOL(retval);
126 }
#define GIST_LEAF(entry)
Definition: gist.h:161
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
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:276
#define PG_GET_COLLATION()
Definition: fmgr.h:198
Datum key
Definition: gist.h:151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
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:272
#define DatumGetPointer(X)
Definition: postgres.h:549
Definition: c.h:555
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:77

◆ gbt_numeric_eq()

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

Definition at line 45 of file btree_numeric.c.

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

46 {
48  PointerGetDatum(a),
49  PointerGetDatum(b)));
50 }
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum numeric_eq(PG_FUNCTION_ARGS)
Definition: numeric.c:2058
#define DatumGetBool(X)
Definition: postgres.h:393
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_ge()

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

Definition at line 37 of file btree_numeric.c.

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

38 {
40  PointerGetDatum(a),
41  PointerGetDatum(b)));
42 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define DatumGetBool(X)
Definition: postgres.h:393
Datum numeric_ge(PG_FUNCTION_ARGS)
Definition: numeric.c:2103
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_gt()

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

Definition at line 29 of file btree_numeric.c.

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

30 {
32  PointerGetDatum(a),
33  PointerGetDatum(b)));
34 }
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum numeric_gt(PG_FUNCTION_ARGS)
Definition: numeric.c:2088
#define DatumGetBool(X)
Definition: postgres.h:393
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_le()

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

Definition at line 53 of file btree_numeric.c.

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

54 {
56  PointerGetDatum(a),
57  PointerGetDatum(b)));
58 }
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum numeric_le(PG_FUNCTION_ARGS)
Definition: numeric.c:2133
#define DatumGetBool(X)
Definition: postgres.h:393
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_lt()

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

Definition at line 61 of file btree_numeric.c.

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

62 {
64  PointerGetDatum(a),
65  PointerGetDatum(b)));
66 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define DatumGetBool(X)
Definition: postgres.h:393
Datum numeric_lt(PG_FUNCTION_ARGS)
Definition: numeric.c:2118
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_penalty()

Datum gbt_numeric_penalty ( PG_FUNCTION_ARGS  )

Definition at line 154 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.

155 {
158  float *result = (float *) PG_GETARG_POINTER(2);
159 
160  Numeric us,
161  os,
162  ds;
163 
164  GBT_VARKEY *org = (GBT_VARKEY *) DatumGetPointer(o->key);
165  GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
166  Datum uni;
167  GBT_VARKEY_R rk,
168  ok,
169  uk;
170 
171  rk = gbt_var_key_readable(org);
172  uni = PointerGetDatum(gbt_var_key_copy(&rk));
173  gbt_var_bin_union(&uni, newe, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
174  ok = gbt_var_key_readable(org);
176 
179  PointerGetDatum(uk.lower)));
180 
183  PointerGetDatum(ok.lower)));
184 
186  NumericGetDatum(us),
187  NumericGetDatum(os)));
188 
189  if (numeric_is_nan(us))
190  {
191  if (numeric_is_nan(os))
192  *result = 0.0;
193  else
194  *result = 1.0;
195  }
196  else
197  {
199 
200  *result = 0.0;
201 
203  {
204  *result += FLT_MIN;
206  NumericGetDatum(ds),
207  NumericGetDatum(us)));
209  }
210  }
211 
212  if (*result > 0)
213  *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
214 
215  PG_RETURN_POINTER(result);
216 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PointerGetDatum(X)
Definition: postgres.h:556
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:2088
#define NumericGetDatum(X)
Definition: numeric.h:51
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
Datum numeric_div(PG_FUNCTION_ARGS)
Definition: numeric.c:2576
#define PG_GET_COLLATION()
Definition: fmgr.h:198
bool numeric_is_nan(Numeric num)
Definition: numeric.c:679
Datum key
Definition: gist.h:151
float float4
Definition: c.h:490
Datum int4_numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:3385
#define DatumGetFloat8(X)
Definition: postgres.h:714
uintptr_t Datum
Definition: postgres.h:367
Datum numeric_sub(PG_FUNCTION_ARGS)
Definition: numeric.c:2460
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:3632
#define DatumGetPointer(X)
Definition: postgres.h:549
#define Int32GetDatum(X)
Definition: postgres.h:479
Definition: c.h:555
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:77
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ gbt_numeric_picksplit()

Datum gbt_numeric_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 221 of file btree_numeric.c.

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

222 {
225 
226  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
227  &tinfo, fcinfo->flinfo);
229 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
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:276
#define PG_GET_COLLATION()
Definition: fmgr.h:198
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:77

◆ gbt_numeric_same()

Datum gbt_numeric_same ( PG_FUNCTION_ARGS  )

Definition at line 142 of file btree_numeric.c.

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

143 {
144  Datum d1 = PG_GETARG_DATUM(0);
145  Datum d2 = PG_GETARG_DATUM(1);
146  bool *result = (bool *) PG_GETARG_POINTER(2);
147 
148  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
149  PG_RETURN_POINTER(result);
150 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_GET_COLLATION()
Definition: fmgr.h:198
uintptr_t Datum
Definition: postgres.h:367
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:77

◆ gbt_numeric_union()

Datum gbt_numeric_union ( PG_FUNCTION_ARGS  )

Definition at line 131 of file btree_numeric.c.

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

132 {
134  int32 *size = (int *) PG_GETARG_POINTER(1);
135 
137  &tinfo, fcinfo->flinfo));
138 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_GET_COLLATION()
Definition: fmgr.h:198
signed int int32
Definition: c.h:355
static const gbtree_vinfo tinfo
Definition: btree_numeric.c:77
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:69
static bool gbt_numeric_gt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:29
static bool gbt_numeric_le(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:53
static bool gbt_numeric_eq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:45
static bool gbt_numeric_ge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:37
static bool gbt_numeric_lt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:61

Definition at line 77 of file btree_numeric.c.