PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree_date.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/fmgrprotos.h"
#include "utils/date.h"
#include "utils/sortsupport.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)
 
 PG_FUNCTION_INFO_V1 (gbt_date_sortsupport)
 
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)
 
static int gbt_date_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_date_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

◆ date_dist()

Datum date_dist ( PG_FUNCTION_ARGS  )

Definition at line 119 of file btree_date.c.

120{
121 /* we assume the difference can't overflow */
124 PG_GETARG_DATUM(1));
125
126 PG_RETURN_INT32(abs(DatumGetInt32(diff)));
127}
Datum date_mi(PG_FUNCTION_ARGS)
Definition: date.c:552
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:684
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
uintptr_t Datum
Definition: postgres.h:69
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207

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

◆ gbt_date_compress()

Datum gbt_date_compress ( PG_FUNCTION_ARGS  )

Definition at line 135 of file btree_date.c.

136{
137 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
138
140}
static const gbtree_ninfo tinfo
Definition: btree_date.c:102
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361

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

◆ gbt_date_consistent()

Datum gbt_date_consistent ( PG_FUNCTION_ARGS  )

Definition at line 151 of file btree_date.c.

152{
153 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
154 DateADT query = PG_GETARG_DATEADT(1);
156
157 /* Oid subtype = PG_GETARG_OID(3); */
158 bool *recheck = (bool *) PG_GETARG_POINTER(4);
159 dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
161
162 /* All cases served by this function are exact */
163 *recheck = false;
164
165 key.lower = (GBT_NUMKEY *) &kkk->lower;
166 key.upper = (GBT_NUMKEY *) &kkk->upper;
167
168 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
169 GIST_LEAF(entry), &tinfo,
170 fcinfo->flinfo));
171}
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
char GBT_NUMKEY
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:89
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:161
DateADT upper
Definition: btree_date.c:15
DateADT lower
Definition: btree_date.c:14

References DatumGetPointer(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, sort-test::key, dateKEY::lower, PG_GETARG_DATEADT, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, tinfo, and dateKEY::upper.

◆ gbt_date_distance()

Datum gbt_date_distance ( PG_FUNCTION_ARGS  )

Definition at line 174 of file btree_date.c.

175{
176 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
177 DateADT query = PG_GETARG_DATEADT(1);
178
179 /* Oid subtype = PG_GETARG_OID(3); */
180 dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
182
183 key.lower = (GBT_NUMKEY *) &kkk->lower;
184 key.upper = (GBT_NUMKEY *) &kkk->upper;
185
187 &tinfo, fcinfo->flinfo));
188}
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367

References DatumGetPointer(), gbt_num_distance(), GIST_LEAF, GISTENTRY::key, sort-test::key, dateKEY::lower, PG_GETARG_DATEADT, PG_GETARG_POINTER, PG_RETURN_FLOAT8, tinfo, and dateKEY::upper.

◆ gbt_date_fetch()

Datum gbt_date_fetch ( PG_FUNCTION_ARGS  )

Definition at line 143 of file btree_date.c.

144{
145 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
146
148}
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

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

◆ gbt_date_penalty()

Datum gbt_date_penalty ( PG_FUNCTION_ARGS  )

Definition at line 201 of file btree_date.c.

202{
203 dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
205 float *result = (float *) PG_GETARG_POINTER(2);
206 int32 diff,
207 res;
208
210 DateADTGetDatum(newentry->upper),
211 DateADTGetDatum(origentry->upper)));
212
213 res = Max(diff, 0);
214
216 DateADTGetDatum(origentry->lower),
217 DateADTGetDatum(newentry->lower)));
218
219 res += Max(diff, 0);
220
221 *result = 0.0;
222
223 if (res > 0)
224 {
226 DateADTGetDatum(origentry->upper),
227 DateADTGetDatum(origentry->lower)));
228 *result += FLT_MIN;
229 *result += (float) (res / ((double) (res + diff)));
230 *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
231 }
232
233 PG_RETURN_POINTER(result);
234}
#define Max(x, y)
Definition: c.h:969
int32_t int32
Definition: c.h:498
static Datum DateADTGetDatum(DateADT X)
Definition: date.h:72

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

◆ gbt_date_picksplit()

Datum gbt_date_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 237 of file btree_date.c.

238{
241 &tinfo, fcinfo->flinfo));
242}
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_date_same()

Datum gbt_date_same ( PG_FUNCTION_ARGS  )

Definition at line 245 of file btree_date.c.

246{
247 dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0);
248 dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1);
249 bool *result = (bool *) PG_GETARG_POINTER(2);
250
251 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
252 PG_RETURN_POINTER(result);
253}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_date_sortsupport()

Datum gbt_date_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 268 of file btree_date.c.

269{
271
273 ssup->ssup_extra = NULL;
274
276}
static int gbt_date_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_date.c:256
#define PG_RETURN_VOID()
Definition: fmgr.h:349
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87

References SortSupportData::comparator, gbt_date_ssup_cmp(), PG_GETARG_POINTER, PG_RETURN_VOID, and SortSupportData::ssup_extra.

◆ gbt_date_ssup_cmp()

static int gbt_date_ssup_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 256 of file btree_date.c.

257{
258 dateKEY *akey = (dateKEY *) DatumGetPointer(x);
259 dateKEY *bkey = (dateKEY *) DatumGetPointer(y);
260
261 /* for leaf items we expect lower == upper, so only compare lower */
263 DateADTGetDatum(akey->lower),
264 DateADTGetDatum(bkey->lower)));
265}
Datum date_cmp(PG_FUNCTION_ARGS)
Definition: date.c:445
int y
Definition: isn.c:76
int x
Definition: isn.c:75

References date_cmp(), DateADTGetDatum(), DatumGetInt32(), DatumGetPointer(), DirectFunctionCall2, dateKEY::lower, x, and y.

Referenced by gbt_date_sortsupport().

◆ gbt_date_union()

Datum gbt_date_union ( PG_FUNCTION_ARGS  )

Definition at line 191 of file btree_date.c.

192{
194 void *out = palloc(sizeof(dateKEY));
195
196 *(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY);
197 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
198}
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * palloc(Size size)
Definition: mcxt.c:1321

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

◆ gbt_dateeq()

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

Definition at line 46 of file btree_date.c.

47{
49 DateADTGetDatum(*((const DateADT *) a)),
50 DateADTGetDatum(*((const DateADT *) b)))
51 );
52}
Datum date_eq(PG_FUNCTION_ARGS)
Definition: date.c:391
int b
Definition: isn.c:74
int a
Definition: isn.c:73
static bool DatumGetBool(Datum X)
Definition: postgres.h:95

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

◆ gbt_datege()

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

Definition at line 38 of file btree_date.c.

39{
41 DateADTGetDatum(*((const DateADT *) a)),
42 DateADTGetDatum(*((const DateADT *) b))));
43}
Datum date_ge(PG_FUNCTION_ARGS)
Definition: date.c:436

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

◆ gbt_dategt()

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

Definition at line 30 of file btree_date.c.

31{
33 DateADTGetDatum(*((const DateADT *) a)),
34 DateADTGetDatum(*((const DateADT *) b))));
35}
Datum date_gt(PG_FUNCTION_ARGS)
Definition: date.c:427

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

◆ gbt_datekey_cmp()

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

Definition at line 73 of file btree_date.c.

74{
75 dateKEY *ia = (dateKEY *) (((const Nsrt *) a)->t);
76 dateKEY *ib = (dateKEY *) (((const Nsrt *) b)->t);
77 int res;
78
82 if (res == 0)
86
87 return res;
88}

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

◆ gbt_datele()

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

Definition at line 55 of file btree_date.c.

56{
58 DateADTGetDatum(*((const DateADT *) a)),
59 DateADTGetDatum(*((const DateADT *) b))));
60}
Datum date_le(PG_FUNCTION_ARGS)
Definition: date.c:418

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

◆ gbt_datelt()

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

Definition at line 63 of file btree_date.c.

64{
66 DateADTGetDatum(*((const DateADT *) a)),
67 DateADTGetDatum(*((const DateADT *) b))));
68}
Datum date_lt(PG_FUNCTION_ARGS)
Definition: date.c:409

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

◆ gdb_date_dist()

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

Definition at line 91 of file btree_date.c.

92{
93 /* we assume the difference can't overflow */
95 DateADTGetDatum(*((const DateADT *) a)),
96 DateADTGetDatum(*((const DateADT *) b)));
97
98 return (float8) abs(DatumGetInt32(diff));
99}
double float8
Definition: c.h:601

References a, b, date_mi(), DateADTGetDatum(), DatumGetInt32(), and DirectFunctionCall2.

◆ PG_FUNCTION_INFO_V1() [1/10]

PG_FUNCTION_INFO_V1 ( date_dist  )

◆ PG_FUNCTION_INFO_V1() [2/10]

PG_FUNCTION_INFO_V1 ( gbt_date_compress  )

◆ PG_FUNCTION_INFO_V1() [3/10]

PG_FUNCTION_INFO_V1 ( gbt_date_consistent  )

◆ PG_FUNCTION_INFO_V1() [4/10]

PG_FUNCTION_INFO_V1 ( gbt_date_distance  )

◆ PG_FUNCTION_INFO_V1() [5/10]

PG_FUNCTION_INFO_V1 ( gbt_date_fetch  )

◆ PG_FUNCTION_INFO_V1() [6/10]

PG_FUNCTION_INFO_V1 ( gbt_date_penalty  )

◆ PG_FUNCTION_INFO_V1() [7/10]

PG_FUNCTION_INFO_V1 ( gbt_date_picksplit  )

◆ PG_FUNCTION_INFO_V1() [8/10]

PG_FUNCTION_INFO_V1 ( gbt_date_same  )

◆ PG_FUNCTION_INFO_V1() [9/10]

PG_FUNCTION_INFO_V1 ( gbt_date_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [10/10]

PG_FUNCTION_INFO_V1 ( gbt_date_union  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(DateADT),
8,
}
static bool gbt_datelt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:63
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:73
static float8 gdb_date_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:91
static bool gbt_dategt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:30
static bool gbt_datele(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:55
static bool gbt_dateeq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_date.c:46
@ gbt_t_date
Definition: btree_gist.h:27

Definition at line 102 of file btree_date.c.

Referenced by gbt_date_compress(), gbt_date_consistent(), gbt_date_distance(), gbt_date_fetch(), gbt_date_picksplit(), gbt_date_same(), and gbt_date_union().