Commit bb850306 authored by Tom Lane's avatar Tom Lane

Fix contrib/btree_gist to handle collations properly.

Make use of the collation attached to the index column, instead of
hard-wiring DEFAULT_COLLATION_OID.  (Note: in theory this could require
reindexing btree_gist indexes on textual columns, but I rather doubt anyone
has one with a non-default declared collation as yet.)
parent ae20bf17
......@@ -29,40 +29,51 @@ Datum gbt_bit_same(PG_FUNCTION_ARGS);
/* define for comparison */
static bool
gbt_bitgt(const void *a, const void *b)
gbt_bitgt(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(bitgt, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(bitgt,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_bitge(const void *a, const void *b)
gbt_bitge(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(bitge, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(bitge,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_biteq(const void *a, const void *b)
gbt_biteq(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(biteq, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(biteq,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_bitle(const void *a, const void *b)
gbt_bitle(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(bitle, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(bitle,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_bitlt(const void *a, const void *b)
gbt_bitlt(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(bitlt, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(bitlt,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static int32
gbt_bitcmp(const bytea *a, const bytea *b)
gbt_bitcmp(const void *a, const void *b, Oid collation)
{
return
(DatumGetInt32(DirectFunctionCall2(byteacmp, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetInt32(DirectFunctionCall2(byteacmp,
PointerGetDatum(a),
PointerGetDatum(b)));
}
......@@ -134,7 +145,7 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval = FALSE;
bool retval;
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY_R r = gbt_var_key_readable(key);
......@@ -142,12 +153,14 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
*recheck = false;
if (GIST_LEAF(entry))
retval = gbt_var_consistent(&r, query, &strategy, TRUE, &tinfo);
retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
TRUE, &tinfo);
else
{
bytea *q = gbt_bit_xfrm((bytea *) query);
retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
retval = gbt_var_consistent(&r, q, strategy, PG_GET_COLLATION(),
FALSE, &tinfo);
}
PG_RETURN_BOOL(retval);
}
......@@ -160,7 +173,8 @@ gbt_bit_union(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
&tinfo));
}
......@@ -170,7 +184,8 @@ gbt_bit_picksplit(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit(entryvec, v, &tinfo);
gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
&tinfo);
PG_RETURN_POINTER(v);
}
......@@ -181,7 +196,8 @@ gbt_bit_same(PG_FUNCTION_ARGS)
Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
*result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
PG_RETURN_POINTER(result);
}
......@@ -192,5 +208,6 @@ gbt_bit_penalty(PG_FUNCTION_ARGS)
GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
float *result = (float *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
&tinfo));
}
......@@ -27,41 +27,51 @@ Datum gbt_bytea_same(PG_FUNCTION_ARGS);
/* define for comparison */
static bool
gbt_byteagt(const void *a, const void *b)
gbt_byteagt(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(byteagt, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(byteagt,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_byteage(const void *a, const void *b)
gbt_byteage(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(byteage, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(byteage,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_byteaeq(const void *a, const void *b)
gbt_byteaeq(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(byteaeq, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(byteaeq,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_byteale(const void *a, const void *b)
gbt_byteale(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(byteale, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(byteale,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_bytealt(const void *a, const void *b)
gbt_bytealt(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(bytealt, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(bytealt,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static int32
gbt_byteacmp(const bytea *a, const bytea *b)
gbt_byteacmp(const void *a, const void *b, Oid collation)
{
return
(DatumGetInt32(DirectFunctionCall2(byteacmp, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetInt32(DirectFunctionCall2(byteacmp,
PointerGetDatum(a),
PointerGetDatum(b)));
}
......@@ -111,7 +121,8 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS)
/* All cases served by this function are exact */
*recheck = false;
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
GIST_LEAF(entry), &tinfo);
PG_RETURN_BOOL(retval);
}
......@@ -123,7 +134,8 @@ gbt_bytea_union(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
&tinfo));
}
......@@ -133,7 +145,8 @@ gbt_bytea_picksplit(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit(entryvec, v, &tinfo);
gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
&tinfo);
PG_RETURN_POINTER(v);
}
......@@ -144,7 +157,8 @@ gbt_bytea_same(PG_FUNCTION_ARGS)
Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
*result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
PG_RETURN_POINTER(result);
}
......@@ -155,5 +169,6 @@ gbt_bytea_penalty(PG_FUNCTION_ARGS)
GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
float *result = (float *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
&tinfo));
}
......@@ -32,41 +32,51 @@ Datum gbt_numeric_same(PG_FUNCTION_ARGS);
/* define for comparison */
static bool
gbt_numeric_gt(const void *a, const void *b)
gbt_numeric_gt(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(numeric_gt, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(numeric_gt,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_numeric_ge(const void *a, const void *b)
gbt_numeric_ge(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(numeric_ge, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(numeric_ge,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_numeric_eq(const void *a, const void *b)
gbt_numeric_eq(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(numeric_eq, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(numeric_eq,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_numeric_le(const void *a, const void *b)
gbt_numeric_le(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(numeric_le, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(numeric_le,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_numeric_lt(const void *a, const void *b)
gbt_numeric_lt(const void *a, const void *b, Oid collation)
{
return (DatumGetBool(DirectFunctionCall2(numeric_lt, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetBool(DirectFunctionCall2(numeric_lt,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static int32
gbt_numeric_cmp(const bytea *a, const bytea *b)
gbt_numeric_cmp(const void *a, const void *b, Oid collation)
{
return
(DatumGetInt32(DirectFunctionCall2(numeric_cmp, PointerGetDatum(a), PointerGetDatum(b))));
return DatumGetInt32(DirectFunctionCall2(numeric_cmp,
PointerGetDatum(a),
PointerGetDatum(b)));
}
......@@ -116,7 +126,8 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS)
/* All cases served by this function are exact */
*recheck = false;
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
GIST_LEAF(entry), &tinfo);
PG_RETURN_BOOL(retval);
}
......@@ -128,7 +139,8 @@ gbt_numeric_union(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
&tinfo));
}
......@@ -139,7 +151,8 @@ gbt_numeric_same(PG_FUNCTION_ARGS)
Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
*result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
PG_RETURN_POINTER(result);
}
......@@ -163,7 +176,7 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
rk = gbt_var_key_readable(org);
uni = PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
gbt_var_bin_union(&uni, newe, &tinfo);
gbt_var_bin_union(&uni, newe, PG_GET_COLLATION(), &tinfo);
ok = gbt_var_key_readable(org);
uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(uni));
......@@ -224,6 +237,7 @@ gbt_numeric_picksplit(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit(entryvec, v, &tinfo);
gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
&tinfo);
PG_RETURN_POINTER(v);
}
......@@ -3,7 +3,6 @@
*/
#include "btree_gist.h"
#include "btree_utils_var.h"
#include "catalog/pg_collation.h"
#include "utils/builtins.h"
/*
......@@ -31,55 +30,55 @@ Datum gbt_text_same(PG_FUNCTION_ARGS);
/* define for comparison */
static bool
gbt_textgt(const void *a, const void *b)
gbt_textgt(const void *a, const void *b, Oid collation)
{
return DatumGetBool(DirectFunctionCall2Coll(text_gt,
DEFAULT_COLLATION_OID,
collation,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_textge(const void *a, const void *b)
gbt_textge(const void *a, const void *b, Oid collation)
{
return DatumGetBool(DirectFunctionCall2Coll(text_ge,
DEFAULT_COLLATION_OID,
collation,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_texteq(const void *a, const void *b)
gbt_texteq(const void *a, const void *b, Oid collation)
{
return DatumGetBool(DirectFunctionCall2Coll(texteq,
DEFAULT_COLLATION_OID,
collation,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_textle(const void *a, const void *b)
gbt_textle(const void *a, const void *b, Oid collation)
{
return DatumGetBool(DirectFunctionCall2Coll(text_le,
DEFAULT_COLLATION_OID,
collation,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static bool
gbt_textlt(const void *a, const void *b)
gbt_textlt(const void *a, const void *b, Oid collation)
{
return DatumGetBool(DirectFunctionCall2Coll(text_lt,
DEFAULT_COLLATION_OID,
collation,
PointerGetDatum(a),
PointerGetDatum(b)));
}
static int32
gbt_textcmp(const bytea *a, const bytea *b)
gbt_textcmp(const void *a, const void *b, Oid collation)
{
return DatumGetInt32(DirectFunctionCall2Coll(bttextcmp,
DEFAULT_COLLATION_OID,
collation,
PointerGetDatum(a),
PointerGetDatum(b)));
}
......@@ -169,7 +168,8 @@ gbt_text_consistent(PG_FUNCTION_ARGS)
tinfo.eml = pg_database_encoding_max_length();
}
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
GIST_LEAF(entry), &tinfo);
PG_RETURN_BOOL(retval);
}
......@@ -197,7 +197,8 @@ gbt_bpchar_consistent(PG_FUNCTION_ARGS)
tinfo.eml = pg_database_encoding_max_length();
}
retval = gbt_var_consistent(&r, trim, &strategy, GIST_LEAF(entry), &tinfo);
retval = gbt_var_consistent(&r, trim, strategy, PG_GET_COLLATION(),
GIST_LEAF(entry), &tinfo);
PG_RETURN_BOOL(retval);
}
......@@ -208,7 +209,8 @@ gbt_text_union(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
&tinfo));
}
......@@ -218,7 +220,8 @@ gbt_text_picksplit(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit(entryvec, v, &tinfo);
gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
&tinfo);
PG_RETURN_POINTER(v);
}
......@@ -229,7 +232,8 @@ gbt_text_same(PG_FUNCTION_ARGS)
Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
*result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
PG_RETURN_POINTER(result);
}
......@@ -240,5 +244,6 @@ gbt_text_penalty(PG_FUNCTION_ARGS)
GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
float *result = (float *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
&tinfo));
}
......@@ -184,9 +184,11 @@ gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo)
/*
** The GiST consistent method
*/
* The GiST consistent method
*
* Note: we currently assume that no datatypes that use this routine are
* collation-aware; so we don't bother passing collation through.
*/
bool
gbt_num_consistent(const GBT_NUMKEY_R *key,
const void *query,
......
This diff is collapsed.
......@@ -18,18 +18,9 @@ typedef struct
*upper;
} GBT_VARKEY_R;
/* used for key sorting */
typedef struct
{
int i;
GBT_VARKEY *t;
} Vsrt;
/*
type description
*/
* type description
*/
typedef struct
{
......@@ -42,12 +33,12 @@ typedef struct
/* Methods */
bool (*f_gt) (const void *, const void *); /* greater then */
bool (*f_ge) (const void *, const void *); /* greater equal */
bool (*f_eq) (const void *, const void *); /* equal */
bool (*f_le) (const void *, const void *); /* less equal */
bool (*f_lt) (const void *, const void *); /* less then */
int32 (*f_cmp) (const bytea *, const bytea *); /* node compare */
bool (*f_gt) (const void *, const void *, Oid); /* greater than */
bool (*f_ge) (const void *, const void *, Oid); /* greater equal */
bool (*f_eq) (const void *, const void *, Oid); /* equal */
bool (*f_le) (const void *, const void *, Oid); /* less equal */
bool (*f_lt) (const void *, const void *, Oid); /* less than */
int32 (*f_cmp) (const void *, const void *, Oid); /* compare */
GBT_VARKEY *(*f_l2n) (GBT_VARKEY *); /* convert leaf to node */
} gbtree_vinfo;
......@@ -60,21 +51,22 @@ extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R *u, bool force_node);
extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo);
extern GBT_VARKEY *gbt_var_union(const GistEntryVector *entryvec, int32 *size,
const gbtree_vinfo *tinfo);
Oid collation, const gbtree_vinfo *tinfo);
extern bool gbt_var_same(bool *result, const Datum d1, const Datum d2,
extern bool gbt_var_same(Datum d1, Datum d2, Oid collation,
const gbtree_vinfo *tinfo);
extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
const gbtree_vinfo *tinfo);
Oid collation, const gbtree_vinfo *tinfo);
extern bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query,
const StrategyNumber *strategy, bool is_leaf,
StrategyNumber strategy, Oid collation, bool is_leaf,
const gbtree_vinfo *tinfo);
extern GIST_SPLITVEC *gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
const gbtree_vinfo *tinfo);
extern void gbt_var_bin_union(Datum *u, GBT_VARKEY *e,
Oid collation, const gbtree_vinfo *tinfo);
extern void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
const gbtree_vinfo *tinfo);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment