diff options
Diffstat (limited to 'contrib/intarray/_int_gist.c')
-rw-r--r-- | contrib/intarray/_int_gist.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c index 50effc3ca57..fb05b06af9e 100644 --- a/contrib/intarray/_int_gist.c +++ b/contrib/intarray/_int_gist.c @@ -7,6 +7,7 @@ #include "_int.h" #include "access/gist.h" +#include "access/reloptions.h" #include "access/stratnum.h" #define GETENTRY(vec,pos) ((ArrayType *) DatumGetPointer((vec)->vector[(pos)].key)) @@ -32,6 +33,7 @@ PG_FUNCTION_INFO_V1(g_int_penalty); PG_FUNCTION_INFO_V1(g_int_picksplit); PG_FUNCTION_INFO_V1(g_int_union); PG_FUNCTION_INFO_V1(g_int_same); +PG_FUNCTION_INFO_V1(g_int_options); /* @@ -156,6 +158,7 @@ g_int_compress(PG_FUNCTION_ARGS) GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval; ArrayType *r; + int num_ranges = G_INT_GET_NUMRANGES(); int len, lenr; int *dr; @@ -170,9 +173,9 @@ g_int_compress(PG_FUNCTION_ARGS) CHECKARRVALID(r); PREPAREARR(r); - if (ARRNELEMS(r) >= 2 * MAXNUMRANGE) + if (ARRNELEMS(r) >= 2 * num_ranges) elog(NOTICE, "input array is too big (%d maximum allowed, %d current), use gist__intbig_ops opclass instead", - 2 * MAXNUMRANGE - 1, ARRNELEMS(r)); + 2 * num_ranges - 1, ARRNELEMS(r)); retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(r), @@ -195,7 +198,7 @@ g_int_compress(PG_FUNCTION_ARGS) PG_RETURN_POINTER(entry); } - if ((len = ARRNELEMS(r)) >= 2 * MAXNUMRANGE) + if ((len = ARRNELEMS(r)) >= 2 * num_ranges) { /* compress */ if (r == (ArrayType *) DatumGetPointer(entry->key)) r = DatumGetArrayTypePCopy(entry->key); @@ -208,7 +211,7 @@ g_int_compress(PG_FUNCTION_ARGS) * "lenr" is the number of ranges we must eventually remove by * merging, we must be careful to remove no more than this number. */ - lenr = len - MAXNUMRANGE; + lenr = len - num_ranges; /* * Initially assume we can merge consecutive ints into a range. but we @@ -241,7 +244,7 @@ g_int_compress(PG_FUNCTION_ARGS) */ len = 2 * (len - j); cand = 1; - while (len > MAXNUMRANGE * 2) + while (len > num_ranges * 2) { min = PG_INT64_MAX; for (i = 2; i < len; i += 2) @@ -278,6 +281,7 @@ g_int_decompress(PG_FUNCTION_ARGS) GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval; ArrayType *r; + int num_ranges = G_INT_GET_NUMRANGES(); int *dr, lenr; ArrayType *in; @@ -304,7 +308,7 @@ g_int_decompress(PG_FUNCTION_ARGS) lenin = ARRNELEMS(in); - if (lenin < 2 * MAXNUMRANGE) + if (lenin < 2 * num_ranges) { /* not compressed value */ if (in != (ArrayType *) DatumGetPointer(entry->key)) { @@ -604,3 +608,17 @@ g_int_picksplit(PG_FUNCTION_ARGS) PG_RETURN_POINTER(v); } + +Datum +g_int_options(PG_FUNCTION_ARGS) +{ + local_relopts *relopts = (local_relopts *) PG_GETARG_POINTER(0); + + init_local_reloptions(relopts, sizeof(GISTIntArrayOptions)); + add_local_int_reloption(relopts, "numranges", + "number of ranges for compression", + G_INT_NUMRANGES_DEFAULT, 1, G_INT_NUMRANGES_MAX, + offsetof(GISTIntArrayOptions, num_ranges)); + + PG_RETURN_VOID(); +} |