2008-05-17 03:28:26 +02:00
|
|
|
/*
|
2010-09-20 22:08:53 +02:00
|
|
|
* contrib/btree_gist/btree_int8.c
|
2008-05-17 03:28:26 +02:00
|
|
|
*/
|
2011-08-27 03:16:24 +02: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 12:43:32 +02:00
|
|
|
#include "btree_gist.h"
|
|
|
|
#include "btree_utils_num.h"
|
2017-12-13 01:32:31 +01:00
|
|
|
#include "common/int.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 12:43:32 +02:00
|
|
|
|
|
|
|
typedef struct int64key
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
int64 lower;
|
|
|
|
int64 upper;
|
2009-06-11 16:49:15 +02:00
|
|
|
} int64KEY;
|
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 12:43:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
** int64 ops
|
|
|
|
*/
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_compress);
|
2015-03-27 22:35:16 +01:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_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 12:43:32 +02:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_union);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_picksplit);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_consistent);
|
2011-03-02 20:43:24 +01:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_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 12:43:32 +02:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_penalty);
|
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_same);
|
2021-04-07 12:22:05 +02:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_int8_sortsupport);
|
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 12:43:32 +02:00
|
|
|
|
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
static bool
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8gt(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 12:43:32 +02:00
|
|
|
{
|
2011-09-11 20:54:32 +02:00
|
|
|
return (*((const int64 *) a) > *((const int64 *) b));
|
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 12:43:32 +02:00
|
|
|
}
|
2004-08-29 07:07:03 +02:00
|
|
|
static bool
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8ge(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 12:43:32 +02:00
|
|
|
{
|
2011-09-11 20:54:32 +02:00
|
|
|
return (*((const int64 *) a) >= *((const int64 *) b));
|
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 12:43:32 +02:00
|
|
|
}
|
2004-08-29 07:07:03 +02:00
|
|
|
static bool
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8eq(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 12:43:32 +02:00
|
|
|
{
|
2011-09-11 20:54:32 +02:00
|
|
|
return (*((const int64 *) a) == *((const int64 *) b));
|
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 12:43:32 +02:00
|
|
|
}
|
2004-08-29 07:07:03 +02:00
|
|
|
static bool
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8le(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 12:43:32 +02:00
|
|
|
{
|
2011-09-11 20:54:32 +02:00
|
|
|
return (*((const int64 *) a) <= *((const int64 *) b));
|
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 12:43:32 +02:00
|
|
|
}
|
2004-08-29 07:07:03 +02:00
|
|
|
static bool
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8lt(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 12:43:32 +02:00
|
|
|
{
|
2011-09-11 20:54:32 +02:00
|
|
|
return (*((const int64 *) a) < *((const int64 *) b));
|
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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8key_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 12:43:32 +02:00
|
|
|
{
|
2011-09-11 20:54:32 +02:00
|
|
|
int64KEY *ia = (int64KEY *) (((const Nsrt *) a)->t);
|
|
|
|
int64KEY *ib = (int64KEY *) (((const Nsrt *) b)->t);
|
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 12:43:32 +02:00
|
|
|
|
2009-12-02 14:13:24 +01:00
|
|
|
if (ia->lower == ib->lower)
|
|
|
|
{
|
|
|
|
if (ia->upper == ib->upper)
|
|
|
|
return 0;
|
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 12:43:32 +02:00
|
|
|
|
2009-12-02 14:13:24 +01:00
|
|
|
return (ia->upper > ib->upper) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ia->lower > ib->lower) ? 1 : -1;
|
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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
2011-03-02 20:43:24 +01:00
|
|
|
static float8
|
2017-03-21 14:12:46 +01:00
|
|
|
gbt_int8_dist(const void *a, const void *b, FmgrInfo *flinfo)
|
2011-03-02 20:43:24 +01:00
|
|
|
{
|
|
|
|
return GET_FLOAT_DISTANCE(int64, a, b);
|
|
|
|
}
|
|
|
|
|
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 12:43:32 +02:00
|
|
|
|
2004-08-29 07:07:03 +02: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 12:43:32 +02:00
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
gbt_t_int8,
|
|
|
|
sizeof(int64),
|
2014-05-16 21:11:51 +02:00
|
|
|
16, /* sizeof(gbtreekey16) */
|
2004-08-29 07:07:03 +02:00
|
|
|
gbt_int8gt,
|
|
|
|
gbt_int8ge,
|
|
|
|
gbt_int8eq,
|
|
|
|
gbt_int8le,
|
|
|
|
gbt_int8lt,
|
2011-03-02 20:43:24 +01:00
|
|
|
gbt_int8key_cmp,
|
|
|
|
gbt_int8_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 12:43:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-02 20:43:24 +01:00
|
|
|
PG_FUNCTION_INFO_V1(int8_dist);
|
|
|
|
Datum
|
|
|
|
int8_dist(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2011-04-10 17:42:00 +02:00
|
|
|
int64 a = PG_GETARG_INT64(0);
|
|
|
|
int64 b = PG_GETARG_INT64(1);
|
|
|
|
int64 r;
|
|
|
|
int64 ra;
|
2011-03-02 20:43:24 +01:00
|
|
|
|
2017-12-13 01:32:31 +01:00
|
|
|
if (pg_sub_s64_overflow(a, b, &r) ||
|
2017-12-13 03:15:22 +01:00
|
|
|
r == PG_INT64_MIN)
|
2011-03-02 20:43:24 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
|
2011-04-10 17:42:00 +02:00
|
|
|
errmsg("bigint out of range")));
|
2011-03-02 20:43:24 +01:00
|
|
|
|
2017-12-13 01:32:31 +01:00
|
|
|
ra = Abs(r);
|
|
|
|
|
2011-03-02 20:43:24 +01:00
|
|
|
PG_RETURN_INT64(ra);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 12:43:32 +02:00
|
|
|
/**************************************************
|
|
|
|
* int64 ops
|
|
|
|
**************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_int8_compress(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
|
2015-03-26 22:10:10 +01: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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:35:16 +01:00
|
|
|
Datum
|
|
|
|
gbt_int8_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 12:43:32 +02:00
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_int8_consistent(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
int64 query = PG_GETARG_INT64(1);
|
2008-04-14 19:05:34 +02:00
|
|
|
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
2009-06-11 16:49:15 +02:00
|
|
|
|
2008-04-14 19:05:34 +02:00
|
|
|
/* Oid subtype = PG_GETARG_OID(3); */
|
|
|
|
bool *recheck = (bool *) PG_GETARG_POINTER(4);
|
2004-08-29 07:07:03 +02:00
|
|
|
int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
|
|
|
|
GBT_NUMKEY_R key;
|
2008-04-14 19:05:34 +02:00
|
|
|
|
|
|
|
/* All cases served by this function are exact */
|
|
|
|
*recheck = false;
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2009-06-11 16:49:15 +02:00
|
|
|
key.lower = (GBT_NUMKEY *) &kkk->lower;
|
|
|
|
key.upper = (GBT_NUMKEY *) &kkk->upper;
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2020-01-30 17:42:14 +01:00
|
|
|
PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
|
|
|
|
GIST_LEAF(entry), &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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 20:43:24 +01:00
|
|
|
Datum
|
|
|
|
gbt_int8_distance(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
|
|
|
int64 query = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
/* Oid subtype = PG_GETARG_OID(3); */
|
|
|
|
int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
|
|
|
|
GBT_NUMKEY_R key;
|
|
|
|
|
|
|
|
key.lower = (GBT_NUMKEY *) &kkk->lower;
|
|
|
|
key.upper = (GBT_NUMKEY *) &kkk->upper;
|
|
|
|
|
2020-01-30 17:42:14 +01:00
|
|
|
PG_RETURN_FLOAT8(gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry),
|
|
|
|
&tinfo, fcinfo->flinfo));
|
2011-03-02 20:43:24 +01: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 12:43:32 +02:00
|
|
|
Datum
|
|
|
|
gbt_int8_union(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
|
|
|
|
void *out = palloc(sizeof(int64KEY));
|
|
|
|
|
|
|
|
*(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
|
2017-03-21 14:12:46 +01: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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_int8_penalty(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
|
2005-10-15 04:49:52 +02:00
|
|
|
int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
|
|
|
|
float *result = (float *) PG_GETARG_POINTER(2);
|
|
|
|
|
|
|
|
penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
|
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 12:43:32 +02:00
|
|
|
|
2004-08-29 07:07:03 +02: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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_int8_picksplit(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2020-01-30 17:42:14 +01:00
|
|
|
PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
|
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-21 21:35:54 +02:00
|
|
|
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
|
2020-01-30 17:42:14 +01:00
|
|
|
&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 12:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_int8_same(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0);
|
|
|
|
int64KEY *b2 = (int64KEY *) 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 12:43:32 +02:00
|
|
|
|
2017-03-21 14:12:46 +01:00
|
|
|
*result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
|
2004-08-29 07:07:03 +02: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 12:43:32 +02:00
|
|
|
}
|
2021-04-07 12:22:05 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
gbt_int8_sort_build_cmp(Datum a, Datum b, SortSupport ssup)
|
|
|
|
{
|
|
|
|
int64KEY *ia = (int64KEY *) DatumGetPointer(a);
|
|
|
|
int64KEY *ib = (int64KEY *) DatumGetPointer(b);
|
|
|
|
|
|
|
|
/* for leaf items we expect lower == upper */
|
|
|
|
Assert(ia->lower == ia->upper);
|
|
|
|
Assert(ib->lower == ib->upper);
|
|
|
|
|
|
|
|
if (ia->lower == ib->lower)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (ia->lower > ib->lower) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
gbt_int8_abbrev_convert(Datum original, SortSupport ssup)
|
|
|
|
{
|
|
|
|
int64KEY *b1 = (int64KEY *) DatumGetPointer(original);
|
|
|
|
int64 z = b1->lower;
|
|
|
|
|
|
|
|
#if SIZEOF_DATUM == 8
|
|
|
|
return Int64GetDatum(z);
|
|
|
|
#else
|
|
|
|
return Int32GetDatum(z >> 32);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gbt_int8_cmp_abbrev(Datum z1, Datum z2, SortSupport ssup)
|
|
|
|
{
|
|
|
|
#if SIZEOF_DATUM == 8
|
|
|
|
int64 a = DatumGetInt64(z1);
|
|
|
|
int64 b = DatumGetInt64(z2);
|
|
|
|
#else
|
|
|
|
int32 a = DatumGetInt32(z1);
|
|
|
|
int32 b = DatumGetInt32(z2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (a > b)
|
|
|
|
return 1;
|
|
|
|
else if (a < b)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We never consider aborting the abbreviation.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
gbt_int8_abbrev_abort(int memtupcount, SortSupport ssup)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort support routine for fast GiST index build by sorting.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
gbt_int8_sortsupport(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
|
|
|
|
|
|
|
|
if (ssup->abbreviate)
|
|
|
|
{
|
|
|
|
ssup->comparator = gbt_int8_cmp_abbrev;
|
|
|
|
ssup->abbrev_converter = gbt_int8_abbrev_convert;
|
|
|
|
ssup->abbrev_abort = gbt_int8_abbrev_abort;
|
|
|
|
ssup->abbrev_full_comparator = gbt_int8_sort_build_cmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ssup->comparator = gbt_int8_sort_build_cmp;
|
|
|
|
}
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|