PostgreSQL Source Code  git master
btree_utils_num.h File Reference
#include "btree_gist.h"
#include "access/gist.h"
#include "utils/rel.h"
#include <math.h>
#include <float.h>
Include dependency graph for btree_utils_num.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GBT_NUMKEY_R
 
struct  Nsrt
 
struct  gbtree_ninfo
 

Macros

#define penalty_num(result, olower, oupper, nlower, nupper)
 
#define INTERVAL_TO_SEC(ivp)
 
#define GET_FLOAT_DISTANCE(t, arg1, arg2)   Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
 
#define SAMESIGN(a, b)   (((a) < 0) == ((b) < 0))
 
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
 

Typedefs

typedef char GBT_NUMKEY
 

Functions

Intervalabs_interval (Interval *a)
 
bool gbt_num_consistent (const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
 
float8 gbt_num_distance (const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
 
GIST_SPLITVECgbt_num_picksplit (const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
 
GISTENTRYgbt_num_compress (GISTENTRY *entry, const gbtree_ninfo *tinfo)
 
GISTENTRYgbt_num_fetch (GISTENTRY *entry, const gbtree_ninfo *tinfo)
 
void * gbt_num_union (GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
 
bool gbt_num_same (const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
 
void gbt_num_bin_union (Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
 

Macro Definition Documentation

◆ CHECKFLOATVAL

#define CHECKFLOATVAL (   val,
  inf_is_valid,
  zero_is_valid 
)
Value:
do { \
if (isinf(val) && !(inf_is_valid)) \
ereport(ERROR, \
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), \
errmsg("value out of range: overflow"))); \
\
if ((val) == 0.0 && !(zero_is_valid)) \
ereport(ERROR, \
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), \
errmsg("value out of range: underflow"))); \
} while(0)
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
int isinf(double x)
int errmsg(const char *fmt,...)
Definition: elog.c:797
long val
Definition: informix.c:689

Definition at line 98 of file btree_utils_num.h.

Referenced by float4_dist(), float8_dist(), and gbt_float8_dist().

◆ GET_FLOAT_DISTANCE

#define GET_FLOAT_DISTANCE (   t,
  arg1,
  arg2 
)    Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )

◆ INTERVAL_TO_SEC

#define INTERVAL_TO_SEC (   ivp)
Value:
(((double) (ivp)->time) / ((double) USECS_PER_SEC) + \
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
(ivp)->month * (30.0 * SECS_PER_DAY))
#define USECS_PER_SEC
Definition: timestamp.h:94
#define SECS_PER_DAY
Definition: timestamp.h:86
#define SECS_PER_HOUR
Definition: timestamp.h:87

Definition at line 85 of file btree_utils_num.h.

Referenced by gbt_time_dist(), gbt_time_penalty(), gbt_ts_dist(), and intr2num().

◆ penalty_num

#define penalty_num (   result,
  olower,
  oupper,
  nlower,
  nupper 
)
Value:
do { \
double tmp = 0.0F; \
(*(result)) = 0.0F; \
if ( (nupper) > (oupper) ) \
tmp += ( ((double)nupper)*0.49F - ((double)oupper)*0.49F ); \
if ( (olower) > (nlower) ) \
tmp += ( ((double)olower)*0.49F - ((double)nlower)*0.49F ); \
if (tmp > 0.0F) \
{ \
(*(result)) += FLT_MIN; \
(*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
(*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
} \
} while (0);
#define F(x)
Definition: blf.c:249
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241

Definition at line 64 of file btree_utils_num.h.

Referenced by gbt_cash_penalty(), gbt_enum_penalty(), gbt_float4_penalty(), gbt_float8_penalty(), gbt_inet_penalty(), gbt_int2_penalty(), gbt_int4_penalty(), gbt_int8_penalty(), gbt_intv_penalty(), gbt_macad8_penalty(), gbt_macad_penalty(), gbt_oid_penalty(), gbt_ts_penalty(), and gbt_uuid_penalty().

◆ SAMESIGN

#define SAMESIGN (   a,
 
)    (((a) < 0) == ((b) < 0))

Definition at line 92 of file btree_utils_num.h.

Referenced by cash_dist(), int2_dist(), int4_dist(), and int8_dist().

Typedef Documentation

◆ GBT_NUMKEY

Definition at line 14 of file btree_utils_num.h.

Function Documentation

◆ abs_interval()

Interval* abs_interval ( Interval a)

Definition at line 114 of file btree_interval.c.

References DatumGetBool, DatumGetIntervalP, DirectFunctionCall1, DirectFunctionCall2, interval_dist(), interval_lt(), interval_um(), IntervalPGetDatum, and PG_FUNCTION_INFO_V1().

Referenced by interval_dist(), time_dist(), ts_dist(), and tstz_dist().

115 {
116  static Interval zero = {0, 0, 0};
117 
120  IntervalPGetDatum(&zero))))
122  IntervalPGetDatum(a)));
123 
124  return a;
125 }
#define DatumGetIntervalP(X)
Definition: timestamp.h:29
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
#define IntervalPGetDatum(X)
Definition: timestamp.h:33
Datum interval_lt(PG_FUNCTION_ARGS)
Definition: timestamp.c:2358
#define DatumGetBool(X)
Definition: postgres.h:399
Datum interval_um(PG_FUNCTION_ARGS)
Definition: timestamp.c:3001
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_num_bin_union()

void gbt_num_bin_union ( Datum u,
GBT_NUMKEY e,
const gbtree_ninfo tinfo,
FmgrInfo flinfo 
)

Definition at line 220 of file btree_utils_num.c.

References DatumGetPointer, gbtree_ninfo::f_gt, gbtree_ninfo::f_lt, gbtree_ninfo::indexsize, GBT_NUMKEY_R::lower, palloc0(), PointerGetDatum, gbtree_ninfo::size, and GBT_NUMKEY_R::upper.

Referenced by gbt_num_picksplit().

221 {
222  GBT_NUMKEY_R rd;
223 
224  rd.lower = &e[0];
225  rd.upper = &e[tinfo->size];
226 
227  if (!DatumGetPointer(*u))
228  {
229  *u = PointerGetDatum(palloc0(tinfo->indexsize));
230  memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]), (void *) rd.lower, tinfo->size);
231  memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]), (void *) rd.upper, tinfo->size);
232  }
233  else
234  {
235  GBT_NUMKEY_R ur;
236 
237  ur.lower = &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]);
238  ur.upper = &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]);
239  if (tinfo->f_gt((void *) ur.lower, (void *) rd.lower, flinfo))
240  memcpy((void *) ur.lower, (void *) rd.lower, tinfo->size);
241  if (tinfo->f_lt((void *) ur.upper, (void *) rd.upper, flinfo))
242  memcpy((void *) ur.upper, (void *) rd.upper, tinfo->size);
243  }
244 }
const GBT_NUMKEY * lower
#define PointerGetDatum(X)
Definition: postgres.h:562
bool(* f_gt)(const void *, const void *, FmgrInfo *)
const GBT_NUMKEY * upper
char GBT_NUMKEY
void * palloc0(Size size)
Definition: mcxt.c:877
bool(* f_lt)(const void *, const void *, FmgrInfo *)
#define DatumGetPointer(X)
Definition: postgres.h:555
e
Definition: preproc-init.c:82

◆ gbt_num_compress()

GISTENTRY* gbt_num_compress ( GISTENTRY entry,
const gbtree_ninfo tinfo 
)

Definition at line 14 of file btree_utils_num.c.

References Assert, DatumGetCash, DatumGetDateADT, DatumGetFloat4, DatumGetFloat8, DatumGetInt16, DatumGetInt32, DatumGetInt64, DatumGetObjectId, DatumGetPointer, DatumGetTimeADT, DatumGetTimestamp, gbt_t_cash, gbt_t_date, gbt_t_enum, gbt_t_float4, gbt_t_float8, gbt_t_int2, gbt_t_int4, gbt_t_int8, gbt_t_oid, gbt_t_time, gbt_t_ts, gistentryinit, gbtree_ninfo::indexsize, GISTENTRY::key, GISTENTRY::leafkey, GISTENTRY::offset, GISTENTRY::page, palloc(), palloc0(), PointerGetDatum, GISTENTRY::rel, gbtree_ninfo::size, gbtree_ninfo::t, and tm.

Referenced by gbt_cash_compress(), gbt_date_compress(), gbt_enum_compress(), gbt_float4_compress(), gbt_float8_compress(), gbt_int2_compress(), gbt_int4_compress(), gbt_int8_compress(), gbt_macad8_compress(), gbt_macad_compress(), gbt_oid_compress(), gbt_time_compress(), and gbt_ts_compress().

15 {
16  GISTENTRY *retval;
17 
18  if (entry->leafkey)
19  {
20  union
21  {
22  int16 i2;
23  int32 i4;
24  int64 i8;
25  float4 f4;
26  float8 f8;
27  DateADT dt;
28  TimeADT tm;
29  Timestamp ts;
30  Cash ch;
31  } v;
32 
33  GBT_NUMKEY *r = (GBT_NUMKEY *) palloc0(tinfo->indexsize);
34  void *leaf = NULL;
35 
36  switch (tinfo->t)
37  {
38  case gbt_t_int2:
39  v.i2 = DatumGetInt16(entry->key);
40  leaf = &v.i2;
41  break;
42  case gbt_t_int4:
43  v.i4 = DatumGetInt32(entry->key);
44  leaf = &v.i4;
45  break;
46  case gbt_t_int8:
47  v.i8 = DatumGetInt64(entry->key);
48  leaf = &v.i8;
49  break;
50  case gbt_t_oid:
51  case gbt_t_enum:
52  v.i4 = DatumGetObjectId(entry->key);
53  leaf = &v.i4;
54  break;
55  case gbt_t_float4:
56  v.f4 = DatumGetFloat4(entry->key);
57  leaf = &v.f4;
58  break;
59  case gbt_t_float8:
60  v.f8 = DatumGetFloat8(entry->key);
61  leaf = &v.f8;
62  break;
63  case gbt_t_date:
64  v.dt = DatumGetDateADT(entry->key);
65  leaf = &v.dt;
66  break;
67  case gbt_t_time:
68  v.tm = DatumGetTimeADT(entry->key);
69  leaf = &v.tm;
70  break;
71  case gbt_t_ts:
72  v.ts = DatumGetTimestamp(entry->key);
73  leaf = &v.ts;
74  break;
75  case gbt_t_cash:
76  v.ch = DatumGetCash(entry->key);
77  leaf = &v.ch;
78  break;
79  default:
80  leaf = DatumGetPointer(entry->key);
81  }
82 
83  Assert(tinfo->indexsize >= 2 * tinfo->size);
84 
85  memcpy((void *) &r[0], leaf, tinfo->size);
86  memcpy((void *) &r[tinfo->size], leaf, tinfo->size);
87  retval = palloc(sizeof(GISTENTRY));
88  gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
89  entry->offset, false);
90  }
91  else
92  retval = entry;
93 
94  return retval;
95 }
Relation rel
Definition: gist.h:124
signed short int16
Definition: c.h:283
#define DatumGetDateADT(X)
Definition: date.h:52
#define DatumGetInt32(X)
Definition: postgres.h:478
int32 DateADT
Definition: date.h:22
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetObjectId(X)
Definition: postgres.h:506
enum gbtree_type t
signed int int32
Definition: c.h:284
static struct pg_tm tm
Definition: localtime.c:107
Page page
Definition: gist.h:125
double float8
Definition: c.h:429
#define DatumGetInt64(X)
Definition: postgres.h:613
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define DatumGetInt16(X)
Definition: postgres.h:450
int64 TimeADT
Definition: date.h:24
bool leafkey
Definition: gist.h:127
int64 Timestamp
Definition: timestamp.h:38
#define DatumGetTimeADT(X)
Definition: date.h:53
float float4
Definition: c.h:428
#define DatumGetCash(X)
Definition: cash.h:20
void * palloc0(Size size)
Definition: mcxt.c:877
#define DatumGetFloat8(X)
Definition: postgres.h:734
#define Assert(condition)
Definition: c.h:670
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
#define DatumGetFloat4(X)
Definition: postgres.h:686
#define DatumGetPointer(X)
Definition: postgres.h:555
int64 Cash
Definition: cash.h:17
void * palloc(Size size)
Definition: mcxt.c:848
OffsetNumber offset
Definition: gist.h:126
#define DatumGetTimestamp(X)
Definition: timestamp.h:27

◆ gbt_num_consistent()

bool gbt_num_consistent ( const GBT_NUMKEY_R key,
const void *  query,
const StrategyNumber strategy,
bool  is_leaf,
const gbtree_ninfo tinfo,
FmgrInfo flinfo 
)

Definition at line 255 of file btree_utils_num.c.

References BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, BtreeGistNotEqualStrategyNumber, gbtree_ninfo::f_eq, gbtree_ninfo::f_ge, gbtree_ninfo::f_gt, gbtree_ninfo::f_le, gbtree_ninfo::f_lt, GBT_NUMKEY_R::lower, and GBT_NUMKEY_R::upper.

Referenced by gbt_cash_consistent(), gbt_date_consistent(), gbt_enum_consistent(), gbt_float4_consistent(), gbt_float8_consistent(), gbt_inet_consistent(), gbt_int2_consistent(), gbt_int4_consistent(), gbt_int8_consistent(), gbt_intv_consistent(), gbt_macad8_consistent(), gbt_macad_consistent(), gbt_oid_consistent(), gbt_time_consistent(), gbt_timetz_consistent(), gbt_ts_consistent(), gbt_tstz_consistent(), and gbt_uuid_consistent().

261 {
262  bool retval;
263 
264  switch (*strategy)
265  {
267  retval = tinfo->f_ge(query, key->lower, flinfo);
268  break;
270  if (is_leaf)
271  retval = tinfo->f_gt(query, key->lower, flinfo);
272  else
273  retval = tinfo->f_ge(query, key->lower, flinfo);
274  break;
276  if (is_leaf)
277  retval = tinfo->f_eq(query, key->lower, flinfo);
278  else
279  retval = (tinfo->f_le(key->lower, query, flinfo) &&
280  tinfo->f_le(query, key->upper, flinfo));
281  break;
283  if (is_leaf)
284  retval = tinfo->f_lt(query, key->upper, flinfo);
285  else
286  retval = tinfo->f_le(query, key->upper, flinfo);
287  break;
289  retval = tinfo->f_le(query, key->upper, flinfo);
290  break;
292  retval = (!(tinfo->f_eq(query, key->lower, flinfo) &&
293  tinfo->f_eq(query, key->upper, flinfo)));
294  break;
295  default:
296  retval = false;
297  }
298 
299  return retval;
300 }
bool(* f_le)(const void *, const void *, FmgrInfo *)
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
const GBT_NUMKEY * lower
bool(* f_gt)(const void *, const void *, FmgrInfo *)
const GBT_NUMKEY * upper
bool(* f_ge)(const void *, const void *, FmgrInfo *)
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
bool(* f_lt)(const void *, const void *, FmgrInfo *)
#define BtreeGistNotEqualStrategyNumber
Definition: btree_gist.h:10
bool(* f_eq)(const void *, const void *, FmgrInfo *)
#define BTLessStrategyNumber
Definition: stratnum.h:29
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32

◆ gbt_num_distance()

float8 gbt_num_distance ( const GBT_NUMKEY_R key,
const void *  query,
bool  is_leaf,
const gbtree_ninfo tinfo,
FmgrInfo flinfo 
)

Definition at line 308 of file btree_utils_num.c.

References elog, ERROR, gbtree_ninfo::f_dist, gbtree_ninfo::f_ge, gbtree_ninfo::f_le, GBT_NUMKEY_R::lower, gbtree_ninfo::t, and GBT_NUMKEY_R::upper.

Referenced by gbt_cash_distance(), gbt_date_distance(), gbt_float4_distance(), gbt_float8_distance(), gbt_int2_distance(), gbt_int4_distance(), gbt_int8_distance(), gbt_intv_distance(), gbt_oid_distance(), gbt_time_distance(), gbt_ts_distance(), and gbt_tstz_distance().

313 {
314  float8 retval;
315 
316  if (tinfo->f_dist == NULL)
317  elog(ERROR, "KNN search is not supported for btree_gist type %d",
318  (int) tinfo->t);
319  if (tinfo->f_le(query, key->lower, flinfo))
320  retval = tinfo->f_dist(query, key->lower, flinfo);
321  else if (tinfo->f_ge(query, key->upper, flinfo))
322  retval = tinfo->f_dist(query, key->upper, flinfo);
323  else
324  retval = 0.0;
325 
326  return retval;
327 }
bool(* f_le)(const void *, const void *, FmgrInfo *)
const GBT_NUMKEY * lower
const GBT_NUMKEY * upper
enum gbtree_type t
bool(* f_ge)(const void *, const void *, FmgrInfo *)
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:429
float8(* f_dist)(const void *, const void *, FmgrInfo *)
#define elog
Definition: elog.h:219

◆ gbt_num_fetch()

GISTENTRY* gbt_num_fetch ( GISTENTRY entry,
const gbtree_ninfo tinfo 
)

Definition at line 102 of file btree_utils_num.c.

References Assert, CashGetDatum, DateADTGetDatum, Float4GetDatum(), Float8GetDatum(), gbt_t_cash, gbt_t_date, gbt_t_enum, gbt_t_float4, gbt_t_float8, gbt_t_int2, gbt_t_int4, gbt_t_int8, gbt_t_oid, gbt_t_time, gbt_t_ts, gistentryinit, gbtree_ninfo::indexsize, Int16GetDatum, Int32GetDatum, Int64GetDatum(), GISTENTRY::key, ObjectIdGetDatum, GISTENTRY::offset, GISTENTRY::page, palloc(), PointerGetDatum, GISTENTRY::rel, gbtree_ninfo::size, gbtree_ninfo::t, TimeADTGetDatum, and TimestampGetDatum.

Referenced by gbt_cash_fetch(), gbt_date_fetch(), gbt_enum_fetch(), gbt_float4_fetch(), gbt_float8_fetch(), gbt_int2_fetch(), gbt_int4_fetch(), gbt_int8_fetch(), gbt_intv_fetch(), gbt_macad8_fetch(), gbt_macad_fetch(), gbt_oid_fetch(), gbt_time_fetch(), gbt_ts_fetch(), and gbt_uuid_fetch().

103 {
104  GISTENTRY *retval;
105  Datum datum;
106 
107  Assert(tinfo->indexsize >= 2 * tinfo->size);
108 
109  /*
110  * Get the original Datum from the stored datum. On leaf entries, the
111  * lower and upper bound are the same. We just grab the lower bound and
112  * return it.
113  */
114  switch (tinfo->t)
115  {
116  case gbt_t_int2:
117  datum = Int16GetDatum(*(int16 *) entry->key);
118  break;
119  case gbt_t_int4:
120  datum = Int32GetDatum(*(int32 *) entry->key);
121  break;
122  case gbt_t_int8:
123  datum = Int64GetDatum(*(int64 *) entry->key);
124  break;
125  case gbt_t_oid:
126  case gbt_t_enum:
127  datum = ObjectIdGetDatum(*(Oid *) entry->key);
128  break;
129  case gbt_t_float4:
130  datum = Float4GetDatum(*(float4 *) entry->key);
131  break;
132  case gbt_t_float8:
133  datum = Float8GetDatum(*(float8 *) entry->key);
134  break;
135  case gbt_t_date:
136  datum = DateADTGetDatum(*(DateADT *) entry->key);
137  break;
138  case gbt_t_time:
139  datum = TimeADTGetDatum(*(TimeADT *) entry->key);
140  break;
141  case gbt_t_ts:
142  datum = TimestampGetDatum(*(Timestamp *) entry->key);
143  break;
144  case gbt_t_cash:
145  datum = CashGetDatum(*(Cash *) entry->key);
146  break;
147  default:
148  datum = PointerGetDatum(entry->key);
149  }
150 
151  retval = palloc(sizeof(GISTENTRY));
152  gistentryinit(*retval, datum, entry->rel, entry->page, entry->offset,
153  false);
154  return retval;
155 }
Relation rel
Definition: gist.h:124
signed short int16
Definition: c.h:283
int32 DateADT
Definition: date.h:22
#define PointerGetDatum(X)
Definition: postgres.h:562
#define Int16GetDatum(X)
Definition: postgres.h:457
#define DateADTGetDatum(X)
Definition: date.h:56
unsigned int Oid
Definition: postgres_ext.h:31
enum gbtree_type t
signed int int32
Definition: c.h:284
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1810
Page page
Definition: gist.h:125
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
double float8
Definition: c.h:429
Datum Float4GetDatum(float4 X)
Definition: fmgr.c:1798
Datum key
Definition: gist.h:123
int64 TimeADT
Definition: date.h:24
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1786
#define TimestampGetDatum(X)
Definition: timestamp.h:31
int64 Timestamp
Definition: timestamp.h:38
float float4
Definition: c.h:428
uintptr_t Datum
Definition: postgres.h:372
#define TimeADTGetDatum(X)
Definition: date.h:57
#define Assert(condition)
Definition: c.h:670
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
int64 Cash
Definition: cash.h:17
#define Int32GetDatum(X)
Definition: postgres.h:485
void * palloc(Size size)
Definition: mcxt.c:848
#define CashGetDatum(X)
Definition: cash.h:21
OffsetNumber offset
Definition: gist.h:126

◆ gbt_num_picksplit()

GIST_SPLITVEC* gbt_num_picksplit ( const GistEntryVector entryvec,
GIST_SPLITVEC v,
const gbtree_ninfo tinfo,
FmgrInfo flinfo 
)

Definition at line 331 of file btree_utils_num.c.

References DatumGetPointer, gbtree_ninfo::f_cmp, FirstOffsetNumber, gbt_num_bin_union(), i, Nsrt::i, GISTENTRY::key, GistEntryVector::n, OffsetNumberNext, palloc(), PointerGetDatum, qsort_arg(), GIST_SPLITVEC::spl_ldatum, GIST_SPLITVEC::spl_left, GIST_SPLITVEC::spl_nleft, GIST_SPLITVEC::spl_nright, GIST_SPLITVEC::spl_rdatum, GIST_SPLITVEC::spl_right, Nsrt::t, and GistEntryVector::vector.

Referenced by gbt_cash_picksplit(), gbt_date_picksplit(), gbt_enum_picksplit(), gbt_float4_picksplit(), gbt_float8_picksplit(), gbt_inet_picksplit(), gbt_int2_picksplit(), gbt_int4_picksplit(), gbt_int8_picksplit(), gbt_intv_picksplit(), gbt_macad8_picksplit(), gbt_macad_picksplit(), gbt_oid_picksplit(), gbt_time_picksplit(), gbt_ts_picksplit(), and gbt_uuid_picksplit().

333 {
334  OffsetNumber i,
335  maxoff = entryvec->n - 1;
336  Nsrt *arr;
337  int nbytes;
338 
339  arr = (Nsrt *) palloc((maxoff + 1) * sizeof(Nsrt));
340  nbytes = (maxoff + 2) * sizeof(OffsetNumber);
341  v->spl_left = (OffsetNumber *) palloc(nbytes);
342  v->spl_right = (OffsetNumber *) palloc(nbytes);
343  v->spl_ldatum = PointerGetDatum(0);
344  v->spl_rdatum = PointerGetDatum(0);
345  v->spl_nleft = 0;
346  v->spl_nright = 0;
347 
348  /* Sort entries */
349 
350  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
351  {
352  arr[i].t = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
353  arr[i].i = i;
354  }
355  qsort_arg((void *) &arr[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1, sizeof(Nsrt), (qsort_arg_comparator) tinfo->f_cmp, (void *) flinfo);
356 
357  /* We do simply create two parts */
358 
359  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
360  {
361  if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
362  {
363  gbt_num_bin_union(&v->spl_ldatum, arr[i].t, tinfo, flinfo);
364  v->spl_left[v->spl_nleft] = arr[i].i;
365  v->spl_nleft++;
366  }
367  else
368  {
369  gbt_num_bin_union(&v->spl_rdatum, arr[i].t, tinfo, flinfo);
370  v->spl_right[v->spl_nright] = arr[i].i;
371  v->spl_nright++;
372  }
373  }
374 
375  return v;
376 }
GBT_NUMKEY * t
#define PointerGetDatum(X)
Definition: postgres.h:562
int(* qsort_arg_comparator)(const void *a, const void *b, void *arg)
Definition: port.h:410
OffsetNumber * spl_left
Definition: gist.h:105
Datum spl_rdatum
Definition: gist.h:112
int32 n
Definition: gist.h:160
int spl_nleft
Definition: gist.h:106
uint16 OffsetNumber
Definition: off.h:24
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
Definition: gist.h:161
int(* f_cmp)(const void *, const void *, FmgrInfo *)
int spl_nright
Definition: gist.h:111
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define FirstOffsetNumber
Definition: off.h:27
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
Definition: qsort_arg.c:113
void gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum spl_ldatum
Definition: gist.h:107
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
OffsetNumber * spl_right
Definition: gist.h:110
#define DatumGetPointer(X)
Definition: postgres.h:555
void * palloc(Size size)
Definition: mcxt.c:848
int i

◆ gbt_num_same()

bool gbt_num_same ( const GBT_NUMKEY a,
const GBT_NUMKEY b,
const gbtree_ninfo tinfo,
FmgrInfo flinfo 
)

Definition at line 204 of file btree_utils_num.c.

References gbtree_ninfo::f_eq, GBT_NUMKEY_R::lower, gbtree_ninfo::size, and GBT_NUMKEY_R::upper.

Referenced by gbt_cash_same(), gbt_date_same(), gbt_enum_same(), gbt_float4_same(), gbt_float8_same(), gbt_inet_same(), gbt_int2_same(), gbt_int4_same(), gbt_int8_same(), gbt_intv_same(), gbt_macad8_same(), gbt_macad_same(), gbt_oid_same(), gbt_time_same(), gbt_ts_same(), and gbt_uuid_same().

205 {
206  GBT_NUMKEY_R b1,
207  b2;
208 
209  b1.lower = &(((GBT_NUMKEY *) a)[0]);
210  b1.upper = &(((GBT_NUMKEY *) a)[tinfo->size]);
211  b2.lower = &(((GBT_NUMKEY *) b)[0]);
212  b2.upper = &(((GBT_NUMKEY *) b)[tinfo->size]);
213 
214  return (tinfo->f_eq(b1.lower, b2.lower, flinfo) &&
215  tinfo->f_eq(b1.upper, b2.upper, flinfo));
216 }
const GBT_NUMKEY * lower
const GBT_NUMKEY * upper
char GBT_NUMKEY
bool(* f_eq)(const void *, const void *, FmgrInfo *)

◆ gbt_num_union()

void* gbt_num_union ( GBT_NUMKEY out,
const GistEntryVector entryvec,
const gbtree_ninfo tinfo,
FmgrInfo flinfo 
)

Definition at line 164 of file btree_utils_num.c.

References cur, DatumGetPointer, gbtree_ninfo::f_gt, gbtree_ninfo::f_lt, i, GISTENTRY::key, GBT_NUMKEY_R::lower, GistEntryVector::n, gbtree_ninfo::size, GBT_NUMKEY_R::upper, and GistEntryVector::vector.

Referenced by gbt_cash_union(), gbt_date_union(), gbt_enum_union(), gbt_float4_union(), gbt_float8_union(), gbt_inet_union(), gbt_int2_union(), gbt_int4_union(), gbt_int8_union(), gbt_intv_union(), gbt_macad8_union(), gbt_macad_union(), gbt_oid_union(), gbt_time_union(), gbt_ts_union(), and gbt_uuid_union().

165 {
166  int i,
167  numranges;
168  GBT_NUMKEY *cur;
169  GBT_NUMKEY_R o,
170  c;
171 
172  numranges = entryvec->n;
173  cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key));
174 
175 
176  o.lower = &((GBT_NUMKEY *) out)[0];
177  o.upper = &((GBT_NUMKEY *) out)[tinfo->size];
178 
179  memcpy((void *) out, (void *) cur, 2 * tinfo->size);
180 
181  for (i = 1; i < numranges; i++)
182  {
183  cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
184  c.lower = &cur[0];
185  c.upper = &cur[tinfo->size];
186  /* if out->lower > cur->lower, adopt cur as lower */
187  if (tinfo->f_gt(o.lower, c.lower, flinfo))
188  memcpy((void *) o.lower, (void *) c.lower, tinfo->size);
189  /* if out->upper < cur->upper, adopt cur as upper */
190  if (tinfo->f_lt(o.upper, c.upper, flinfo))
191  memcpy((void *) o.upper, (void *) c.upper, tinfo->size);
192  }
193 
194  return out;
195 }
const GBT_NUMKEY * lower
bool(* f_gt)(const void *, const void *, FmgrInfo *)
int32 n
Definition: gist.h:160
struct cursor * cur
Definition: ecpg.c:28
const GBT_NUMKEY * upper
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
Definition: gist.h:161
Datum key
Definition: gist.h:123
char * c
char GBT_NUMKEY
bool(* f_lt)(const void *, const void *, FmgrInfo *)
#define DatumGetPointer(X)
Definition: postgres.h:555
int i