summaryrefslogtreecommitdiff
path: root/contrib/btree_gist
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist')
-rw-r--r--contrib/btree_gist/btree_bit.c21
-rw-r--r--contrib/btree_gist/btree_bytea.c7
-rw-r--r--contrib/btree_gist/btree_cash.c10
-rw-r--r--contrib/btree_gist/btree_date.c10
-rw-r--r--contrib/btree_gist/btree_float4.c10
-rw-r--r--contrib/btree_gist/btree_float8.c10
-rw-r--r--contrib/btree_gist/btree_gist.c2
-rw-r--r--contrib/btree_gist/btree_inet.c8
-rw-r--r--contrib/btree_gist/btree_int2.c20
-rw-r--r--contrib/btree_gist/btree_int4.c20
-rw-r--r--contrib/btree_gist/btree_int8.c10
-rw-r--r--contrib/btree_gist/btree_interval.c17
-rw-r--r--contrib/btree_gist/btree_macaddr.c11
-rw-r--r--contrib/btree_gist/btree_numeric.c7
-rw-r--r--contrib/btree_gist/btree_oid.c10
-rw-r--r--contrib/btree_gist/btree_text.c10
-rw-r--r--contrib/btree_gist/btree_time.c12
-rw-r--r--contrib/btree_gist/btree_ts.c15
-rw-r--r--contrib/btree_gist/btree_utils_num.c8
-rw-r--r--contrib/btree_gist/btree_utils_num.h3
-rw-r--r--contrib/btree_gist/btree_utils_var.c67
-rw-r--r--contrib/btree_gist/expected/not_equal.out1
22 files changed, 74 insertions, 215 deletions
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index 5c0d198b09..76297515c5 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -19,14 +19,6 @@ PG_FUNCTION_INFO_V1(gbt_bit_consistent);
PG_FUNCTION_INFO_V1(gbt_bit_penalty);
PG_FUNCTION_INFO_V1(gbt_bit_same);
-Datum gbt_bit_compress(PG_FUNCTION_ARGS);
-Datum gbt_bit_union(PG_FUNCTION_ARGS);
-Datum gbt_bit_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_bit_consistent(PG_FUNCTION_ARGS);
-Datum gbt_bit_penalty(PG_FUNCTION_ARGS);
-Datum gbt_bit_same(PG_FUNCTION_ARGS);
-
-
/* define for comparison */
@@ -83,10 +75,14 @@ static bytea *
gbt_bit_xfrm(bytea *leaf)
{
bytea *out = leaf;
- int s = INTALIGN(VARBITBYTES(leaf) + VARHDRSZ);
-
- out = palloc(s);
- SET_VARSIZE(out, s);
+ int sz = VARBITBYTES(leaf) + VARHDRSZ;
+ int padded_sz = INTALIGN(sz);
+
+ out = (bytea *) palloc(padded_sz);
+ /* initialize the padding bytes to zero */
+ while (sz < padded_sz)
+ ((char *) out)[sz++] = 0;
+ SET_VARSIZE(out, padded_sz);
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
return out;
}
@@ -97,7 +93,6 @@ gbt_bit_xfrm(bytea *leaf)
static GBT_VARKEY *
gbt_bit_l2n(GBT_VARKEY *leaf)
{
-
GBT_VARKEY *out = leaf;
GBT_VARKEY_R r = gbt_var_key_readable(leaf);
bytea *o;
diff --git a/contrib/btree_gist/btree_bytea.c b/contrib/btree_gist/btree_bytea.c
index 0dd441964a..dfc25a45c6 100644
--- a/contrib/btree_gist/btree_bytea.c
+++ b/contrib/btree_gist/btree_bytea.c
@@ -18,13 +18,6 @@ PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
PG_FUNCTION_INFO_V1(gbt_bytea_same);
-Datum gbt_bytea_compress(PG_FUNCTION_ARGS);
-Datum gbt_bytea_union(PG_FUNCTION_ARGS);
-Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_bytea_consistent(PG_FUNCTION_ARGS);
-Datum gbt_bytea_penalty(PG_FUNCTION_ARGS);
-Datum gbt_bytea_same(PG_FUNCTION_ARGS);
-
/* define for comparison */
diff --git a/contrib/btree_gist/btree_cash.c b/contrib/btree_gist/btree_cash.c
index 8e8495ca06..63f86ebeef 100644
--- a/contrib/btree_gist/btree_cash.c
+++ b/contrib/btree_gist/btree_cash.c
@@ -24,14 +24,6 @@ PG_FUNCTION_INFO_V1(gbt_cash_distance);
PG_FUNCTION_INFO_V1(gbt_cash_penalty);
PG_FUNCTION_INFO_V1(gbt_cash_same);
-Datum gbt_cash_compress(PG_FUNCTION_ARGS);
-Datum gbt_cash_union(PG_FUNCTION_ARGS);
-Datum gbt_cash_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_cash_consistent(PG_FUNCTION_ARGS);
-Datum gbt_cash_distance(PG_FUNCTION_ARGS);
-Datum gbt_cash_penalty(PG_FUNCTION_ARGS);
-Datum gbt_cash_same(PG_FUNCTION_ARGS);
-
static bool
gbt_cashgt(const void *a, const void *b)
{
@@ -86,6 +78,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_cash,
sizeof(Cash),
+ 16, /* sizeof(gbtreekey16) */
gbt_cashgt,
gbt_cashge,
gbt_casheq,
@@ -97,7 +90,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(cash_dist);
-Datum cash_dist(PG_FUNCTION_ARGS);
Datum
cash_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_date.c b/contrib/btree_gist/btree_date.c
index 1c0c3ec20c..7a4c6aa600 100644
--- a/contrib/btree_gist/btree_date.c
+++ b/contrib/btree_gist/btree_date.c
@@ -24,14 +24,6 @@ PG_FUNCTION_INFO_V1(gbt_date_distance);
PG_FUNCTION_INFO_V1(gbt_date_penalty);
PG_FUNCTION_INFO_V1(gbt_date_same);
-Datum gbt_date_compress(PG_FUNCTION_ARGS);
-Datum gbt_date_union(PG_FUNCTION_ARGS);
-Datum gbt_date_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_date_consistent(PG_FUNCTION_ARGS);
-Datum gbt_date_distance(PG_FUNCTION_ARGS);
-Datum gbt_date_penalty(PG_FUNCTION_ARGS);
-Datum gbt_date_same(PG_FUNCTION_ARGS);
-
static bool
gbt_dategt(const void *a, const void *b)
{
@@ -104,6 +96,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_date,
sizeof(DateADT),
+ 8, /* sizeof(gbtreekey8) */
gbt_dategt,
gbt_datege,
gbt_dateeq,
@@ -115,7 +108,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(date_dist);
-Datum date_dist(PG_FUNCTION_ARGS);
Datum
date_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_float4.c b/contrib/btree_gist/btree_float4.c
index cf1e45a381..778d8dad84 100644
--- a/contrib/btree_gist/btree_float4.c
+++ b/contrib/btree_gist/btree_float4.c
@@ -23,14 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_float4_distance);
PG_FUNCTION_INFO_V1(gbt_float4_penalty);
PG_FUNCTION_INFO_V1(gbt_float4_same);
-Datum gbt_float4_compress(PG_FUNCTION_ARGS);
-Datum gbt_float4_union(PG_FUNCTION_ARGS);
-Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
-Datum gbt_float4_distance(PG_FUNCTION_ARGS);
-Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
-Datum gbt_float4_same(PG_FUNCTION_ARGS);
-
static bool
gbt_float4gt(const void *a, const void *b)
{
@@ -85,6 +77,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_float4,
sizeof(float4),
+ 8, /* sizeof(gbtreekey8) */
gbt_float4gt,
gbt_float4ge,
gbt_float4eq,
@@ -96,7 +89,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(float4_dist);
-Datum float4_dist(PG_FUNCTION_ARGS);
Datum
float4_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_float8.c b/contrib/btree_gist/btree_float8.c
index 3ce87642cb..c898bf2d97 100644
--- a/contrib/btree_gist/btree_float8.c
+++ b/contrib/btree_gist/btree_float8.c
@@ -23,14 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_float8_distance);
PG_FUNCTION_INFO_V1(gbt_float8_penalty);
PG_FUNCTION_INFO_V1(gbt_float8_same);
-Datum gbt_float8_compress(PG_FUNCTION_ARGS);
-Datum gbt_float8_union(PG_FUNCTION_ARGS);
-Datum gbt_float8_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_float8_consistent(PG_FUNCTION_ARGS);
-Datum gbt_float8_distance(PG_FUNCTION_ARGS);
-Datum gbt_float8_penalty(PG_FUNCTION_ARGS);
-Datum gbt_float8_same(PG_FUNCTION_ARGS);
-
static bool
gbt_float8gt(const void *a, const void *b)
@@ -93,6 +85,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_float8,
sizeof(float8),
+ 16, /* sizeof(gbtreekey16) */
gbt_float8gt,
gbt_float8ge,
gbt_float8eq,
@@ -104,7 +97,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(float8_dist);
-Datum float8_dist(PG_FUNCTION_ARGS);
Datum
float8_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_gist.c b/contrib/btree_gist/btree_gist.c
index f2d2ed2cb2..e1dc253c96 100644
--- a/contrib/btree_gist/btree_gist.c
+++ b/contrib/btree_gist/btree_gist.c
@@ -11,8 +11,6 @@ PG_FUNCTION_INFO_V1(gbt_decompress);
PG_FUNCTION_INFO_V1(gbtreekey_in);
PG_FUNCTION_INFO_V1(gbtreekey_out);
-Datum gbt_decompress(PG_FUNCTION_ARGS);
-
/**************************************************
* In/Out for keys
**************************************************/
diff --git a/contrib/btree_gist/btree_inet.c b/contrib/btree_gist/btree_inet.c
index c136296ab5..822786125d 100644
--- a/contrib/btree_gist/btree_inet.c
+++ b/contrib/btree_gist/btree_inet.c
@@ -25,13 +25,6 @@ PG_FUNCTION_INFO_V1(gbt_inet_consistent);
PG_FUNCTION_INFO_V1(gbt_inet_penalty);
PG_FUNCTION_INFO_V1(gbt_inet_same);
-Datum gbt_inet_compress(PG_FUNCTION_ARGS);
-Datum gbt_inet_union(PG_FUNCTION_ARGS);
-Datum gbt_inet_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_inet_consistent(PG_FUNCTION_ARGS);
-Datum gbt_inet_penalty(PG_FUNCTION_ARGS);
-Datum gbt_inet_same(PG_FUNCTION_ARGS);
-
static bool
gbt_inetgt(const void *a, const void *b)
@@ -81,6 +74,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_inet,
sizeof(double),
+ 16, /* sizeof(gbtreekey16) */
gbt_inetgt,
gbt_inetge,
gbt_ineteq,
diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index a40912b13d..a88aae6453 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -23,14 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_int2_distance);
PG_FUNCTION_INFO_V1(gbt_int2_penalty);
PG_FUNCTION_INFO_V1(gbt_int2_same);
-Datum gbt_int2_compress(PG_FUNCTION_ARGS);
-Datum gbt_int2_union(PG_FUNCTION_ARGS);
-Datum gbt_int2_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_int2_consistent(PG_FUNCTION_ARGS);
-Datum gbt_int2_distance(PG_FUNCTION_ARGS);
-Datum gbt_int2_penalty(PG_FUNCTION_ARGS);
-Datum gbt_int2_same(PG_FUNCTION_ARGS);
-
static bool
gbt_int2gt(const void *a, const void *b)
{
@@ -77,7 +69,7 @@ gbt_int2key_cmp(const void *a, const void *b)
static float8
gbt_int2_dist(const void *a, const void *b)
{
- return GET_FLOAT_DISTANCE(int2, a, b);
+ return GET_FLOAT_DISTANCE(int16, a, b);
}
@@ -85,6 +77,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_int2,
sizeof(int16),
+ 4, /* sizeof(gbtreekey4) */
gbt_int2gt,
gbt_int2ge,
gbt_int2eq,
@@ -96,14 +89,13 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(int2_dist);
-Datum int2_dist(PG_FUNCTION_ARGS);
Datum
int2_dist(PG_FUNCTION_ARGS)
{
- int2 a = PG_GETARG_INT16(0);
- int2 b = PG_GETARG_INT16(1);
- int2 r;
- int2 ra;
+ int16 a = PG_GETARG_INT16(0);
+ int16 b = PG_GETARG_INT16(1);
+ int16 r;
+ int16 ra;
r = a - b;
ra = Abs(r);
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index 426f23f3fe..889a512078 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -23,14 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_int4_distance);
PG_FUNCTION_INFO_V1(gbt_int4_penalty);
PG_FUNCTION_INFO_V1(gbt_int4_same);
-Datum gbt_int4_compress(PG_FUNCTION_ARGS);
-Datum gbt_int4_union(PG_FUNCTION_ARGS);
-Datum gbt_int4_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_int4_consistent(PG_FUNCTION_ARGS);
-Datum gbt_int4_distance(PG_FUNCTION_ARGS);
-Datum gbt_int4_penalty(PG_FUNCTION_ARGS);
-Datum gbt_int4_same(PG_FUNCTION_ARGS);
-
static bool
gbt_int4gt(const void *a, const void *b)
@@ -78,7 +70,7 @@ gbt_int4key_cmp(const void *a, const void *b)
static float8
gbt_int4_dist(const void *a, const void *b)
{
- return GET_FLOAT_DISTANCE(int4, a, b);
+ return GET_FLOAT_DISTANCE(int32, a, b);
}
@@ -86,6 +78,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_int4,
sizeof(int32),
+ 8, /* sizeof(gbtreekey8) */
gbt_int4gt,
gbt_int4ge,
gbt_int4eq,
@@ -97,14 +90,13 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(int4_dist);
-Datum int4_dist(PG_FUNCTION_ARGS);
Datum
int4_dist(PG_FUNCTION_ARGS)
{
- int4 a = PG_GETARG_INT32(0);
- int4 b = PG_GETARG_INT32(1);
- int4 r;
- int4 ra;
+ int32 a = PG_GETARG_INT32(0);
+ int32 b = PG_GETARG_INT32(1);
+ int32 r;
+ int32 ra;
r = a - b;
ra = Abs(r);
diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c
index c05d8687fd..8685cee176 100644
--- a/contrib/btree_gist/btree_int8.c
+++ b/contrib/btree_gist/btree_int8.c
@@ -23,14 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_int8_distance);
PG_FUNCTION_INFO_V1(gbt_int8_penalty);
PG_FUNCTION_INFO_V1(gbt_int8_same);
-Datum gbt_int8_compress(PG_FUNCTION_ARGS);
-Datum gbt_int8_union(PG_FUNCTION_ARGS);
-Datum gbt_int8_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_int8_consistent(PG_FUNCTION_ARGS);
-Datum gbt_int8_distance(PG_FUNCTION_ARGS);
-Datum gbt_int8_penalty(PG_FUNCTION_ARGS);
-Datum gbt_int8_same(PG_FUNCTION_ARGS);
-
static bool
gbt_int8gt(const void *a, const void *b)
@@ -86,6 +78,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_int8,
sizeof(int64),
+ 16, /* sizeof(gbtreekey16) */
gbt_int8gt,
gbt_int8ge,
gbt_int8eq,
@@ -97,7 +90,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(int8_dist);
-Datum int8_dist(PG_FUNCTION_ARGS);
Datum
int8_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c
index bb779adf8e..68d80e8e0a 100644
--- a/contrib/btree_gist/btree_interval.c
+++ b/contrib/btree_gist/btree_interval.c
@@ -26,15 +26,6 @@ PG_FUNCTION_INFO_V1(gbt_intv_distance);
PG_FUNCTION_INFO_V1(gbt_intv_penalty);
PG_FUNCTION_INFO_V1(gbt_intv_same);
-Datum gbt_intv_compress(PG_FUNCTION_ARGS);
-Datum gbt_intv_decompress(PG_FUNCTION_ARGS);
-Datum gbt_intv_union(PG_FUNCTION_ARGS);
-Datum gbt_intv_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_intv_consistent(PG_FUNCTION_ARGS);
-Datum gbt_intv_distance(PG_FUNCTION_ARGS);
-Datum gbt_intv_penalty(PG_FUNCTION_ARGS);
-Datum gbt_intv_same(PG_FUNCTION_ARGS);
-
static bool
gbt_intvgt(const void *a, const void *b)
@@ -95,8 +86,10 @@ gbt_intv_dist(const void *a, const void *b)
/*
* INTERVALSIZE should be the actual size-on-disk of an Interval, as shown
- * in pg_type. This might be less than sizeof(Interval) if the compiler
- * insists on adding alignment padding at the end of the struct.
+ * in pg_type. This might be less than sizeof(Interval) if the compiler
+ * insists on adding alignment padding at the end of the struct. (Note:
+ * this concern is obsolete with the current definition of Interval, but
+ * was real before a separate "day" field was added to it.)
*/
#define INTERVALSIZE 16
@@ -104,6 +97,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_intv,
sizeof(Interval),
+ 32, /* sizeof(gbtreekey32) */
gbt_intvgt,
gbt_intvge,
gbt_intveq,
@@ -129,7 +123,6 @@ abs_interval(Interval *a)
}
PG_FUNCTION_INFO_V1(interval_dist);
-Datum interval_dist(PG_FUNCTION_ARGS);
Datum
interval_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_macaddr.c b/contrib/btree_gist/btree_macaddr.c
index 31125beda6..ed58a1b742 100644
--- a/contrib/btree_gist/btree_macaddr.c
+++ b/contrib/btree_gist/btree_macaddr.c
@@ -12,6 +12,7 @@ typedef struct
{
macaddr lower;
macaddr upper;
+ char pad[4]; /* make struct size = sizeof(gbtreekey16) */
} macKEY;
/*
@@ -24,13 +25,6 @@ PG_FUNCTION_INFO_V1(gbt_macad_consistent);
PG_FUNCTION_INFO_V1(gbt_macad_penalty);
PG_FUNCTION_INFO_V1(gbt_macad_same);
-Datum gbt_macad_compress(PG_FUNCTION_ARGS);
-Datum gbt_macad_union(PG_FUNCTION_ARGS);
-Datum gbt_macad_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_macad_consistent(PG_FUNCTION_ARGS);
-Datum gbt_macad_penalty(PG_FUNCTION_ARGS);
-Datum gbt_macad_same(PG_FUNCTION_ARGS);
-
static bool
gbt_macadgt(const void *a, const void *b)
@@ -81,6 +75,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_macad,
sizeof(macaddr),
+ 16, /* sizeof(gbtreekey16) */
gbt_macadgt,
gbt_macadge,
gbt_macadeq,
@@ -149,7 +144,7 @@ Datum
gbt_macad_union(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(macKEY));
+ void *out = palloc0(sizeof(macKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
diff --git a/contrib/btree_gist/btree_numeric.c b/contrib/btree_gist/btree_numeric.c
index 37938aff6a..02ccca8647 100644
--- a/contrib/btree_gist/btree_numeric.c
+++ b/contrib/btree_gist/btree_numeric.c
@@ -23,13 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_numeric_consistent);
PG_FUNCTION_INFO_V1(gbt_numeric_penalty);
PG_FUNCTION_INFO_V1(gbt_numeric_same);
-Datum gbt_numeric_compress(PG_FUNCTION_ARGS);
-Datum gbt_numeric_union(PG_FUNCTION_ARGS);
-Datum gbt_numeric_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_numeric_consistent(PG_FUNCTION_ARGS);
-Datum gbt_numeric_penalty(PG_FUNCTION_ARGS);
-Datum gbt_numeric_same(PG_FUNCTION_ARGS);
-
/* define for comparison */
diff --git a/contrib/btree_gist/btree_oid.c b/contrib/btree_gist/btree_oid.c
index e80a23c0b1..f6b7bfa05b 100644
--- a/contrib/btree_gist/btree_oid.c
+++ b/contrib/btree_gist/btree_oid.c
@@ -23,14 +23,6 @@ PG_FUNCTION_INFO_V1(gbt_oid_distance);
PG_FUNCTION_INFO_V1(gbt_oid_penalty);
PG_FUNCTION_INFO_V1(gbt_oid_same);
-Datum gbt_oid_compress(PG_FUNCTION_ARGS);
-Datum gbt_oid_union(PG_FUNCTION_ARGS);
-Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
-Datum gbt_oid_distance(PG_FUNCTION_ARGS);
-Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
-Datum gbt_oid_same(PG_FUNCTION_ARGS);
-
static bool
gbt_oidgt(const void *a, const void *b)
@@ -92,6 +84,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_oid,
sizeof(Oid),
+ 8, /* sizeof(gbtreekey8) */
gbt_oidgt,
gbt_oidge,
gbt_oideq,
@@ -103,7 +96,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(oid_dist);
-Datum oid_dist(PG_FUNCTION_ARGS);
Datum
oid_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c
index 277820dc0a..2e00cb60ba 100644
--- a/contrib/btree_gist/btree_text.c
+++ b/contrib/btree_gist/btree_text.c
@@ -19,15 +19,6 @@ PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
PG_FUNCTION_INFO_V1(gbt_text_penalty);
PG_FUNCTION_INFO_V1(gbt_text_same);
-Datum gbt_text_compress(PG_FUNCTION_ARGS);
-Datum gbt_bpchar_compress(PG_FUNCTION_ARGS);
-Datum gbt_text_union(PG_FUNCTION_ARGS);
-Datum gbt_text_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_text_consistent(PG_FUNCTION_ARGS);
-Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS);
-Datum gbt_text_penalty(PG_FUNCTION_ARGS);
-Datum gbt_text_same(PG_FUNCTION_ARGS);
-
/* define for comparison */
@@ -121,7 +112,6 @@ gbt_text_compress(PG_FUNCTION_ARGS)
Datum
gbt_bpchar_compress(PG_FUNCTION_ARGS)
{
-
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval;
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index a148e5e120..cdf81711e7 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -27,16 +27,6 @@ PG_FUNCTION_INFO_V1(gbt_timetz_consistent);
PG_FUNCTION_INFO_V1(gbt_time_penalty);
PG_FUNCTION_INFO_V1(gbt_time_same);
-Datum gbt_time_compress(PG_FUNCTION_ARGS);
-Datum gbt_timetz_compress(PG_FUNCTION_ARGS);
-Datum gbt_time_union(PG_FUNCTION_ARGS);
-Datum gbt_time_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_time_consistent(PG_FUNCTION_ARGS);
-Datum gbt_time_distance(PG_FUNCTION_ARGS);
-Datum gbt_timetz_consistent(PG_FUNCTION_ARGS);
-Datum gbt_time_penalty(PG_FUNCTION_ARGS);
-Datum gbt_time_same(PG_FUNCTION_ARGS);
-
#ifdef USE_FLOAT8_BYVAL
#define TimeADTGetDatumFast(X) TimeADTGetDatum(X)
@@ -134,6 +124,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_time,
sizeof(TimeADT),
+ 16, /* sizeof(gbtreekey16) */
gbt_timegt,
gbt_timege,
gbt_timeeq,
@@ -145,7 +136,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(time_dist);
-Datum time_dist(PG_FUNCTION_ARGS);
Datum
time_dist(PG_FUNCTION_ARGS)
{
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index 05609232d2..a13dcc8bea 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -28,17 +28,6 @@ PG_FUNCTION_INFO_V1(gbt_tstz_distance);
PG_FUNCTION_INFO_V1(gbt_ts_penalty);
PG_FUNCTION_INFO_V1(gbt_ts_same);
-Datum gbt_ts_compress(PG_FUNCTION_ARGS);
-Datum gbt_tstz_compress(PG_FUNCTION_ARGS);
-Datum gbt_ts_union(PG_FUNCTION_ARGS);
-Datum gbt_ts_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_ts_consistent(PG_FUNCTION_ARGS);
-Datum gbt_ts_distance(PG_FUNCTION_ARGS);
-Datum gbt_tstz_consistent(PG_FUNCTION_ARGS);
-Datum gbt_tstz_distance(PG_FUNCTION_ARGS);
-Datum gbt_ts_penalty(PG_FUNCTION_ARGS);
-Datum gbt_ts_same(PG_FUNCTION_ARGS);
-
#ifdef USE_FLOAT8_BYVAL
#define TimestampGetDatumFast(X) TimestampGetDatum(X)
@@ -138,6 +127,7 @@ static const gbtree_ninfo tinfo =
{
gbt_t_ts,
sizeof(Timestamp),
+ 16, /* sizeof(gbtreekey16) */
gbt_tsgt,
gbt_tsge,
gbt_tseq,
@@ -149,7 +139,6 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(ts_dist);
-Datum ts_dist(PG_FUNCTION_ARGS);
Datum
ts_dist(PG_FUNCTION_ARGS)
{
@@ -178,7 +167,6 @@ ts_dist(PG_FUNCTION_ARGS)
}
PG_FUNCTION_INFO_V1(tstz_dist);
-Datum tstz_dist(PG_FUNCTION_ARGS);
Datum
tstz_dist(PG_FUNCTION_ARGS)
{
@@ -382,7 +370,6 @@ gbt_ts_union(PG_FUNCTION_ARGS)
Datum
gbt_ts_penalty(PG_FUNCTION_ARGS)
{
-
tsKEY *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c
index 832dbc500b..505633c98b 100644
--- a/contrib/btree_gist/btree_utils_num.c
+++ b/contrib/btree_gist/btree_utils_num.c
@@ -28,7 +28,7 @@ gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry, const gbtree_ninfo *tinfo)
Cash ch;
} v;
- GBT_NUMKEY *r = (GBT_NUMKEY *) palloc0(2 * tinfo->size);
+ GBT_NUMKEY *r = (GBT_NUMKEY *) palloc0(tinfo->indexsize);
void *leaf = NULL;
switch (tinfo->t)
@@ -77,6 +77,8 @@ gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry, const gbtree_ninfo *tinfo)
leaf = DatumGetPointer(entry->key);
}
+ Assert(tinfo->indexsize >= 2 * tinfo->size);
+
memcpy((void *) &r[0], leaf, tinfo->size);
memcpy((void *) &r[tinfo->size], leaf, tinfo->size);
retval = palloc(sizeof(GISTENTRY));
@@ -137,7 +139,6 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
bool
gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo)
{
-
GBT_NUMKEY_R b1,
b2;
@@ -159,7 +160,6 @@ gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo
void
gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo)
{
-
GBT_NUMKEY_R rd;
rd.lower = &e[0];
@@ -167,7 +167,7 @@ gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo)
if (!DatumGetPointer(*u))
{
- *u = PointerGetDatum(palloc(2 * tinfo->size));
+ *u = PointerGetDatum(palloc0(tinfo->indexsize));
memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]), (void *) rd.lower, tinfo->size);
memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]), (void *) rd.upper, tinfo->size);
}
diff --git a/contrib/btree_gist/btree_utils_num.h b/contrib/btree_gist/btree_utils_num.h
index d7a61d2242..0d79cd2a7f 100644
--- a/contrib/btree_gist/btree_utils_num.h
+++ b/contrib/btree_gist/btree_utils_num.h
@@ -37,7 +37,8 @@ typedef struct
/* Attribs */
enum gbtree_type t; /* data type */
- int32 size; /* size of type , 0 means variable */
+ int32 size; /* size of type, 0 means variable */
+ int32 indexsize; /* size of datums stored in index */
/* Methods */
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index 9f8a132775..b7dd060a94 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -29,7 +29,6 @@ typedef struct
PG_FUNCTION_INFO_V1(gbt_var_decompress);
-Datum gbt_var_decompress(PG_FUNCTION_ARGS);
Datum
@@ -56,7 +55,6 @@ gbt_var_decompress(PG_FUNCTION_ARGS)
GBT_VARKEY_R
gbt_var_key_readable(const GBT_VARKEY *k)
{
-
GBT_VARKEY_R r;
r.lower = (bytea *) &(((char *) k)[VARHDRSZ]);
@@ -72,19 +70,21 @@ GBT_VARKEY *
gbt_var_key_copy(const GBT_VARKEY_R *u, bool force_node)
{
GBT_VARKEY *r = NULL;
+ int32 lowersize = VARSIZE(u->lower);
+ int32 uppersize = VARSIZE(u->upper);
if (u->lower == u->upper && !force_node)
{ /* leaf key mode */
- r = (GBT_VARKEY *) palloc(VARSIZE(u->lower) + VARHDRSZ);
- memcpy(VARDATA(r), u->lower, VARSIZE(u->lower));
- SET_VARSIZE(r, VARSIZE(u->lower) + VARHDRSZ);
+ r = (GBT_VARKEY *) palloc(lowersize + VARHDRSZ);
+ memcpy(VARDATA(r), u->lower, lowersize);
+ SET_VARSIZE(r, lowersize + VARHDRSZ);
}
else
{ /* node key mode */
- r = (GBT_VARKEY *) palloc(INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ);
- memcpy(VARDATA(r), u->lower, VARSIZE(u->lower));
- memcpy(VARDATA(r) + INTALIGN(VARSIZE(u->lower)), u->upper, VARSIZE(u->upper));
- SET_VARSIZE(r, INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ);
+ 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);
}
return r;
}
@@ -108,14 +108,12 @@ gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo)
static int32
gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
{
-
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);
@@ -126,7 +124,6 @@ gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
{
if (tinfo->eml > 1 && l == 0)
{
-
if ((l = pg_mblen(p1)) != pg_mblen(p2))
{
return i;
@@ -206,7 +203,7 @@ gbt_var_node_truncate(const GBT_VARKEY *node, int32 cpf_length, const gbtree_vin
len2 = Min(len2, (cpf_length + 1));
si = 2 * VARHDRSZ + INTALIGN(len1 + VARHDRSZ) + len2;
- out = (GBT_VARKEY *) palloc(si);
+ out = (GBT_VARKEY *) palloc0(si);
SET_VARSIZE(out, si);
memcpy(VARDATA(out), r.lower, len1 + VARHDRSZ);
@@ -225,13 +222,13 @@ void
gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
const gbtree_vinfo *tinfo)
{
- GBT_VARKEY *nk = NULL;
- GBT_VARKEY *tmp = NULL;
- GBT_VARKEY_R nr;
GBT_VARKEY_R eo = gbt_var_key_readable(e);
+ GBT_VARKEY_R nr;
if (eo.lower == eo.upper) /* leaf */
{
+ GBT_VARKEY *tmp;
+
tmp = gbt_var_leaf2node(e, tinfo);
if (tmp != e)
eo = gbt_var_key_readable(tmp);
@@ -239,25 +236,26 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
if (DatumGetPointer(*u))
{
-
GBT_VARKEY_R ro = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(*u));
+ bool update = false;
+
+ nr.lower = ro.lower;
+ nr.upper = ro.upper;
if ((*tinfo->f_cmp) (ro.lower, eo.lower, collation) > 0)
{
nr.lower = eo.lower;
- nr.upper = ro.upper;
- nk = gbt_var_key_copy(&nr, TRUE);
+ update = true;
}
if ((*tinfo->f_cmp) (ro.upper, eo.upper, collation) < 0)
{
nr.upper = eo.upper;
- nr.lower = ro.lower;
- nk = gbt_var_key_copy(&nr, TRUE);
+ update = true;
}
- if (nk)
- *u = PointerGetDatum(nk);
+ if (update)
+ *u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
}
else
{
@@ -272,7 +270,6 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
GISTENTRY *
gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
{
-
GISTENTRY *retval;
if (entry->leafkey)
@@ -301,7 +298,6 @@ GBT_VARKEY *
gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
const gbtree_vinfo *tinfo)
{
-
int i = 0,
numranges = entryvec->n;
GBT_VARKEY *cur;
@@ -368,13 +364,14 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
GBT_VARKEY_R ok,
nk;
- GBT_VARKEY *tmp = NULL;
*res = 0.0;
nk = gbt_var_key_readable(newe);
if (nk.lower == nk.upper) /* leaf */
{
+ GBT_VARKEY *tmp;
+
tmp = gbt_var_leaf2node(newe, tinfo);
if (tmp != newe)
nk = gbt_var_key_readable(tmp);
@@ -389,7 +386,7 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
gbt_bytea_pf_match(ok.upper, nk.upper, tinfo))))
{
Datum d = PointerGetDatum(0);
- double dres = 0.0;
+ double dres;
int32 ol,
ul;
@@ -400,20 +397,18 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
if (ul < ol)
{
- dres = (ol - ul); /* lost of common prefix len */
+ dres = (ol - ul); /* reduction of common prefix len */
}
else
{
GBT_VARKEY_R uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(d));
+ unsigned char tmp[4];
- char tmp[4];
-
- tmp[0] = ((VARSIZE(ok.lower) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(ok.lower)[ul]);
- tmp[1] = ((VARSIZE(uk.lower) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(uk.lower)[ul]);
- tmp[2] = ((VARSIZE(ok.upper) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(ok.upper)[ul]);
- tmp[3] = ((VARSIZE(uk.upper) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(uk.upper)[ul]);
- dres = (tmp[0] - tmp[1]) +
- (tmp[3] - tmp[2]);
+ 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]));
+ dres = Abs(tmp[0] - tmp[1]) + Abs(tmp[3] - tmp[2]);
dres /= 256.0;
}
diff --git a/contrib/btree_gist/expected/not_equal.out b/contrib/btree_gist/expected/not_equal.out
index d9b91e2d56..1d5b55db5a 100644
--- a/contrib/btree_gist/expected/not_equal.out
+++ b/contrib/btree_gist/expected/not_equal.out
@@ -31,7 +31,6 @@ CREATE TABLE zoo (
animal TEXT,
EXCLUDE USING gist (cage WITH =, animal WITH <>)
);
-NOTICE: CREATE TABLE / EXCLUDE will create implicit index "zoo_cage_animal_excl" for table "zoo"
INSERT INTO zoo VALUES(123, 'zebra');
INSERT INTO zoo VALUES(123, 'zebra');
INSERT INTO zoo VALUES(123, 'lion');