2008-05-17 09:28:26 +08:00
|
|
|
/*
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/btree_gist/btree_time.c
|
2008-05-17 09:28:26 +08:00
|
|
|
*/
|
2011-08-27 09:16:24 +08:00
|
|
|
#include "postgres.h"
|
|
|
|
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
#include "btree_gist.h"
|
|
|
|
#include "btree_utils_num.h"
|
2016-12-29 01:00:00 +08:00
|
|
|
#include "utils/builtins.h"
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
#include "utils/date.h"
|
2006-07-14 00:57:31 +08:00
|
|
|
#include "utils/timestamp.h"
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
TimeADT lower;
|
|
|
|
TimeADT upper;
|
2009-06-11 22:49:15 +08:00
|
|
|
} timeKEY;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** time ops
|
|
|
|
*/
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_compress);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_timetz_compress);
|
2015-03-28 05:35:16 +08:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_fetch);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_union);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_picksplit);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_consistent);
|
2011-03-03 03:43:24 +08:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_distance);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_timetz_consistent);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_penalty);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_time_same);
|
|
|
|
|
|
|
|
|
2008-04-21 08:26:47 +08:00
|
|
|
#ifdef USE_FLOAT8_BYVAL
|
|
|
|
#define TimeADTGetDatumFast(X) TimeADTGetDatum(X)
|
|
|
|
#else
|
|
|
|
#define TimeADTGetDatumFast(X) PointerGetDatum(&(X))
|
|
|
|
#endif
|
|
|
|
|
2005-02-21 18:03:57 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
static bool
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_timegt(const void *a, const void *b, FmgrInfo *flinfo)
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2008-04-21 08:26:47 +08:00
|
|
|
const TimeADT *aa = (const TimeADT *) a;
|
|
|
|
const TimeADT *bb = (const TimeADT *) b;
|
|
|
|
|
|
|
|
return DatumGetBool(DirectFunctionCall2(time_gt,
|
|
|
|
TimeADTGetDatumFast(*aa),
|
|
|
|
TimeADTGetDatumFast(*bb)));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
static bool
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_timege(const void *a, const void *b, FmgrInfo *flinfo)
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2008-04-21 08:26:47 +08:00
|
|
|
const TimeADT *aa = (const TimeADT *) a;
|
|
|
|
const TimeADT *bb = (const TimeADT *) b;
|
|
|
|
|
|
|
|
return DatumGetBool(DirectFunctionCall2(time_ge,
|
|
|
|
TimeADTGetDatumFast(*aa),
|
|
|
|
TimeADTGetDatumFast(*bb)));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
static bool
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_timeeq(const void *a, const void *b, FmgrInfo *flinfo)
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2008-04-21 08:26:47 +08:00
|
|
|
const TimeADT *aa = (const TimeADT *) a;
|
|
|
|
const TimeADT *bb = (const TimeADT *) b;
|
|
|
|
|
|
|
|
return DatumGetBool(DirectFunctionCall2(time_eq,
|
|
|
|
TimeADTGetDatumFast(*aa),
|
|
|
|
TimeADTGetDatumFast(*bb)));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
static bool
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_timele(const void *a, const void *b, FmgrInfo *flinfo)
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2008-04-21 08:26:47 +08:00
|
|
|
const TimeADT *aa = (const TimeADT *) a;
|
|
|
|
const TimeADT *bb = (const TimeADT *) b;
|
|
|
|
|
|
|
|
return DatumGetBool(DirectFunctionCall2(time_le,
|
|
|
|
TimeADTGetDatumFast(*aa),
|
|
|
|
TimeADTGetDatumFast(*bb)));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
static bool
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_timelt(const void *a, const void *b, FmgrInfo *flinfo)
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2008-04-21 08:26:47 +08:00
|
|
|
const TimeADT *aa = (const TimeADT *) a;
|
|
|
|
const TimeADT *bb = (const TimeADT *) b;
|
|
|
|
|
|
|
|
return DatumGetBool(DirectFunctionCall2(time_lt,
|
|
|
|
TimeADTGetDatumFast(*aa),
|
|
|
|
TimeADTGetDatumFast(*bb)));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_timekey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2011-09-12 02:54:32 +08:00
|
|
|
timeKEY *ia = (timeKEY *) (((const Nsrt *) a)->t);
|
|
|
|
timeKEY *ib = (timeKEY *) (((const Nsrt *) b)->t);
|
2010-02-26 10:01:40 +08:00
|
|
|
int res;
|
2009-12-02 21:13:24 +08:00
|
|
|
|
|
|
|
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;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2011-03-03 03:43:24 +08:00
|
|
|
static float8
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_time_dist(const void *a, const void *b, FmgrInfo *flinfo)
|
2011-03-03 03:43:24 +08:00
|
|
|
{
|
|
|
|
const TimeADT *aa = (const TimeADT *) a;
|
|
|
|
const TimeADT *bb = (const TimeADT *) b;
|
2011-04-10 23:42:00 +08:00
|
|
|
Interval *i;
|
2011-03-03 03:43:24 +08:00
|
|
|
|
|
|
|
i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
|
|
|
|
TimeADTGetDatumFast(*aa),
|
|
|
|
TimeADTGetDatumFast(*bb)));
|
|
|
|
return (float8) Abs(INTERVAL_TO_SEC(i));
|
|
|
|
}
|
|
|
|
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
static const gbtree_ninfo tinfo =
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
gbt_t_time,
|
|
|
|
sizeof(TimeADT),
|
2014-05-17 03:11:51 +08:00
|
|
|
16, /* sizeof(gbtreekey16) */
|
2004-08-29 13:07:03 +08:00
|
|
|
gbt_timegt,
|
|
|
|
gbt_timege,
|
|
|
|
gbt_timeeq,
|
|
|
|
gbt_timele,
|
|
|
|
gbt_timelt,
|
2011-03-03 03:43:24 +08:00
|
|
|
gbt_timekey_cmp,
|
|
|
|
gbt_time_dist
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-03 03:43:24 +08:00
|
|
|
PG_FUNCTION_INFO_V1(time_dist);
|
|
|
|
Datum
|
|
|
|
time_dist(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Datum diff = DirectFunctionCall2(time_mi_time,
|
|
|
|
PG_GETARG_DATUM(0),
|
|
|
|
PG_GETARG_DATUM(1));
|
|
|
|
|
|
|
|
PG_RETURN_INTERVAL_P(abs_interval(DatumGetIntervalP(diff)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
/**************************************************
|
|
|
|
* time ops
|
|
|
|
**************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_time_compress(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
|
2015-03-27 05:10:10 +08:00
|
|
|
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_timetz_compress(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
GISTENTRY *retval;
|
|
|
|
|
|
|
|
if (entry->leafkey)
|
|
|
|
{
|
|
|
|
timeKEY *r = (timeKEY *) palloc(sizeof(timeKEY));
|
|
|
|
TimeTzADT *tz = DatumGetTimeTzADTP(entry->key);
|
2005-04-25 15:00:32 +08:00
|
|
|
TimeADT tmp;
|
2004-08-29 13:07:03 +08:00
|
|
|
|
|
|
|
retval = palloc(sizeof(GISTENTRY));
|
|
|
|
|
|
|
|
/* We are using the time + zone only to compress */
|
2005-04-25 15:00:32 +08:00
|
|
|
tmp = tz->time + (tz->zone * INT64CONST(1000000));
|
|
|
|
r->lower = r->upper = tmp;
|
2004-08-29 13:07:03 +08:00
|
|
|
gistentryinit(*retval, PointerGetDatum(r),
|
|
|
|
entry->rel, entry->page,
|
2017-08-16 12:22:32 +08:00
|
|
|
entry->offset, false);
|
2004-08-29 13:07:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
retval = entry;
|
|
|
|
PG_RETURN_POINTER(retval);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2015-03-28 05:35:16 +08:00
|
|
|
Datum
|
|
|
|
gbt_time_fetch(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
|
|
|
|
PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
|
|
|
|
}
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_time_consistent(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
TimeADT query = PG_GETARG_TIMEADT(1);
|
2008-04-15 01:05:34 +08:00
|
|
|
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2008-04-15 01:05:34 +08:00
|
|
|
/* Oid subtype = PG_GETARG_OID(3); */
|
|
|
|
bool *recheck = (bool *) PG_GETARG_POINTER(4);
|
2004-08-29 13:07:03 +08:00
|
|
|
timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
|
|
|
|
GBT_NUMKEY_R key;
|
2008-04-15 01:05:34 +08:00
|
|
|
|
|
|
|
/* All cases served by this function are exact */
|
|
|
|
*recheck = false;
|
2004-08-29 13:07:03 +08:00
|
|
|
|
2009-06-11 22:49:15 +08:00
|
|
|
key.lower = (GBT_NUMKEY *) &kkk->lower;
|
|
|
|
key.upper = (GBT_NUMKEY *) &kkk->upper;
|
2004-08-29 13:07:03 +08:00
|
|
|
|
|
|
|
PG_RETURN_BOOL(
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
|
2004-08-29 13:07:03 +08:00
|
|
|
);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
2011-03-03 03:43:24 +08:00
|
|
|
Datum
|
|
|
|
gbt_time_distance(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
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(
|
2017-05-18 04:31:56 +08:00
|
|
|
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
|
2011-03-03 03:43:24 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
Datum
|
|
|
|
gbt_timetz_consistent(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
TimeTzADT *query = PG_GETARG_TIMETZADT_P(1);
|
2005-04-25 15:00:32 +08:00
|
|
|
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2008-04-15 01:05:34 +08:00
|
|
|
/* Oid subtype = PG_GETARG_OID(3); */
|
|
|
|
bool *recheck = (bool *) PG_GETARG_POINTER(4);
|
2004-08-29 13:07:03 +08:00
|
|
|
timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
|
2005-04-25 15:00:32 +08:00
|
|
|
TimeADT qqq;
|
2004-08-29 13:07:03 +08:00
|
|
|
GBT_NUMKEY_R key;
|
2005-04-25 15:00:32 +08:00
|
|
|
|
2008-04-15 01:05:34 +08:00
|
|
|
/* All cases served by this function are inexact */
|
|
|
|
*recheck = true;
|
|
|
|
|
2005-04-25 15:00:32 +08:00
|
|
|
qqq = query->time + (query->zone * INT64CONST(1000000));
|
2004-08-29 13:07:03 +08:00
|
|
|
|
2009-06-11 22:49:15 +08:00
|
|
|
key.lower = (GBT_NUMKEY *) &kkk->lower;
|
|
|
|
key.upper = (GBT_NUMKEY *) &kkk->upper;
|
2004-08-29 13:07:03 +08:00
|
|
|
|
|
|
|
PG_RETURN_BOOL(
|
2017-03-21 21:12:46 +08:00
|
|
|
gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
|
2004-08-29 13:07:03 +08:00
|
|
|
);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_time_union(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
|
|
|
|
void *out = palloc(sizeof(timeKEY));
|
|
|
|
|
|
|
|
*(int *) PG_GETARG_POINTER(1) = sizeof(timeKEY);
|
2017-03-21 21:12:46 +08:00
|
|
|
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_time_penalty(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
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;
|
2005-07-21 12:15:04 +08:00
|
|
|
double res2;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
intr = DatumGetIntervalP(DirectFunctionCall2(
|
|
|
|
time_mi_time,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
TimeADTGetDatumFast(newentry->upper),
|
|
|
|
TimeADTGetDatumFast(origentry->upper)));
|
2005-07-21 12:15:04 +08:00
|
|
|
res = INTERVAL_TO_SEC(intr);
|
|
|
|
res = Max(res, 0);
|
2004-08-29 13:07:03 +08:00
|
|
|
|
|
|
|
intr = DatumGetIntervalP(DirectFunctionCall2(
|
|
|
|
time_mi_time,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
TimeADTGetDatumFast(origentry->lower),
|
|
|
|
TimeADTGetDatumFast(newentry->lower)));
|
2005-07-21 12:15:04 +08:00
|
|
|
res2 = INTERVAL_TO_SEC(intr);
|
|
|
|
res2 = Max(res2, 0);
|
2004-08-29 13:07:03 +08:00
|
|
|
|
2005-07-21 12:15:04 +08:00
|
|
|
res += res2;
|
2004-08-29 13:07:03 +08:00
|
|
|
|
|
|
|
*result = 0.0;
|
|
|
|
|
|
|
|
if (res > 0)
|
|
|
|
{
|
|
|
|
intr = DatumGetIntervalP(DirectFunctionCall2(
|
|
|
|
time_mi_time,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
TimeADTGetDatumFast(origentry->upper),
|
|
|
|
TimeADTGetDatumFast(origentry->lower)));
|
2004-08-29 13:07:03 +08:00
|
|
|
*result += FLT_MIN;
|
2005-07-21 12:15:04 +08:00
|
|
|
*result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
|
2004-08-29 13:07:03 +08:00
|
|
|
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
PG_RETURN_POINTER(result);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_time_picksplit(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
PG_RETURN_POINTER(gbt_num_picksplit(
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
(GistEntryVector *) PG_GETARG_POINTER(0),
|
|
|
|
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
|
2017-03-21 21:12:46 +08:00
|
|
|
&tinfo, fcinfo->flinfo
|
2004-08-29 13:07:03 +08:00
|
|
|
));
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_time_same(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
timeKEY *b1 = (timeKEY *) PG_GETARG_POINTER(0);
|
|
|
|
timeKEY *b2 = (timeKEY *) PG_GETARG_POINTER(1);
|
|
|
|
bool *result = (bool *) PG_GETARG_POINTER(2);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2017-03-21 21:12:46 +08:00
|
|
|
*result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
|
2004-08-29 13:07:03 +08:00
|
|
|
PG_RETURN_POINTER(result);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
}
|