33
44#include <stddef.h>
55#include <string.h>
6- #include <access/gin.h>
6+ #include "access/gin.h"
7+ #include "access/reloptions.h"
78
89#include "circle.h"
910#include "polygon.h"
@@ -45,6 +46,7 @@ PG_FUNCTION_INFO_V1(smoc_gin_extract_value_fine);
4546PG_FUNCTION_INFO_V1 (smoc_gin_extract_query );
4647PG_FUNCTION_INFO_V1 (smoc_gin_extract_query_fine );
4748PG_FUNCTION_INFO_V1 (smoc_gin_consistent );
49+ PG_FUNCTION_INFO_V1 (smoc_gin_options );
4850
4951int32 smoc_output_type = 0 ;
5052
@@ -1079,7 +1081,6 @@ smoc_gin_extract_internal(Smoc *moc_a, int32 *nkeys, int gin_order)
10791081if (* nkeys >=nalloc )
10801082{
10811083nalloc *=2 ;
1082- Assert (nalloc < 2000000 );
10831084keys = repalloc (keys ,nalloc * sizeof (Datum ));
10841085}
10851086keys [(* nkeys )++ ]= Int32GetDatum (p );
@@ -1094,8 +1095,9 @@ smoc_gin_extract_value(PG_FUNCTION_ARGS)
10941095{
10951096Smoc * moc_a = (Smoc * )PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
10961097int32 * nkeys = (int32 * )PG_GETARG_POINTER (1 );
1098+ int order = SMOC_GIN_GET_ORDER ();
10971099
1098- PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a ,nkeys ,MOC_GIN_ORDER ));
1100+ PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a ,nkeys ,order ));
10991101}
11001102
11011103Datum
@@ -1114,13 +1116,14 @@ smoc_gin_extract_query(PG_FUNCTION_ARGS)
11141116int32 * nkeys = (int32 * )PG_GETARG_POINTER (1 );
11151117StrategyNumber st = PG_GETARG_UINT16 (2 );
11161118int32 * searchmode = (int32 * )PG_GETARG_POINTER (6 );
1119+ int order = SMOC_GIN_GET_ORDER ();
11171120
11181121if (st == MOC_GIN_STRATEGY_SUBSET || (st == MOC_GIN_STRATEGY_EQUAL && moc_a -> area == 0 ))
11191122* searchmode = GIN_SEARCH_MODE_INCLUDE_EMPTY ;
11201123else if (st == MOC_GIN_STRATEGY_UNEQUAL )
11211124* searchmode = GIN_SEARCH_MODE_ALL ;
11221125
1123- PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a ,nkeys ,MOC_GIN_ORDER ));
1126+ PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a ,nkeys ,order ));
11241127}
11251128
11261129Datum
@@ -1202,3 +1205,21 @@ smoc_gin_consistent(PG_FUNCTION_ARGS)
12021205/* not reached */
12031206PG_RETURN_NULL ();
12041207}
1208+
1209+ #if PG_VERSION_NUM >=130000
1210+ Datum
1211+ smoc_gin_options (PG_FUNCTION_ARGS )
1212+ {
1213+ local_relopts * relopts = (local_relopts * )PG_GETARG_POINTER (0 );
1214+
1215+ init_local_reloptions (relopts ,sizeof (SMocGinOptions ));
1216+ add_local_int_reloption (relopts ,"order" ,
1217+ "smoc order to store in index" ,
1218+ MOC_GIN_ORDER_DEFAULT ,
1219+ 0 ,
1220+ 12 ,/* maximum order fitting into 32bit */
1221+ offsetof(SMocGinOptions ,order ));
1222+
1223+ PG_RETURN_VOID ();
1224+ }
1225+ #endif