PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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/rel.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 120 of file btree_date.c.

121{
122 /* we assume the difference can't overflow */
125 PG_GETARG_DATUM(1));
126
128}
Datum date_mi(PG_FUNCTION_ARGS)
Definition date.c:553
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:686
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
uint64_t Datum
Definition postgres.h:70
static int32 DatumGetInt32(Datum X)
Definition postgres.h:212
static int fb(int x)

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

◆ gbt_date_compress()

Datum gbt_date_compress ( PG_FUNCTION_ARGS  )

Definition at line 136 of file btree_date.c.

137{
138 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139
141}
static const gbtree_ninfo tinfo
Definition btree_date.c:103
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363

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 152 of file btree_date.c.

153{
154 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
155 DateADT query = PG_GETARG_DATEADT(1);
157#ifdef NOT_USED
158 Oid subtype = PG_GETARG_OID(3);
159#endif
160 bool *recheck = (bool *) PG_GETARG_POINTER(4);
161 dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
163
164 /* All cases served by this function are exact */
165 *recheck = false;
166
167 key.lower = (GBT_NUMKEY *) &kkk->lower;
168 key.upper = (GBT_NUMKEY *) &kkk->upper;
169
170 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
171 GIST_LEAF(entry), &tinfo,
172 fcinfo->flinfo));
173}
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:21
#define PG_GETARG_DATEADT(n)
Definition date.h:95
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_UINT16(n)
Definition fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
#define GIST_LEAF(entry)
Definition gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
unsigned int Oid
uint16 StrategyNumber
Definition stratnum.h:22
Datum key
Definition gist.h:161

References DatumGetPointer(), fb(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, PG_GETARG_DATEADT, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, and tinfo.

◆ gbt_date_distance()

Datum gbt_date_distance ( PG_FUNCTION_ARGS  )

Definition at line 176 of file btree_date.c.

177{
178 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
179 DateADT query = PG_GETARG_DATEADT(1);
180#ifdef NOT_USED
181 Oid subtype = PG_GETARG_OID(3);
182#endif
183 dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
185
186 key.lower = (GBT_NUMKEY *) &kkk->lower;
187 key.upper = (GBT_NUMKEY *) &kkk->upper;
188
189 PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
190 &tinfo, fcinfo->flinfo));
191}
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:369

References DatumGetPointer(), fb(), gbt_num_distance(), GIST_LEAF, GISTENTRY::key, PG_GETARG_DATEADT, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_FLOAT8, and tinfo.

◆ gbt_date_fetch()

Datum gbt_date_fetch ( PG_FUNCTION_ARGS  )

Definition at line 144 of file btree_date.c.

145{
146 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
147
149}
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 204 of file btree_date.c.

205{
208 float *result = (float *) PG_GETARG_POINTER(2);
209 int32 diff,
210 res;
211
214 DateADTGetDatum(origentry->upper)));
215
216 res = Max(diff, 0);
217
220 DateADTGetDatum(newentry->lower)));
221
222 res += Max(diff, 0);
223
224 *result = 0.0;
225
226 if (res > 0)
227 {
230 DateADTGetDatum(origentry->lower)));
231 *result += FLT_MIN;
232 *result += (float) (res / ((double) (res + diff)));
233 *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
234 }
235
236 PG_RETURN_POINTER(result);
237}
#define Max(x, y)
Definition c.h:991
int32_t int32
Definition c.h:542
static Datum DateADTGetDatum(DateADT X)
Definition date.h:78

References date_mi(), DateADTGetDatum(), DatumGetInt32(), DatumGetPointer(), DirectFunctionCall2, fb(), Max, PG_GETARG_POINTER, and PG_RETURN_POINTER.

◆ gbt_date_picksplit()

Datum gbt_date_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 240 of file btree_date.c.

241{
244 &tinfo, fcinfo->flinfo));
245}
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 248 of file btree_date.c.

249{
252 bool *result = (bool *) PG_GETARG_POINTER(2);
253
254 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
255 PG_RETURN_POINTER(result);
256}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_date_sortsupport()

Datum gbt_date_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 271 of file btree_date.c.

272{
274
276 ssup->ssup_extra = NULL;
277
279}
static int gbt_date_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_date.c:259
#define PG_RETURN_VOID()
Definition fmgr.h:350
struct SortSupportData * SortSupport
Definition sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)

References SortSupportData::comparator, fb(), 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 259 of file btree_date.c.

260{
263
264 /* for leaf items we expect lower == upper, so only compare lower */
266 DateADTGetDatum(akey->lower),
267 DateADTGetDatum(bkey->lower)));
268}
Datum date_cmp(PG_FUNCTION_ARGS)
Definition date.c:446
int y
Definition isn.c:76
int x
Definition isn.c:75

References date_cmp(), DateADTGetDatum(), DatumGetInt32(), DatumGetPointer(), DirectFunctionCall2, fb(), x, and y.

Referenced by gbt_date_sortsupport().

◆ gbt_date_union()

Datum gbt_date_union ( PG_FUNCTION_ARGS  )

Definition at line 194 of file btree_date.c.

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

References fb(), 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 47 of file btree_date.c.

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

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 39 of file btree_date.c.

40{
42 DateADTGetDatum(*((const DateADT *) a)),
43 DateADTGetDatum(*((const DateADT *) b))));
44}
Datum date_ge(PG_FUNCTION_ARGS)
Definition date.c:437

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 31 of file btree_date.c.

32{
34 DateADTGetDatum(*((const DateADT *) a)),
35 DateADTGetDatum(*((const DateADT *) b))));
36}
Datum date_gt(PG_FUNCTION_ARGS)
Definition date.c:428

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 74 of file btree_date.c.

75{
76 dateKEY *ia = (dateKEY *) (((const Nsrt *) a)->t);
77 dateKEY *ib = (dateKEY *) (((const Nsrt *) b)->t);
78 int res;
79
81 DateADTGetDatum(ia->lower),
82 DateADTGetDatum(ib->lower)));
83 if (res == 0)
85 DateADTGetDatum(ia->upper),
86 DateADTGetDatum(ib->upper)));
87
88 return res;
89}

References a, b, date_cmp(), DateADTGetDatum(), DatumGetInt32(), DirectFunctionCall2, and fb().

◆ gbt_datele()

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

Definition at line 56 of file btree_date.c.

57{
59 DateADTGetDatum(*((const DateADT *) a)),
60 DateADTGetDatum(*((const DateADT *) b))));
61}
Datum date_le(PG_FUNCTION_ARGS)
Definition date.c:419

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 64 of file btree_date.c.

65{
67 DateADTGetDatum(*((const DateADT *) a)),
68 DateADTGetDatum(*((const DateADT *) b))));
69}
Datum date_lt(PG_FUNCTION_ARGS)
Definition date.c:410

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 92 of file btree_date.c.

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

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

◆ 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:64
static bool gbt_datege(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_date.c:39
static int gbt_datekey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_date.c:74
static float8 gdb_date_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_date.c:92
static bool gbt_dategt(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_date.c:31
static bool gbt_datele(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_date.c:56
static bool gbt_dateeq(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_date.c:47
@ gbt_t_date
Definition btree_gist.h:27

Definition at line 103 of file btree_date.c.

104{
106 sizeof(DateADT),
107 8, /* sizeof(gbtreekey8) */
115};

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