aboutsummaryrefslogtreecommitdiff
path: root/contrib/btree_gist/btree_time.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist/btree_time.c')
-rw-r--r--contrib/btree_gist/btree_time.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index 79a895159b2..1dba95057ba 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -7,6 +7,7 @@
#include "btree_utils_num.h"
#include "utils/fmgrprotos.h"
#include "utils/date.h"
+#include "utils/sortsupport.h"
#include "utils/timestamp.h"
typedef struct
@@ -26,6 +27,8 @@ PG_FUNCTION_INFO_V1(gbt_time_distance);
PG_FUNCTION_INFO_V1(gbt_timetz_consistent);
PG_FUNCTION_INFO_V1(gbt_time_penalty);
PG_FUNCTION_INFO_V1(gbt_time_same);
+PG_FUNCTION_INFO_V1(gbt_time_sortsupport);
+PG_FUNCTION_INFO_V1(gbt_timetz_sortsupport);
#ifdef USE_FLOAT8_BYVAL
@@ -322,3 +325,26 @@ gbt_time_same(PG_FUNCTION_ARGS)
*result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
PG_RETURN_POINTER(result);
}
+
+static int
+gbt_timekey_ssup_cmp(Datum x, Datum y, SortSupport ssup)
+{
+ timeKEY *arg1 = (timeKEY *) DatumGetPointer(x);
+ timeKEY *arg2 = (timeKEY *) DatumGetPointer(y);
+
+ /* for leaf items we expect lower == upper, so only compare lower */
+ return DatumGetInt32(DirectFunctionCall2(time_cmp,
+ TimeADTGetDatumFast(arg1->lower),
+ TimeADTGetDatumFast(arg2->lower)));
+}
+
+Datum
+gbt_time_sortsupport(PG_FUNCTION_ARGS)
+{
+ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
+
+ ssup->comparator = gbt_timekey_ssup_cmp;
+ ssup->ssup_extra = NULL;
+
+ PG_RETURN_VOID();
+}