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.

70 {
73  PointerGetDatum(b)));
74 }
Datum numeric_cmp(PG_FUNCTION_ARGS)
Definition: numeric.c:2399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
int b
Definition: isn.c:70
int a
Definition: isn.c:69
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202

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

◆ gbt_numeric_compress()

Datum gbt_numeric_compress ( PG_FUNCTION_ARGS  )

Definition at line 98 of file btree_numeric.c.

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

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

◆ gbt_numeric_consistent()

Datum gbt_numeric_consistent ( PG_FUNCTION_ARGS  )

Definition at line 108 of file btree_numeric.c.

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 }
bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_GET_COLLATION()
Definition: fmgr.h:198
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:170
static Numeric DatumGetNumeric(Datum X)
Definition: numeric.h:61
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:160
Definition: c.h:690

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

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

46 {
49  PointerGetDatum(b)));
50 }
Datum numeric_eq(PG_FUNCTION_ARGS)
Definition: numeric.c:2415
static bool DatumGetBool(Datum X)
Definition: postgres.h:90

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

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

38 {
41  PointerGetDatum(b)));
42 }
Datum numeric_ge(PG_FUNCTION_ARGS)
Definition: numeric.c:2460

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

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

30 {
33  PointerGetDatum(b)));
34 }
Datum numeric_gt(PG_FUNCTION_ARGS)
Definition: numeric.c:2445

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

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

54 {
57  PointerGetDatum(b)));
58 }
Datum numeric_le(PG_FUNCTION_ARGS)
Definition: numeric.c:2490

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

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

62 {
65  PointerGetDatum(b)));
66 }
Datum numeric_lt(PG_FUNCTION_ARGS)
Definition: numeric.c:2475

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

◆ gbt_numeric_penalty()

Datum gbt_numeric_penalty ( PG_FUNCTION_ARGS  )

Definition at line 154 of file btree_numeric.c.

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  {
198  Numeric nul = int64_to_numeric(0);
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 }
Datum numeric_div(PG_FUNCTION_ARGS)
Definition: numeric.c:3124
Datum numeric_sub(PG_FUNCTION_ARGS)
Definition: numeric.c:2925
Numeric int64_to_numeric(int64 val)
Definition: numeric.c:4283
bool numeric_is_nan(Numeric num)
Definition: numeric.c:853
Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS)
Definition: numeric.c:4661
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
float float4
Definition: c.h:632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
static Datum NumericGetDatum(Numeric X)
Definition: numeric.h:73
uintptr_t Datum
Definition: postgres.h:64
static float8 DatumGetFloat8(Datum X)
Definition: postgres.h:494

References DatumGetFloat8(), DatumGetNumeric(), DatumGetPointer(), DirectFunctionCall1, DirectFunctionCall2, gbt_var_bin_union(), gbt_var_key_copy(), gbt_var_key_readable(), int64_to_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(), tinfo, and GBT_VARKEY_R::upper.

◆ gbt_numeric_picksplit()

Datum gbt_numeric_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 221 of file btree_numeric.c.

222 {
225 
226  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
227  &tinfo, fcinfo->flinfo);
229 }
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_numeric_same()

Datum gbt_numeric_same ( PG_FUNCTION_ARGS  )

Definition at line 142 of file btree_numeric.c.

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 }
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_numeric_union()

Datum gbt_numeric_union ( PG_FUNCTION_ARGS  )

Definition at line 131 of file btree_numeric.c.

132 {
134  int32 *size = (int *) PG_GETARG_POINTER(1);
135 
137  &tinfo, fcinfo->flinfo));
138 }
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
signed int int32
Definition: c.h:497
static pg_noinline void Size size
Definition: slab.c:607

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

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

◆ PG_FUNCTION_INFO_V1() [3/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_penalty  )

◆ PG_FUNCTION_INFO_V1() [4/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_same  )

◆ PG_FUNCTION_INFO_V1() [6/6]

PG_FUNCTION_INFO_V1 ( gbt_numeric_union  )

Variable Documentation

◆ tinfo

const gbtree_vinfo tinfo
static
Initial value:
=
{
0,
false,
NULL
}
@ gbt_t_numeric
Definition: btree_gist.h:22
static bool gbt_numeric_gt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:29
static int32 gbt_numeric_cmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:69
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
static bool gbt_numeric_le(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_numeric.c:53

Definition at line 77 of file btree_numeric.c.

Referenced by gbt_numeric_compress(), gbt_numeric_consistent(), gbt_numeric_penalty(), gbt_numeric_picksplit(), gbt_numeric_same(), and gbt_numeric_union().