@@ -1020,13 +1020,11 @@ smoc_spoly(PG_FUNCTION_ARGS)
1020
1020
1021
1021
/* GIN index ***********************************/
1022
1022
1023
- Datum
1024
- smoc_gin_extract_value ( PG_FUNCTION_ARGS )
1023
+ static Datum
1024
+ smoc_gin_extract_internal ( Smoc * moc_a , int32 * nkeys , int gin_order )
1025
1025
{
1026
- Smoc * moc_a = (Smoc * ) PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
1027
1026
char * moc_a_base = MOC_BASE (moc_a );
1028
1027
int32 moc_a_end = VARSIZE (moc_a ) - VARHDRSZ ;
1029
- int32 * nkeys = (int32 * ) PG_GETARG_POINTER (1 );
1030
1028
int32 nalloc = 4 ;
1031
1029
Datum * keys = palloc (nalloc * sizeof (Datum ));
1032
1030
@@ -1036,7 +1034,7 @@ smoc_gin_extract_value(PG_FUNCTION_ARGS)
1036
1034
{
1037
1035
moc_interval * x = MOC_INTERVAL (moc_a_base , a );
1038
1036
1039
- int shift = 2 * (HEALPIX_MAX_ORDER - MOC_GIN_ORDER ); // degrade to MOC_GIN_ORDER
1037
+ int shift = 2 * (HEALPIX_MAX_ORDER - gin_order ); // degrade to MOC_GIN_ORDER
1040
1038
int32 first = (x -> first >> shift ); // set low bits to zero
1041
1039
hpint64 low_bits_one = (1L << shift ) - 1 ;
1042
1040
int32 second = ((x -> second + low_bits_one ) >> shift ); // round low bits up
@@ -1060,49 +1058,27 @@ smoc_gin_extract_value(PG_FUNCTION_ARGS)
1060
1058
PG_RETURN_POINTER (keys );
1061
1059
}
1062
1060
1061
+ Datum
1062
+ smoc_gin_extract_value (PG_FUNCTION_ARGS )
1063
+ {
1064
+ Smoc * moc_a = (Smoc * ) PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
1065
+ int32 * nkeys = (int32 * ) PG_GETARG_POINTER (1 );
1066
+
1067
+ PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a , nkeys , MOC_GIN_ORDER ));
1068
+ }
1069
+
1063
1070
Datum
1064
1071
smoc_gin_extract_query (PG_FUNCTION_ARGS )
1065
1072
{
1066
1073
Smoc * moc_a = (Smoc * ) PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
1067
- char * moc_a_base = MOC_BASE (moc_a );
1068
- int32 moc_a_end = VARSIZE (moc_a ) - VARHDRSZ ;
1069
1074
int32 * nkeys = (int32 * ) PG_GETARG_POINTER (1 );
1070
1075
StrategyNumber st = PG_GETARG_UINT16 (2 );
1071
1076
int32 * searchmode = (int32 * ) PG_GETARG_POINTER (6 );
1072
- int32 nalloc = 4 ;
1073
- Datum * keys = palloc (nalloc * sizeof (Datum ));
1074
-
1075
- * nkeys = 0 ;
1076
1077
1077
1078
if (st == MOC_GIN_STRATEGY_SUBSET )
1078
1079
* searchmode = GIN_SEARCH_MODE_INCLUDE_EMPTY ;
1079
1080
1080
- for (int32 a = moc_a -> data_begin ; a < moc_a_end ; a = next_interval (a ))
1081
- {
1082
- moc_interval * x = MOC_INTERVAL (moc_a_base , a );
1083
-
1084
- int shift = 2 * (HEALPIX_MAX_ORDER - MOC_GIN_ORDER ); // degrade to MOC_GIN_ORDER
1085
- int32 first = (x -> first >> shift ); // set low bits to zero
1086
- hpint64 low_bits_one = (1L << shift ) - 1 ;
1087
- int32 second = ((x -> second + low_bits_one ) >> shift ); // round low bits up
1088
- Assert (shift > 32 ); // internal GIN datatype isn't 64 bits
1089
-
1090
- // split interval into individual pixels of order MOC_GIN_ORDER
1091
- for (int32 p = first ; p < second ; p ++ )
1092
- {
1093
- if (* nkeys > 0 && keys [* nkeys - 1 ] == p ) // has (larger) pixel already been added?
1094
- continue ;
1095
- if (* nkeys >= nalloc )
1096
- {
1097
- nalloc *= 2 ;
1098
- Assert (nalloc < 1000000 );
1099
- keys = repalloc (keys , nalloc * sizeof (Datum ));
1100
- }
1101
- keys [(* nkeys )++ ] = Int32GetDatum (p );
1102
- }
1103
- }
1104
-
1105
- PG_RETURN_POINTER (keys );
1081
+ PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a , nkeys , MOC_GIN_ORDER ));
1106
1082
}
1107
1083
1108
1084
Datum
0 commit comments