PostgreSQL Source Code git master
Data Structures | Functions | Variables
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

 
 
 
 
 
 
 
 
 
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)
 
 
 
 
 
 
 
 
 
 
 
static int  gbt_date_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
 

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
127 PG_RETURN_INT32(abs(DatumGetInt32(diff)));
128}
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
uint64_t Datum
Definition: postgres.h:70
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212

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 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:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
Definition: gist.h:160

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
158 /* Oid subtype = PG_GETARG_OID(3); */
159 bool *recheck = (bool *) PG_GETARG_POINTER(4);
160 dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
162
163 /* All cases served by this function are exact */
164 *recheck = false;
165
166 key.lower = (GBT_NUMKEY *) &kkk->lower;
167 key.upper = (GBT_NUMKEY *) &kkk->upper;
168
169 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
170 GIST_LEAF(entry), &tinfo,
171 fcinfo->flinfo));
172}
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:322
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:161
DateADT upper
Definition: btree_date.c:16
DateADT lower
Definition: btree_date.c:15

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

176{
177 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
178 DateADT query = PG_GETARG_DATEADT(1);
179
180 /* Oid subtype = PG_GETARG_OID(3); */
181 dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
183
184 key.lower = (GBT_NUMKEY *) &kkk->lower;
185 key.upper = (GBT_NUMKEY *) &kkk->upper;
186
188 &tinfo, fcinfo->flinfo));
189}
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 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 202 of file btree_date.c.

203{
204 dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
206 float *result = (float *) PG_GETARG_POINTER(2);
207 int32 diff,
208 res;
209
211 DateADTGetDatum(newentry->upper),
212 DateADTGetDatum(origentry->upper)));
213
214 res = Max(diff, 0);
215
217 DateADTGetDatum(origentry->lower),
218 DateADTGetDatum(newentry->lower)));
219
220 res += Max(diff, 0);
221
222 *result = 0.0;
223
224 if (res > 0)
225 {
227 DateADTGetDatum(origentry->upper),
228 DateADTGetDatum(origentry->lower)));
229 *result += FLT_MIN;
230 *result += (float) (res / ((double) (res + diff)));
231 *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
232 }
233
234 PG_RETURN_POINTER(result);
235}
#define Max(x, y)
Definition: c.h:997
int32_t int32
Definition: c.h:534
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 238 of file btree_date.c.

239{
242 &tinfo, fcinfo->flinfo));
243}
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 246 of file btree_date.c.

247{
248 dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0);
249 dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1);
250 bool *result = (bool *) PG_GETARG_POINTER(2);
251
252 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
253 PG_RETURN_POINTER(result);
254}
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 269 of file btree_date.c.

270{
272
274 ssup->ssup_extra = NULL;
275
277}
static int gbt_date_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_date.c:257
#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 257 of file btree_date.c.

258{
259 dateKEY *akey = (dateKEY *) DatumGetPointer(x);
260 dateKEY *bkey = (dateKEY *) DatumGetPointer(y);
261
262 /* for leaf items we expect lower == upper, so only compare lower */
264 DateADTGetDatum(akey->lower),
265 DateADTGetDatum(bkey->lower)));
266}
Datum date_cmp(PG_FUNCTION_ARGS)
Definition: date.c:445
y
int y
Definition: isn.c:76
x
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 192 of file btree_date.c.

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

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,
FmgrInfoflinfo 
)
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:391
b
int b
Definition: isn.c:74
a
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,
FmgrInfoflinfo 
)
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:436

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

gbt_dategt()

static bool gbt_dategt ( const void *  a,
const void *  b,
FmgrInfoflinfo 
)
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:427

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

gbt_datekey_cmp()

static int gbt_datekey_cmp ( const void *  a,
const void *  b,
FmgrInfoflinfo 
)
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
83 if (res == 0)
87
88 return res;
89}

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,
FmgrInfoflinfo 
)
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:418

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

gbt_datelt()

static bool gbt_datelt ( const void *  a,
const void *  b,
FmgrInfoflinfo 
)
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:409

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

gdb_date_dist()

static float8 gdb_date_dist ( const void *  a,
const void *  b,
FmgrInfoflinfo 
)
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:635

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

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

AltStyle によって変換されたページ (->オリジナル) /