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

Go to the source code of this file.

Data Structures

struct  dateKEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_date_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_date_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_date_union)
 
 PG_FUNCTION_INFO_V1 (gbt_date_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_date_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_date_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_date_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_date_same)
 
static bool gbt_dategt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_datege (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_dateeq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_datele (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_datelt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_datekey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gdb_date_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (date_dist)
 
Datum date_dist (PG_FUNCTION_ARGS)
 
Datum gbt_date_compress (PG_FUNCTION_ARGS)
 
Datum gbt_date_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_date_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_date_distance (PG_FUNCTION_ARGS)
 
Datum gbt_date_union (PG_FUNCTION_ARGS)
 
Datum gbt_date_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_date_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_date_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

◆ date_dist()

Datum date_dist ( PG_FUNCTION_ARGS  )

Definition at line 114 of file btree_date.c.

References Abs, date_mi(), DatumGetInt32, DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_INT32.

115 {
116  /* we assume the difference can't overflow */
118  PG_GETARG_DATUM(0),
119  PG_GETARG_DATUM(1));
120 
122 }
#define DatumGetInt32(X)
Definition: postgres.h:478
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define Abs(x)
Definition: c.h:808
uintptr_t Datum
Definition: postgres.h:372
Datum date_mi(PG_FUNCTION_ARGS)
Definition: date.c:506
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_date_compress()

Datum gbt_date_compress ( PG_FUNCTION_ARGS  )

Definition at line 132 of file btree_date.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

133 {
134  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
135 
137 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
static const gbtree_ninfo tinfo
Definition: btree_date.c:97

◆ gbt_date_consistent()

Datum gbt_date_consistent ( PG_FUNCTION_ARGS  )

Definition at line 148 of file btree_date.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, dateKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_DATEADT, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, dateKEY::upper, and GBT_NUMKEY_R::upper.

149 {
150  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
151  DateADT query = PG_GETARG_DATEADT(1);
153 
154  /* Oid subtype = PG_GETARG_OID(3); */
155  bool *recheck = (bool *) PG_GETARG_POINTER(4);
156  dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
157  GBT_NUMKEY_R key;
158 
159  /* All cases served by this function are exact */
160  *recheck = false;
161 
162  key.lower = (GBT_NUMKEY *) &kkk->lower;
163  key.upper = (GBT_NUMKEY *) &kkk->upper;
164 
166  gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
167  );
168 }
#define GIST_LEAF(entry)
Definition: gist.h:133
DateADT lower
Definition: btree_date.c:13
const GBT_NUMKEY * lower
int32 DateADT
Definition: date.h:22
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
DateADT upper
Definition: btree_date.c:14
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
static const gbtree_ninfo tinfo
Definition: btree_date.c:97

◆ gbt_date_distance()

Datum gbt_date_distance ( PG_FUNCTION_ARGS  )

Definition at line 172 of file btree_date.c.

References DatumGetPointer, gbt_num_distance(), GIST_LEAF, GISTENTRY::key, dateKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_DATEADT, PG_GETARG_POINTER, PG_RETURN_FLOAT8, dateKEY::upper, and GBT_NUMKEY_R::upper.

173 {
174  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
175  DateADT query = PG_GETARG_DATEADT(1);
176 
177  /* Oid subtype = PG_GETARG_OID(3); */
178  dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
179  GBT_NUMKEY_R key;
180 
181  key.lower = (GBT_NUMKEY *) &kkk->lower;
182  key.upper = (GBT_NUMKEY *) &kkk->upper;
183 
185  gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
186  );
187 }
#define GIST_LEAF(entry)
Definition: gist.h:133
DateADT lower
Definition: btree_date.c:13
const GBT_NUMKEY * lower
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
int32 DateADT
Definition: date.h:22
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
DateADT upper
Definition: btree_date.c:14
#define DatumGetPointer(X)
Definition: postgres.h:555
static const gbtree_ninfo tinfo
Definition: btree_date.c:97

◆ gbt_date_fetch()

Datum gbt_date_fetch ( PG_FUNCTION_ARGS  )

Definition at line 140 of file btree_date.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

141 {
142  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
143 
145 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_date.c:97

◆ gbt_date_penalty()

Datum gbt_date_penalty ( PG_FUNCTION_ARGS  )

Definition at line 202 of file btree_date.c.

References date_mi(), DateADTGetDatum, DatumGetInt32, DatumGetPointer, DirectFunctionCall2, dateKEY::lower, Max, PG_GETARG_POINTER, PG_RETURN_POINTER, and dateKEY::upper.

203 {
204  dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
205  dateKEY *newentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
206  float *result = (float *) PG_GETARG_POINTER(2);
207  int32 diff,
208  res;
209 
211  date_mi,
212  DateADTGetDatum(newentry->upper),
213  DateADTGetDatum(origentry->upper)));
214 
215  res = Max(diff, 0);
216 
218  date_mi,
219  DateADTGetDatum(origentry->lower),
220  DateADTGetDatum(newentry->lower)));
221 
222  res += Max(diff, 0);
223 
224  *result = 0.0;
225 
226  if (res > 0)
227  {
229  date_mi,
230  DateADTGetDatum(origentry->upper),
231  DateADTGetDatum(origentry->lower)));
232  *result += FLT_MIN;
233  *result += (float) (res / ((double) (res + diff)));
234  *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
235  }
236 
237  PG_RETURN_POINTER(result);
238 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
DateADT lower
Definition: btree_date.c:13
#define DatumGetInt32(X)
Definition: postgres.h:478
#define DateADTGetDatum(X)
Definition: date.h:56
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
signed int int32
Definition: c.h:284
#define Max(x, y)
Definition: c.h:796
DateADT upper
Definition: btree_date.c:14
#define DatumGetPointer(X)
Definition: postgres.h:555
Datum date_mi(PG_FUNCTION_ARGS)
Definition: date.c:506
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_date_picksplit()

Datum gbt_date_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 242 of file btree_date.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

243 {
247  &tinfo, fcinfo->flinfo
248  ));
249 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static const gbtree_ninfo tinfo
Definition: btree_date.c:97

◆ gbt_date_same()

Datum gbt_date_same ( PG_FUNCTION_ARGS  )

Definition at line 252 of file btree_date.c.

References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

253 {
254  dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0);
255  dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1);
256  bool *result = (bool *) PG_GETARG_POINTER(2);
257 
258  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
259  PG_RETURN_POINTER(result);
260 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_date.c:97

◆ gbt_date_union()

Datum gbt_date_union ( PG_FUNCTION_ARGS  )

Definition at line 191 of file btree_date.c.

References gbt_num_union(), palloc(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

192 {
194  void *out = palloc(sizeof(dateKEY));
195 
196  *(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY);
197  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
198 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_date.c:97
void * palloc(Size size)
Definition: mcxt.c:848
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

◆ gbt_dateeq()

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

Definition at line 46 of file btree_date.c.

References date_eq(), DateADTGetDatum, DatumGetBool, and DirectFunctionCall2.

47 {
48  return DatumGetBool(
50  );
51 }
Datum date_eq(PG_FUNCTION_ARGS)
Definition: date.c:389
int32 DateADT
Definition: date.h:22
#define DateADTGetDatum(X)
Definition: date.h:56
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_datege()

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

Definition at line 38 of file btree_date.c.

References date_ge(), DateADTGetDatum, DatumGetBool, and DirectFunctionCall2.

39 {
40  return DatumGetBool(
42  );
43 }
int32 DateADT
Definition: date.h:22
#define DateADTGetDatum(X)
Definition: date.h:56
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
Datum date_ge(PG_FUNCTION_ARGS)
Definition: date.c:434

◆ gbt_dategt()

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

Definition at line 30 of file btree_date.c.

References date_gt(), DateADTGetDatum, DatumGetBool, and DirectFunctionCall2.

31 {
32  return DatumGetBool(
34  );
35 }
int32 DateADT
Definition: date.h:22
#define DateADTGetDatum(X)
Definition: date.h:56
#define DatumGetBool(X)
Definition: postgres.h:399
Datum date_gt(PG_FUNCTION_ARGS)
Definition: date.c:425
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_datekey_cmp()

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

Definition at line 72 of file btree_date.c.

References date_cmp(), DateADTGetDatum, DatumGetInt32, DirectFunctionCall2, dateKEY::lower, and dateKEY::upper.

73 {
74  dateKEY *ia = (dateKEY *) (((const Nsrt *) a)->t);
75  dateKEY *ib = (dateKEY *) (((const Nsrt *) b)->t);
76  int res;
77 
79  if (res == 0)
81 
82  return res;
83 }
DateADT lower
Definition: btree_date.c:13
#define DatumGetInt32(X)
Definition: postgres.h:478
#define DateADTGetDatum(X)
Definition: date.h:56
Datum date_cmp(PG_FUNCTION_ARGS)
Definition: date.c:443
DateADT upper
Definition: btree_date.c:14
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_datele()

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

Definition at line 54 of file btree_date.c.

References date_le(), DateADTGetDatum, DatumGetBool, and DirectFunctionCall2.

55 {
56  return DatumGetBool(
58  );
59 }
Datum date_le(PG_FUNCTION_ARGS)
Definition: date.c:416
int32 DateADT
Definition: date.h:22
#define DateADTGetDatum(X)
Definition: date.h:56
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gbt_datelt()

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

Definition at line 62 of file btree_date.c.

References date_lt(), DateADTGetDatum, DatumGetBool, and DirectFunctionCall2.

63 {
64  return DatumGetBool(
66  );
67 }
Datum date_lt(PG_FUNCTION_ARGS)
Definition: date.c:407
int32 DateADT
Definition: date.h:22
#define DateADTGetDatum(X)
Definition: date.h:56
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ gdb_date_dist()

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

Definition at line 86 of file btree_date.c.

References Abs, date_mi(), DateADTGetDatum, DatumGetInt32, and DirectFunctionCall2.

87 {
88  /* we assume the difference can't overflow */
90  DateADTGetDatum(*((const DateADT *) a)),
91  DateADTGetDatum(*((const DateADT *) b)));
92 
93  return (float8) Abs(DatumGetInt32(diff));
94 }
#define DatumGetInt32(X)
Definition: postgres.h:478
int32 DateADT
Definition: date.h:22
#define DateADTGetDatum(X)
Definition: date.h:56
#define Abs(x)
Definition: c.h:808
double float8
Definition: c.h:429
uintptr_t Datum
Definition: postgres.h:372
Datum date_mi(PG_FUNCTION_ARGS)
Definition: date.c:506
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ PG_FUNCTION_INFO_V1() [1/9]

PG_FUNCTION_INFO_V1 ( gbt_date_compress  )

◆ PG_FUNCTION_INFO_V1() [2/9]

PG_FUNCTION_INFO_V1 ( gbt_date_fetch  )

◆ PG_FUNCTION_INFO_V1() [3/9]

PG_FUNCTION_INFO_V1 ( gbt_date_union  )

◆ PG_FUNCTION_INFO_V1() [4/9]

PG_FUNCTION_INFO_V1 ( gbt_date_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/9]

PG_FUNCTION_INFO_V1 ( gbt_date_consistent  )

◆ PG_FUNCTION_INFO_V1() [6/9]

PG_FUNCTION_INFO_V1 ( gbt_date_distance  )

◆ PG_FUNCTION_INFO_V1() [7/9]

PG_FUNCTION_INFO_V1 ( gbt_date_penalty  )

◆ PG_FUNCTION_INFO_V1() [8/9]

PG_FUNCTION_INFO_V1 ( gbt_date_same  )

◆ PG_FUNCTION_INFO_V1() [9/9]

PG_FUNCTION_INFO_V1 ( date_dist  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(DateADT),
8,
}
static bool gbt_datege(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:38
static int gbt_datekey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:72
int32 DateADT
Definition: date.h:22
static bool gbt_datele(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:54
static float8 gdb_date_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:86
static bool gbt_dategt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:30
static bool gbt_dateeq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:46
static bool gbt_datelt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:62

Definition at line 97 of file btree_date.c.