#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/date.h"
#include "utils/timestamp.h"
Go to the source code of this file.
Data Structures | |
struct | timeKEY |
Defines | |
#define | TimeADTGetDatumFast(X) PointerGetDatum(&(X)) |
Functions | |
PG_FUNCTION_INFO_V1 (gbt_time_compress) | |
PG_FUNCTION_INFO_V1 (gbt_timetz_compress) | |
PG_FUNCTION_INFO_V1 (gbt_time_union) | |
PG_FUNCTION_INFO_V1 (gbt_time_picksplit) | |
PG_FUNCTION_INFO_V1 (gbt_time_consistent) | |
PG_FUNCTION_INFO_V1 (gbt_time_distance) | |
PG_FUNCTION_INFO_V1 (gbt_timetz_consistent) | |
PG_FUNCTION_INFO_V1 (gbt_time_penalty) | |
PG_FUNCTION_INFO_V1 (gbt_time_same) | |
Datum | gbt_time_compress (PG_FUNCTION_ARGS) |
Datum | gbt_timetz_compress (PG_FUNCTION_ARGS) |
Datum | gbt_time_union (PG_FUNCTION_ARGS) |
Datum | gbt_time_picksplit (PG_FUNCTION_ARGS) |
Datum | gbt_time_consistent (PG_FUNCTION_ARGS) |
Datum | gbt_time_distance (PG_FUNCTION_ARGS) |
Datum | gbt_timetz_consistent (PG_FUNCTION_ARGS) |
Datum | gbt_time_penalty (PG_FUNCTION_ARGS) |
Datum | gbt_time_same (PG_FUNCTION_ARGS) |
static bool | gbt_timegt (const void *a, const void *b) |
static bool | gbt_timege (const void *a, const void *b) |
static bool | gbt_timeeq (const void *a, const void *b) |
static bool | gbt_timele (const void *a, const void *b) |
static bool | gbt_timelt (const void *a, const void *b) |
static int | gbt_timekey_cmp (const void *a, const void *b) |
static float8 | gbt_time_dist (const void *a, const void *b) |
PG_FUNCTION_INFO_V1 (time_dist) | |
Datum | time_dist (PG_FUNCTION_ARGS) |
Variables | |
static const gbtree_ninfo | tinfo |
#define TimeADTGetDatumFast | ( | X | ) | PointerGetDatum(&(X)) |
Definition at line 44 of file btree_time.c.
Referenced by gbt_time_dist(), gbt_time_penalty(), gbt_timeeq(), gbt_timege(), gbt_timegt(), gbt_timekey_cmp(), gbt_timele(), and gbt_timelt().
Datum gbt_time_compress | ( | PG_FUNCTION_ARGS | ) |
Definition at line 167 of file btree_time.c.
References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.
{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = NULL; PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo)); }
Datum gbt_time_consistent | ( | PG_FUNCTION_ARGS | ) |
Definition at line 208 of file btree_time.c.
References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, timeKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_TIMEADT, PG_GETARG_UINT16, PG_RETURN_BOOL, timeKEY::upper, and GBT_NUMKEY_R::upper.
{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); TimeADT query = PG_GETARG_TIMEADT(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); /* Oid subtype = PG_GETARG_OID(3); */ bool *recheck = (bool *) PG_GETARG_POINTER(4); timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key); GBT_NUMKEY_R key; /* All cases served by this function are exact */ *recheck = false; key.lower = (GBT_NUMKEY *) &kkk->lower; key.upper = (GBT_NUMKEY *) &kkk->upper; PG_RETURN_BOOL( gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo) ); }
static float8 gbt_time_dist | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 120 of file btree_time.c.
References Abs, DatumGetIntervalP, DirectFunctionCall2, i, INTERVAL_TO_SEC, time_mi_time(), and TimeADTGetDatumFast.
{ const TimeADT *aa = (const TimeADT *) a; const TimeADT *bb = (const TimeADT *) b; Interval *i; i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time, TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*bb))); return (float8) Abs(INTERVAL_TO_SEC(i)); }
Datum gbt_time_distance | ( | PG_FUNCTION_ARGS | ) |
Definition at line 231 of file btree_time.c.
References DatumGetPointer, gbt_num_distance(), GIST_LEAF, GISTENTRY::key, timeKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_TIMEADT, PG_RETURN_FLOAT8, timeKEY::upper, and GBT_NUMKEY_R::upper.
{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); TimeADT query = PG_GETARG_TIMEADT(1); /* Oid subtype = PG_GETARG_OID(3); */ timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key); GBT_NUMKEY_R key; key.lower = (GBT_NUMKEY *) &kkk->lower; key.upper = (GBT_NUMKEY *) &kkk->upper; PG_RETURN_FLOAT8( gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) ); }
Datum gbt_time_penalty | ( | PG_FUNCTION_ARGS | ) |
Definition at line 291 of file btree_time.c.
References DatumGetIntervalP, DatumGetPointer, DirectFunctionCall2, INTERVAL_TO_SEC, timeKEY::lower, Max, PG_GETARG_POINTER, PG_RETURN_POINTER, time_mi_time(), TimeADTGetDatumFast, and timeKEY::upper.
{ timeKEY *origentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); float *result = (float *) PG_GETARG_POINTER(2); Interval *intr; double res; double res2; intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, TimeADTGetDatumFast(newentry->upper), TimeADTGetDatumFast(origentry->upper))); res = INTERVAL_TO_SEC(intr); res = Max(res, 0); intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, TimeADTGetDatumFast(origentry->lower), TimeADTGetDatumFast(newentry->lower))); res2 = INTERVAL_TO_SEC(intr); res2 = Max(res2, 0); res += res2; *result = 0.0; if (res > 0) { intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, TimeADTGetDatumFast(origentry->upper), TimeADTGetDatumFast(origentry->lower))); *result += FLT_MIN; *result += (float) (res / (res + INTERVAL_TO_SEC(intr))); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); } PG_RETURN_POINTER(result); }
Datum gbt_time_picksplit | ( | PG_FUNCTION_ARGS | ) |
Definition at line 334 of file btree_time.c.
References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.
{ PG_RETURN_POINTER(gbt_num_picksplit( (GistEntryVector *) PG_GETARG_POINTER(0), (GIST_SPLITVEC *) PG_GETARG_POINTER(1), &tinfo )); }
Datum gbt_time_same | ( | PG_FUNCTION_ARGS | ) |
Definition at line 344 of file btree_time.c.
References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.
{ timeKEY *b1 = (timeKEY *) PG_GETARG_POINTER(0); timeKEY *b2 = (timeKEY *) PG_GETARG_POINTER(1); bool *result = (bool *) PG_GETARG_POINTER(2); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo); PG_RETURN_POINTER(result); }
Datum gbt_time_union | ( | PG_FUNCTION_ARGS | ) |
Definition at line 280 of file btree_time.c.
References gbt_num_union(), palloc(), PG_GETARG_POINTER, and PG_RETURN_POINTER.
{ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); void *out = palloc(sizeof(timeKEY)); *(int *) PG_GETARG_POINTER(1) = sizeof(timeKEY); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo)); }
static bool gbt_timeeq | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 71 of file btree_time.c.
References DatumGetBool, DirectFunctionCall2, time_eq(), and TimeADTGetDatumFast.
{ const TimeADT *aa = (const TimeADT *) a; const TimeADT *bb = (const TimeADT *) b; return DatumGetBool(DirectFunctionCall2(time_eq, TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*bb))); }
static bool gbt_timege | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 60 of file btree_time.c.
References DatumGetBool, DirectFunctionCall2, time_ge(), and TimeADTGetDatumFast.
{ const TimeADT *aa = (const TimeADT *) a; const TimeADT *bb = (const TimeADT *) b; return DatumGetBool(DirectFunctionCall2(time_ge, TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*bb))); }
static bool gbt_timegt | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 49 of file btree_time.c.
References DatumGetBool, DirectFunctionCall2, time_gt(), and TimeADTGetDatumFast.
{ const TimeADT *aa = (const TimeADT *) a; const TimeADT *bb = (const TimeADT *) b; return DatumGetBool(DirectFunctionCall2(time_gt, TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*bb))); }
static int gbt_timekey_cmp | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 106 of file btree_time.c.
References DatumGetInt32, DirectFunctionCall2, timeKEY::lower, time_cmp(), TimeADTGetDatumFast, and timeKEY::upper.
{ timeKEY *ia = (timeKEY *) (((const Nsrt *) a)->t); timeKEY *ib = (timeKEY *) (((const Nsrt *) b)->t); int res; res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower))); if (res == 0) return DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->upper), TimeADTGetDatumFast(ib->upper))); return res; }
static bool gbt_timele | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 82 of file btree_time.c.
References DatumGetBool, DirectFunctionCall2, time_le(), and TimeADTGetDatumFast.
{ const TimeADT *aa = (const TimeADT *) a; const TimeADT *bb = (const TimeADT *) b; return DatumGetBool(DirectFunctionCall2(time_le, TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*bb))); }
static bool gbt_timelt | ( | const void * | a, | |
const void * | b | |||
) | [static] |
Definition at line 93 of file btree_time.c.
References DatumGetBool, DirectFunctionCall2, time_lt(), and TimeADTGetDatumFast.
{ const TimeADT *aa = (const TimeADT *) a; const TimeADT *bb = (const TimeADT *) b; return DatumGetBool(DirectFunctionCall2(time_lt, TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*bb))); }
Datum gbt_timetz_compress | ( | PG_FUNCTION_ARGS | ) |
Definition at line 177 of file btree_time.c.
References DatumGetTimeTzADTP, FALSE, gistentryinit, INT64CONST, GISTENTRY::key, GISTENTRY::leafkey, timeKEY::lower, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, GISTENTRY::rel, TimeTzADT::time, timeKEY::upper, and TimeTzADT::zone.
{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval; if (entry->leafkey) { timeKEY *r = (timeKEY *) palloc(sizeof(timeKEY)); TimeTzADT *tz = DatumGetTimeTzADTP(entry->key); TimeADT tmp; retval = palloc(sizeof(GISTENTRY)); /* We are using the time + zone only to compress */ #ifdef HAVE_INT64_TIMESTAMP tmp = tz->time + (tz->zone * INT64CONST(1000000)); #else tmp = (tz->time + tz->zone); #endif r->lower = r->upper = tmp; gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page, entry->offset, FALSE); } else retval = entry; PG_RETURN_POINTER(retval); }
Datum gbt_timetz_consistent | ( | PG_FUNCTION_ARGS | ) |
Definition at line 249 of file btree_time.c.
References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, INT64CONST, GISTENTRY::key, timeKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_TIMETZADT_P, PG_GETARG_UINT16, PG_RETURN_BOOL, TimeTzADT::time, timeKEY::upper, GBT_NUMKEY_R::upper, and TimeTzADT::zone.
{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); TimeTzADT *query = PG_GETARG_TIMETZADT_P(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); /* Oid subtype = PG_GETARG_OID(3); */ bool *recheck = (bool *) PG_GETARG_POINTER(4); timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key); TimeADT qqq; GBT_NUMKEY_R key; /* All cases served by this function are inexact */ *recheck = true; #ifdef HAVE_INT64_TIMESTAMP qqq = query->time + (query->zone * INT64CONST(1000000)); #else qqq = (query->time + query->zone); #endif key.lower = (GBT_NUMKEY *) &kkk->lower; key.upper = (GBT_NUMKEY *) &kkk->upper; PG_RETURN_BOOL( gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo) ); }
PG_FUNCTION_INFO_V1 | ( | gbt_time_compress | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_time_consistent | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_timetz_compress | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_time_distance | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_time_union | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_timetz_consistent | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_time_picksplit | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_time_same | ) |
PG_FUNCTION_INFO_V1 | ( | gbt_time_penalty | ) |
PG_FUNCTION_INFO_V1 | ( | time_dist | ) |
Datum time_dist | ( | PG_FUNCTION_ARGS | ) |
Definition at line 150 of file btree_time.c.
References abs_interval(), DatumGetIntervalP, DirectFunctionCall2, PG_GETARG_DATUM, PG_RETURN_INTERVAL_P, and time_mi_time().
{ Datum diff = DirectFunctionCall2(time_mi_time, PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)); PG_RETURN_INTERVAL_P(abs_interval(DatumGetIntervalP(diff))); }
const gbtree_ninfo tinfo [static] |
{ gbt_t_time, sizeof(TimeADT), gbt_timegt, gbt_timege, gbt_timeeq, gbt_timele, gbt_timelt, gbt_timekey_cmp, gbt_time_dist }
Definition at line 133 of file btree_time.c.