aboutsummaryrefslogtreecommitdiff
path: root/contrib/btree_gist/btree_text.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist/btree_text.c')
-rw-r--r--contrib/btree_gist/btree_text.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c
index ed706e3eaa7..ddee42504a1 100644
--- a/contrib/btree_gist/btree_text.c
+++ b/contrib/btree_gist/btree_text.c
@@ -7,6 +7,7 @@
#include "btree_utils_var.h"
#include "mb/pg_wchar.h"
#include "utils/fmgrprotos.h"
+#include "utils/sortsupport.h"
/* GiST support functions */
PG_FUNCTION_INFO_V1(gbt_text_compress);
@@ -17,6 +18,8 @@ PG_FUNCTION_INFO_V1(gbt_text_consistent);
PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
PG_FUNCTION_INFO_V1(gbt_text_penalty);
PG_FUNCTION_INFO_V1(gbt_text_same);
+PG_FUNCTION_INFO_V1(gbt_text_sortsupport);
+PG_FUNCTION_INFO_V1(gbt_bpchar_sortsupport);
/* define for comparison */
@@ -279,3 +282,69 @@ gbt_text_penalty(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
&tinfo, fcinfo->flinfo));
}
+
+static int
+gbt_text_ssup_cmp(Datum x, Datum y, SortSupport ssup)
+{
+ GBT_VARKEY *key1 = PG_DETOAST_DATUM(x);
+ GBT_VARKEY *key2 = PG_DETOAST_DATUM(y);
+
+ GBT_VARKEY_R arg1 = gbt_var_key_readable(key1);
+ GBT_VARKEY_R arg2 = gbt_var_key_readable(key2);
+ Datum result;
+
+ /* for leaf items we expect lower == upper, so only compare lower */
+ result = DirectFunctionCall2Coll(bttextcmp,
+ ssup->ssup_collation,
+ PointerGetDatum(arg1.lower),
+ PointerGetDatum(arg2.lower));
+
+ GBT_FREE_IF_COPY(key1, x);
+ GBT_FREE_IF_COPY(key2, y);
+
+ return DatumGetInt32(result);
+}
+
+Datum
+gbt_text_sortsupport(PG_FUNCTION_ARGS)
+{
+ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
+
+ ssup->comparator = gbt_text_ssup_cmp;
+ ssup->ssup_extra = NULL;
+
+ PG_RETURN_VOID();
+}
+
+static int
+gbt_bpchar_ssup_cmp(Datum x, Datum y, SortSupport ssup)
+{
+ GBT_VARKEY *key1 = PG_DETOAST_DATUM(x);
+ GBT_VARKEY *key2 = PG_DETOAST_DATUM(y);
+
+ GBT_VARKEY_R arg1 = gbt_var_key_readable(key1);
+ GBT_VARKEY_R arg2 = gbt_var_key_readable(key2);
+ Datum result;
+
+ /* for leaf items we expect lower == upper, so only compare lower */
+ result = DirectFunctionCall2Coll(bpcharcmp,
+ ssup->ssup_collation,
+ PointerGetDatum(arg1.lower),
+ PointerGetDatum(arg2.lower));
+
+ GBT_FREE_IF_COPY(key1, x);
+ GBT_FREE_IF_COPY(key2, y);
+
+ return DatumGetInt32(result);
+}
+
+Datum
+gbt_bpchar_sortsupport(PG_FUNCTION_ARGS)
+{
+ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
+
+ ssup->comparator = gbt_bpchar_ssup_cmp;
+ ssup->ssup_extra = NULL;
+
+ PG_RETURN_VOID();
+}