2008-05-17 05:28:26 +04:00
|
|
|
/*
|
2010-09-21 00:08:53 +04:00
|
|
|
* contrib/btree_gist/btree_utils_var.c
|
2008-05-17 05:28:26 +04:00
|
|
|
*/
|
2011-08-27 05:16:24 +04:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2006-07-13 20:57:31 +04:00
|
|
|
#include <math.h>
|
2006-07-14 08:44:46 +04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <float.h>
|
2006-07-13 20:57:31 +04:00
|
|
|
|
2019-10-23 06:56:22 +03:00
|
|
|
#include "btree_gist.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 14:43:32 +04:00
|
|
|
#include "btree_utils_var.h"
|
2005-07-01 17:44:56 +04:00
|
|
|
#include "utils/builtins.h"
|
2019-10-23 06:56:22 +03:00
|
|
|
#include "utils/pg_locale.h"
|
2008-06-19 04:46:06 +04:00
|
|
|
#include "utils/rel.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 14:43:32 +04:00
|
|
|
|
2011-04-23 04:19:58 +04:00
|
|
|
/* used for key sorting */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GBT_VARKEY *t;
|
|
|
|
} Vsrt;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const gbtree_vinfo *tinfo;
|
|
|
|
Oid collation;
|
2017-03-21 16:53:35 +03:00
|
|
|
FmgrInfo *flinfo;
|
2011-04-23 04:19:58 +04:00
|
|
|
} gbt_vsrt_arg;
|
|
|
|
|
|
|
|
|
2005-03-01 18:40:04 +03:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_var_decompress);
|
2015-03-28 00:35:16 +03:00
|
|
|
PG_FUNCTION_INFO_V1(gbt_var_fetch);
|
2005-03-01 18:40:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
gbt_var_decompress(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2005-05-21 16:08:06 +04:00
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
2017-09-18 22:21:23 +03:00
|
|
|
GBT_VARKEY *key = (GBT_VARKEY *) PG_DETOAST_DATUM(entry->key);
|
2005-03-01 18:40:04 +03:00
|
|
|
|
2005-05-21 16:08:06 +04:00
|
|
|
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
|
|
|
|
{
|
|
|
|
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
|
2005-03-01 18:40:04 +03:00
|
|
|
|
2005-05-21 16:08:06 +04:00
|
|
|
gistentryinit(*retval, PointerGetDatum(key),
|
|
|
|
entry->rel, entry->page,
|
2017-08-16 07:22:32 +03:00
|
|
|
entry->offset, false);
|
2005-03-01 18:40:04 +03:00
|
|
|
|
2005-05-21 16:08:06 +04:00
|
|
|
PG_RETURN_POINTER(retval);
|
|
|
|
}
|
2005-03-01 18:40:04 +03:00
|
|
|
|
2005-05-21 16:08:06 +04:00
|
|
|
PG_RETURN_POINTER(entry);
|
2005-03-01 18:40:04 +03:00
|
|
|
}
|
|
|
|
|
2015-09-05 11:35:49 +03:00
|
|
|
/* Returns a better readable representation of variable key ( sets pointer ) */
|
2005-05-12 04:39:37 +04:00
|
|
|
GBT_VARKEY_R
|
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 14:43:32 +04:00
|
|
|
gbt_var_key_readable(const GBT_VARKEY *k)
|
|
|
|
{
|
|
|
|
GBT_VARKEY_R r;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
r.lower = (bytea *) &(((char *) k)[VARHDRSZ]);
|
|
|
|
if (VARSIZE(k) > (VARHDRSZ + (VARSIZE(r.lower))))
|
2004-06-03 16:26:10 +04:00
|
|
|
r.upper = (bytea *) &(((char *) k)[VARHDRSZ + INTALIGN(VARSIZE(r.lower))]);
|
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 14:43:32 +04:00
|
|
|
else
|
|
|
|
r.upper = r.lower;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-27 00:10:10 +03:00
|
|
|
/*
|
|
|
|
* Create a leaf-entry to store in the index, from a single Datum.
|
|
|
|
*/
|
|
|
|
static GBT_VARKEY *
|
|
|
|
gbt_var_key_from_datum(const struct varlena *u)
|
|
|
|
{
|
|
|
|
int32 lowersize = VARSIZE(u);
|
|
|
|
GBT_VARKEY *r;
|
|
|
|
|
|
|
|
r = (GBT_VARKEY *) palloc(lowersize + VARHDRSZ);
|
|
|
|
memcpy(VARDATA(r), u, lowersize);
|
|
|
|
SET_VARSIZE(r, lowersize + VARHDRSZ);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an entry to store in the index, from lower and upper bound.
|
|
|
|
*/
|
2005-05-12 04:39:37 +04:00
|
|
|
GBT_VARKEY *
|
2015-03-27 00:10:10 +03:00
|
|
|
gbt_var_key_copy(const GBT_VARKEY_R *u)
|
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 14:43:32 +04:00
|
|
|
{
|
2014-05-16 23:29:02 +04:00
|
|
|
int32 lowersize = VARSIZE(u->lower);
|
|
|
|
int32 uppersize = VARSIZE(u->upper);
|
2015-03-27 00:10:10 +03:00
|
|
|
GBT_VARKEY *r;
|
|
|
|
|
|
|
|
r = (GBT_VARKEY *) palloc0(INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
|
|
|
memcpy(VARDATA(r), u->lower, lowersize);
|
|
|
|
memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
|
|
|
|
SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
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 14:43:32 +04:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GBT_VARKEY *
|
2017-03-21 16:53:35 +03:00
|
|
|
gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, 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 14:43:32 +04:00
|
|
|
{
|
|
|
|
GBT_VARKEY *out = leaf;
|
|
|
|
|
|
|
|
if (tinfo->f_l2n)
|
2017-09-07 19:06:23 +03:00
|
|
|
out = tinfo->f_l2n(leaf, 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 14:43:32 +04:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the common prefix length of a node key
|
|
|
|
*/
|
|
|
|
static int32
|
|
|
|
gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
|
|
|
|
{
|
2005-07-01 17:44:56 +04:00
|
|
|
GBT_VARKEY_R r = gbt_var_key_readable(node);
|
|
|
|
int32 i = 0;
|
|
|
|
int32 l = 0;
|
|
|
|
int32 t1len = VARSIZE(r.lower) - VARHDRSZ;
|
|
|
|
int32 t2len = VARSIZE(r.upper) - VARHDRSZ;
|
|
|
|
int32 ml = Min(t1len, t2len);
|
|
|
|
char *p1 = VARDATA(r.lower);
|
|
|
|
char *p2 = VARDATA(r.upper);
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2005-07-01 17:44:56 +04:00
|
|
|
if (ml == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (i < ml)
|
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 14:43:32 +04:00
|
|
|
{
|
2005-07-01 17:44:56 +04:00
|
|
|
if (tinfo->eml > 1 && l == 0)
|
|
|
|
{
|
|
|
|
if ((l = pg_mblen(p1)) != pg_mblen(p2))
|
|
|
|
{
|
|
|
|
return i;
|
2005-10-15 06:49:52 +04:00
|
|
|
}
|
2005-07-01 17:44:56 +04:00
|
|
|
}
|
|
|
|
if (*p1 != *p2)
|
|
|
|
{
|
|
|
|
if (tinfo->eml > 1)
|
|
|
|
{
|
|
|
|
return (i - l + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
2005-10-15 06:49:52 +04:00
|
|
|
}
|
|
|
|
|
2005-07-01 17:44:56 +04:00
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
l--;
|
|
|
|
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 14:43:32 +04:00
|
|
|
}
|
2017-09-18 22:21:23 +03:00
|
|
|
return ml; /* lower == 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 14:43:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-07-01 17:44:56 +04:00
|
|
|
* returns true, if query matches prefix ( common prefix )
|
2011-04-23 04:19:58 +04: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 14:43:32 +04:00
|
|
|
static bool
|
|
|
|
gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)
|
|
|
|
{
|
2017-08-16 07:22:32 +03:00
|
|
|
bool out = false;
|
2005-07-01 17:44:56 +04:00
|
|
|
int32 qlen = VARSIZE(query) - VARHDRSZ;
|
|
|
|
int32 nlen = VARSIZE(pf) - VARHDRSZ;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
if (nlen <= qlen)
|
|
|
|
{
|
2005-07-01 17:44:56 +04:00
|
|
|
char *q = VARDATA(query);
|
|
|
|
char *n = VARDATA(pf);
|
2005-10-15 06:49:52 +04:00
|
|
|
|
2011-04-23 04:19:58 +04:00
|
|
|
out = (memcmp(q, n, nlen) == 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 14:43:32 +04:00
|
|
|
}
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns true, if query matches node using common prefix
|
2011-04-23 04:19:58 +04: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 14:43:32 +04:00
|
|
|
static bool
|
|
|
|
gbt_var_node_pf_match(const GBT_VARKEY_R *node, const bytea *query, const gbtree_vinfo *tinfo)
|
|
|
|
{
|
2005-07-01 17:44:56 +04:00
|
|
|
return (tinfo->trnc &&
|
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 14:43:32 +04:00
|
|
|
(gbt_bytea_pf_match(node->lower, query, tinfo) ||
|
|
|
|
gbt_bytea_pf_match(node->upper, query, tinfo)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* truncates / compresses the node key
|
2005-07-01 17:44:56 +04:00
|
|
|
* cpf_length .. common prefix length
|
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 14:43:32 +04:00
|
|
|
*/
|
|
|
|
static GBT_VARKEY *
|
2005-07-01 17:44:56 +04:00
|
|
|
gbt_var_node_truncate(const GBT_VARKEY *node, int32 cpf_length, const gbtree_vinfo *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 14:43:32 +04:00
|
|
|
{
|
|
|
|
GBT_VARKEY *out = NULL;
|
|
|
|
GBT_VARKEY_R r = gbt_var_key_readable(node);
|
2005-07-01 17:44:56 +04:00
|
|
|
int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
|
|
|
|
int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
|
2007-02-28 02:48:10 +03:00
|
|
|
int32 si;
|
|
|
|
char *out2;
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2005-07-01 17:44:56 +04:00
|
|
|
len1 = Min(len1, (cpf_length + 1));
|
|
|
|
len2 = Min(len2, (cpf_length + 1));
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2007-02-28 02:48:10 +03:00
|
|
|
si = 2 * VARHDRSZ + INTALIGN(len1 + VARHDRSZ) + len2;
|
2014-05-16 23:29:02 +04:00
|
|
|
out = (GBT_VARKEY *) palloc0(si);
|
2007-02-28 02:48:10 +03:00
|
|
|
SET_VARSIZE(out, si);
|
|
|
|
|
|
|
|
memcpy(VARDATA(out), r.lower, len1 + VARHDRSZ);
|
|
|
|
SET_VARSIZE(VARDATA(out), len1 + VARHDRSZ);
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2007-02-28 02:48:10 +03:00
|
|
|
out2 = VARDATA(out) + INTALIGN(len1 + VARHDRSZ);
|
|
|
|
memcpy(out2, r.upper, len2 + VARHDRSZ);
|
|
|
|
SET_VARSIZE(out2, len2 + VARHDRSZ);
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-05-12 04:39:37 +04:00
|
|
|
void
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
|
2017-03-21 16:53:35 +03:00
|
|
|
const gbtree_vinfo *tinfo, 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 14:43:32 +04:00
|
|
|
{
|
|
|
|
GBT_VARKEY_R eo = gbt_var_key_readable(e);
|
2013-02-08 03:22:19 +04:00
|
|
|
GBT_VARKEY_R nr;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
if (eo.lower == eo.upper) /* leaf */
|
|
|
|
{
|
2013-02-08 03:22:19 +04:00
|
|
|
GBT_VARKEY *tmp;
|
|
|
|
|
2017-03-21 16:53:35 +03:00
|
|
|
tmp = gbt_var_leaf2node(e, tinfo, 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 14:43:32 +04:00
|
|
|
if (tmp != e)
|
|
|
|
eo = gbt_var_key_readable(tmp);
|
|
|
|
}
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
if (DatumGetPointer(*u))
|
|
|
|
{
|
|
|
|
GBT_VARKEY_R ro = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(*u));
|
2013-02-08 03:22:19 +04:00
|
|
|
bool update = false;
|
|
|
|
|
|
|
|
nr.lower = ro.lower;
|
|
|
|
nr.upper = ro.upper;
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2017-09-07 19:06:23 +03:00
|
|
|
if (tinfo->f_cmp(ro.lower, eo.lower, collation, flinfo) > 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 14:43:32 +04:00
|
|
|
{
|
|
|
|
nr.lower = eo.lower;
|
2013-02-08 03:22:19 +04:00
|
|
|
update = true;
|
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 14:43:32 +04:00
|
|
|
}
|
2005-05-21 16:08:06 +04:00
|
|
|
|
2017-09-07 19:06:23 +03:00
|
|
|
if (tinfo->f_cmp(ro.upper, eo.upper, collation, flinfo) < 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 14:43:32 +04:00
|
|
|
{
|
|
|
|
nr.upper = eo.upper;
|
2013-02-08 03:22:19 +04:00
|
|
|
update = true;
|
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 14:43:32 +04:00
|
|
|
}
|
2005-05-21 16:08:06 +04:00
|
|
|
|
2013-02-08 03:22:19 +04:00
|
|
|
if (update)
|
2015-03-27 00:10:10 +03:00
|
|
|
*u = PointerGetDatum(gbt_var_key_copy(&nr));
|
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 14:43:32 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nr.lower = eo.lower;
|
|
|
|
nr.upper = eo.upper;
|
2015-03-27 00:10:10 +03:00
|
|
|
*u = PointerGetDatum(gbt_var_key_copy(&nr));
|
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 14:43:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-12 04:39:37 +04:00
|
|
|
GISTENTRY *
|
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 14:43:32 +04:00
|
|
|
gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
|
|
|
|
{
|
|
|
|
GISTENTRY *retval;
|
|
|
|
|
|
|
|
if (entry->leafkey)
|
|
|
|
{
|
2015-03-27 00:10:10 +03:00
|
|
|
struct varlena *leaf = PG_DETOAST_DATUM(entry->key);
|
|
|
|
GBT_VARKEY *r;
|
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 14:43:32 +04:00
|
|
|
|
2015-03-27 00:10:10 +03:00
|
|
|
r = gbt_var_key_from_datum(leaf);
|
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 14:43:32 +04:00
|
|
|
|
|
|
|
retval = palloc(sizeof(GISTENTRY));
|
|
|
|
gistentryinit(*retval, PointerGetDatum(r),
|
|
|
|
entry->rel, entry->page,
|
2017-08-16 07:22:32 +03:00
|
|
|
entry->offset, true);
|
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 14:43:32 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
retval = entry;
|
|
|
|
|
2017-08-17 19:39:20 +03:00
|
|
|
return 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 14:43:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-28 00:35:16 +03:00
|
|
|
Datum
|
|
|
|
gbt_var_fetch(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
2017-09-18 22:21:23 +03:00
|
|
|
GBT_VARKEY *key = (GBT_VARKEY *) PG_DETOAST_DATUM(entry->key);
|
2015-03-28 00:35:16 +03:00
|
|
|
GBT_VARKEY_R r = gbt_var_key_readable(key);
|
|
|
|
GISTENTRY *retval;
|
|
|
|
|
|
|
|
retval = palloc(sizeof(GISTENTRY));
|
|
|
|
gistentryinit(*retval, PointerGetDatum(r.lower),
|
|
|
|
entry->rel, entry->page,
|
2017-08-16 07:22:32 +03:00
|
|
|
entry->offset, true);
|
2015-03-28 00:35:16 +03:00
|
|
|
|
|
|
|
PG_RETURN_POINTER(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-12 04:39:37 +04:00
|
|
|
GBT_VARKEY *
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
|
2017-03-21 16:53:35 +03:00
|
|
|
const gbtree_vinfo *tinfo, 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 14:43:32 +04:00
|
|
|
{
|
|
|
|
int i = 0,
|
|
|
|
numranges = entryvec->n;
|
2005-03-01 18:40:04 +03:00
|
|
|
GBT_VARKEY *cur;
|
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 14:43:32 +04:00
|
|
|
Datum out;
|
|
|
|
GBT_VARKEY_R rk;
|
|
|
|
|
|
|
|
*size = sizeof(GBT_VARKEY);
|
|
|
|
|
2005-03-01 18:40:04 +03:00
|
|
|
cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
|
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 14:43:32 +04:00
|
|
|
rk = gbt_var_key_readable(cur);
|
2015-03-27 00:10:10 +03:00
|
|
|
out = PointerGetDatum(gbt_var_key_copy(&rk));
|
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 14:43:32 +04:00
|
|
|
|
|
|
|
for (i = 1; i < numranges; i++)
|
|
|
|
{
|
2005-03-01 18:40:04 +03:00
|
|
|
cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[i].key);
|
2017-03-21 16:53:35 +03:00
|
|
|
gbt_var_bin_union(&out, cur, collation, tinfo, 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 14:43:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Truncate (=compress) key */
|
|
|
|
if (tinfo->trnc)
|
|
|
|
{
|
|
|
|
int32 plen;
|
|
|
|
GBT_VARKEY *trc = NULL;
|
|
|
|
|
|
|
|
plen = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(out), tinfo);
|
|
|
|
trc = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(out), plen + 1, tinfo);
|
|
|
|
|
|
|
|
out = PointerGetDatum(trc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((GBT_VARKEY *) DatumGetPointer(out));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-12 04:39:37 +04:00
|
|
|
bool
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_same(Datum d1, Datum d2, Oid collation,
|
2017-03-21 16:53:35 +03:00
|
|
|
const gbtree_vinfo *tinfo, 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 14:43:32 +04:00
|
|
|
{
|
2005-03-01 18:40:04 +03:00
|
|
|
GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(d1);
|
|
|
|
GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer(d2);
|
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 14:43:32 +04:00
|
|
|
GBT_VARKEY_R r1,
|
2004-08-29 09:07:03 +04:00
|
|
|
r2;
|
|
|
|
|
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 14:43:32 +04:00
|
|
|
r1 = gbt_var_key_readable(t1);
|
|
|
|
r2 = gbt_var_key_readable(t2);
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2017-09-07 19:06:23 +03:00
|
|
|
return (tinfo->f_cmp(r1.lower, r2.lower, collation, flinfo) == 0 &&
|
|
|
|
tinfo->f_cmp(r1.upper, r2.upper, collation, flinfo) == 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 14:43:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-12 04:39:37 +04:00
|
|
|
float *
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
|
2017-03-21 16:53:35 +03:00
|
|
|
Oid collation, const gbtree_vinfo *tinfo, 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 14:43:32 +04:00
|
|
|
{
|
2005-03-01 18:40:04 +03:00
|
|
|
GBT_VARKEY *orge = (GBT_VARKEY *) DatumGetPointer(o->key);
|
|
|
|
GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
|
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 14:43:32 +04:00
|
|
|
GBT_VARKEY_R ok,
|
|
|
|
nk;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
*res = 0.0;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
nk = gbt_var_key_readable(newe);
|
|
|
|
if (nk.lower == nk.upper) /* leaf */
|
|
|
|
{
|
2013-02-08 04:13:59 +04:00
|
|
|
GBT_VARKEY *tmp;
|
|
|
|
|
2017-03-21 16:53:35 +03:00
|
|
|
tmp = gbt_var_leaf2node(newe, tinfo, 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 14:43:32 +04:00
|
|
|
if (tmp != newe)
|
|
|
|
nk = gbt_var_key_readable(tmp);
|
|
|
|
}
|
|
|
|
ok = gbt_var_key_readable(orge);
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2005-07-01 17:44:56 +04:00
|
|
|
if ((VARSIZE(ok.lower) - VARHDRSZ) == 0 && (VARSIZE(ok.upper) - VARHDRSZ) == 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 14:43:32 +04:00
|
|
|
*res = 0.0;
|
2017-09-07 19:06:23 +03:00
|
|
|
else if (!((tinfo->f_cmp(nk.lower, ok.lower, collation, flinfo) >= 0 ||
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_bytea_pf_match(ok.lower, nk.lower, tinfo)) &&
|
2017-09-07 19:06:23 +03:00
|
|
|
(tinfo->f_cmp(nk.upper, ok.upper, collation, flinfo) <= 0 ||
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_bytea_pf_match(ok.upper, nk.upper, 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 14:43:32 +04:00
|
|
|
{
|
|
|
|
Datum d = PointerGetDatum(0);
|
2013-02-08 04:13:59 +04:00
|
|
|
double dres;
|
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 14:43:32 +04:00
|
|
|
int32 ol,
|
|
|
|
ul;
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2017-03-21 16:53:35 +03:00
|
|
|
gbt_var_bin_union(&d, orge, collation, tinfo, 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 14:43:32 +04:00
|
|
|
ol = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(d), tinfo);
|
2017-03-21 16:53:35 +03:00
|
|
|
gbt_var_bin_union(&d, newe, collation, tinfo, 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 14:43:32 +04:00
|
|
|
ul = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(d), tinfo);
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
if (ul < ol)
|
|
|
|
{
|
2013-02-08 04:13:59 +04:00
|
|
|
dres = (ol - ul); /* reduction of common prefix len */
|
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 14:43:32 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GBT_VARKEY_R uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(d));
|
2013-02-08 04:13:59 +04:00
|
|
|
unsigned char tmp[4];
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2013-02-08 04:13:59 +04:00
|
|
|
tmp[0] = (unsigned char) (((VARSIZE(ok.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.lower)[ul]));
|
|
|
|
tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
|
|
|
|
tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
|
|
|
|
tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
|
2022-10-07 14:28:38 +03:00
|
|
|
dres = abs(tmp[0] - tmp[1]) + abs(tmp[3] - tmp[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 14:43:32 +04:00
|
|
|
dres /= 256.0;
|
|
|
|
}
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
*res += FLT_MIN;
|
|
|
|
*res += (float) (dres / ((double) (ol + 1)));
|
|
|
|
*res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
|
|
|
|
}
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-21 04:09:10 +04:00
|
|
|
static int
|
2006-10-05 21:57:40 +04:00
|
|
|
gbt_vsrt_cmp(const void *a, const void *b, void *arg)
|
2004-08-21 04:09:10 +04:00
|
|
|
{
|
|
|
|
GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
|
|
|
|
GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
|
2011-04-23 04:19:58 +04:00
|
|
|
const gbt_vsrt_arg *varg = (const gbt_vsrt_arg *) arg;
|
2009-12-02 16:13:24 +03:00
|
|
|
int 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 14:43:32 +04:00
|
|
|
|
2017-09-07 19:06:23 +03:00
|
|
|
res = varg->tinfo->f_cmp(ar.lower, br.lower, varg->collation, varg->flinfo);
|
2009-12-02 16:13:24 +03:00
|
|
|
if (res == 0)
|
2017-09-07 19:06:23 +03:00
|
|
|
return varg->tinfo->f_cmp(ar.upper, br.upper, varg->collation, varg->flinfo);
|
2009-12-02 16:13:24 +03:00
|
|
|
|
|
|
|
return res;
|
2004-08-21 04:09:10 +04: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 14:43:32 +04:00
|
|
|
|
2005-05-12 04:39:37 +04:00
|
|
|
GIST_SPLITVEC *
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
|
2017-03-21 16:53:35 +03:00
|
|
|
Oid collation, const gbtree_vinfo *tinfo, 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 14:43:32 +04:00
|
|
|
{
|
2004-08-21 04:09:10 +04:00
|
|
|
OffsetNumber i,
|
|
|
|
maxoff = entryvec->n - 1;
|
|
|
|
Vsrt *arr;
|
2005-03-01 18:40:04 +03:00
|
|
|
int svcntr = 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 14:43:32 +04:00
|
|
|
nbytes;
|
2005-03-01 18:40:04 +03:00
|
|
|
char *cur;
|
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 14:43:32 +04:00
|
|
|
GBT_VARKEY **sv = NULL;
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_vsrt_arg varg;
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2004-08-21 04:09:10 +04:00
|
|
|
arr = (Vsrt *) palloc((maxoff + 1) * sizeof(Vsrt));
|
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 14:43:32 +04:00
|
|
|
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
|
|
|
|
v->spl_left = (OffsetNumber *) palloc(nbytes);
|
|
|
|
v->spl_right = (OffsetNumber *) palloc(nbytes);
|
|
|
|
v->spl_ldatum = PointerGetDatum(0);
|
|
|
|
v->spl_rdatum = PointerGetDatum(0);
|
|
|
|
v->spl_nleft = 0;
|
|
|
|
v->spl_nright = 0;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
sv = palloc(sizeof(bytea *) * (maxoff + 1));
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
/* Sort entries */
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
|
|
|
|
{
|
|
|
|
GBT_VARKEY_R ro;
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2005-03-01 18:40:04 +03:00
|
|
|
cur = (char *) DatumGetPointer(entryvec->vector[i].key);
|
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 14:43:32 +04:00
|
|
|
ro = gbt_var_key_readable((GBT_VARKEY *) cur);
|
|
|
|
if (ro.lower == ro.upper) /* leaf */
|
|
|
|
{
|
2017-03-21 16:53:35 +03:00
|
|
|
sv[svcntr] = gbt_var_leaf2node((GBT_VARKEY *) cur, tinfo, 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 14:43:32 +04:00
|
|
|
arr[i].t = sv[svcntr];
|
|
|
|
if (sv[svcntr] != (GBT_VARKEY *) cur)
|
|
|
|
svcntr++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
arr[i].t = (GBT_VARKEY *) cur;
|
|
|
|
arr[i].i = i;
|
|
|
|
}
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
/* sort */
|
2011-04-23 04:19:58 +04:00
|
|
|
varg.tinfo = tinfo;
|
|
|
|
varg.collation = collation;
|
2017-03-21 16:53:35 +03:00
|
|
|
varg.flinfo = flinfo;
|
2023-02-07 08:53:05 +03:00
|
|
|
qsort_arg(&arr[FirstOffsetNumber],
|
2006-10-05 21:57:40 +04:00
|
|
|
maxoff - FirstOffsetNumber + 1,
|
|
|
|
sizeof(Vsrt),
|
|
|
|
gbt_vsrt_cmp,
|
2023-02-07 08:53:05 +03:00
|
|
|
&varg);
|
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 14:43:32 +04:00
|
|
|
|
|
|
|
/* We do simply create two parts */
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
|
|
|
|
{
|
|
|
|
if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
|
|
|
|
{
|
2017-03-21 16:53:35 +03:00
|
|
|
gbt_var_bin_union(&v->spl_ldatum, arr[i].t, collation, tinfo, 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 14:43:32 +04:00
|
|
|
v->spl_left[v->spl_nleft] = arr[i].i;
|
|
|
|
v->spl_nleft++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-21 16:53:35 +03:00
|
|
|
gbt_var_bin_union(&v->spl_rdatum, arr[i].t, collation, tinfo, 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 14:43:32 +04:00
|
|
|
v->spl_right[v->spl_nright] = arr[i].i;
|
|
|
|
v->spl_nright++;
|
|
|
|
}
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
/* Truncate (=compress) key */
|
|
|
|
if (tinfo->trnc)
|
|
|
|
{
|
|
|
|
int32 ll = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), tinfo);
|
|
|
|
int32 lr = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), tinfo);
|
|
|
|
GBT_VARKEY *dl;
|
|
|
|
GBT_VARKEY *dr;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
ll = Max(ll, lr);
|
|
|
|
ll++;
|
2004-08-29 09:07:03 +04: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 14:43:32 +04:00
|
|
|
dl = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), ll, tinfo);
|
|
|
|
dr = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), ll, tinfo);
|
|
|
|
v->spl_ldatum = PointerGetDatum(dl);
|
|
|
|
v->spl_rdatum = PointerGetDatum(dr);
|
|
|
|
}
|
|
|
|
|
2004-08-21 04:09:10 +04:00
|
|
|
return v;
|
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 14:43:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-08-21 04:09:10 +04:00
|
|
|
* The GiST consistent method
|
|
|
|
*/
|
2005-05-12 04:39:37 +04:00
|
|
|
bool
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_consistent(GBT_VARKEY_R *key,
|
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 14:43:32 +04:00
|
|
|
const void *query,
|
2011-04-23 04:19:58 +04:00
|
|
|
StrategyNumber strategy,
|
|
|
|
Oid collation,
|
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 14:43:32 +04:00
|
|
|
bool is_leaf,
|
2017-03-21 16:53:35 +03:00
|
|
|
const gbtree_vinfo *tinfo,
|
|
|
|
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 14:43:32 +04:00
|
|
|
{
|
2017-08-16 07:22:32 +03:00
|
|
|
bool retval = false;
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2011-04-23 04:19:58 +04:00
|
|
|
switch (strategy)
|
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 14:43:32 +04:00
|
|
|
{
|
|
|
|
case BTLessEqualStrategyNumber:
|
|
|
|
if (is_leaf)
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_ge(query, key->lower, collation, 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 14:43:32 +04:00
|
|
|
else
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 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 14:43:32 +04:00
|
|
|
|| gbt_var_node_pf_match(key, query, tinfo);
|
|
|
|
break;
|
|
|
|
case BTLessStrategyNumber:
|
|
|
|
if (is_leaf)
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_gt(query, key->lower, collation, 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 14:43:32 +04:00
|
|
|
else
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 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 14:43:32 +04:00
|
|
|
|| gbt_var_node_pf_match(key, query, tinfo);
|
|
|
|
break;
|
|
|
|
case BTEqualStrategyNumber:
|
|
|
|
if (is_leaf)
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_eq(query, key->lower, collation, 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 14:43:32 +04:00
|
|
|
else
|
2011-04-23 04:19:58 +04:00
|
|
|
retval =
|
2017-09-07 19:06:23 +03:00
|
|
|
(tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0 &&
|
|
|
|
tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0) ||
|
2011-04-23 04:19:58 +04:00
|
|
|
gbt_var_node_pf_match(key, query, 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 14:43:32 +04:00
|
|
|
break;
|
|
|
|
case BTGreaterStrategyNumber:
|
|
|
|
if (is_leaf)
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_lt(query, key->upper, collation, 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 14:43:32 +04:00
|
|
|
else
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 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 14:43:32 +04:00
|
|
|
|| gbt_var_node_pf_match(key, query, tinfo);
|
|
|
|
break;
|
|
|
|
case BTGreaterEqualStrategyNumber:
|
|
|
|
if (is_leaf)
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_le(query, key->upper, collation, 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 14:43:32 +04:00
|
|
|
else
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 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 14:43:32 +04:00
|
|
|
|| gbt_var_node_pf_match(key, query, tinfo);
|
|
|
|
break;
|
2010-08-02 20:26:48 +04:00
|
|
|
case BtreeGistNotEqualStrategyNumber:
|
2017-09-07 19:06:23 +03:00
|
|
|
retval = !(tinfo->f_eq(query, key->lower, collation, flinfo) &&
|
|
|
|
tinfo->f_eq(query, key->upper, collation, flinfo));
|
2010-08-02 20:26:48 +04:00
|
|
|
break;
|
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 14:43:32 +04:00
|
|
|
default:
|
2017-08-16 07:22:32 +03:00
|
|
|
retval = false;
|
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 14:43:32 +04:00
|
|
|
}
|
2004-08-29 09:07:03 +04:00
|
|
|
|
2011-04-23 04:19:58 +04:00
|
|
|
return 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 14:43:32 +04:00
|
|
|
}
|