@@ -122,25 +122,50 @@ _PG_init(void)
122
122
{
123
123
hnsw_relopt_kind = add_reloption_kind ();
124
124
add_int_reloption (hnsw_relopt_kind , "dims" , "Number of dimensions" ,
125
- 0 , 0 , INT_MAX , AccessExclusiveLock );
125
+ 0 , 0 , INT_MAX
126
+ #if PG_VERSION_NUM >= 130000
127
+ , AccessExclusiveLock
128
+ #endif
129
+ );
126
130
add_int_reloption (hnsw_relopt_kind , "m" , "Number of neighbors of each vertex" ,
127
- DEFAULT_M , 0 , INT_MAX , AccessExclusiveLock );
131
+ DEFAULT_M , 0 , INT_MAX
132
+ #if PG_VERSION_NUM >= 130000
133
+ , AccessExclusiveLock
134
+ #endif
135
+ );
128
136
add_int_reloption (hnsw_relopt_kind , "efconstruction" , "Number of inspected neighbors during index construction" ,
129
- DEFAULT_EF_CONSTRUCT , 1 , INT_MAX , AccessExclusiveLock );
137
+ DEFAULT_EF_CONSTRUCT , 1 , INT_MAX
138
+ #if PG_VERSION_NUM >= 130000
139
+ , AccessExclusiveLock
140
+ #endif
141
+ );
130
142
add_int_reloption (hnsw_relopt_kind , "efsearch" , "Number of inspected neighbors during index search" ,
131
- DEFAULT_EF_SEARCH , 1 , INT_MAX , AccessExclusiveLock );
143
+ DEFAULT_EF_SEARCH , 1 , INT_MAX
144
+ #if PG_VERSION_NUM >= 130000
145
+ , AccessExclusiveLock
146
+ #endif
147
+ );
132
148
hnsw_init_dist_func ();
133
149
}
134
150
135
151
static void
136
- hnsw_build_callback (Relation index , ItemPointer tid , Datum * values ,
137
- bool * isnull , bool tupleIsAlive , void * state )
152
+ hnsw_build_callback (Relation index ,
153
+ #if PG_VERSION_NUM >= 130000
154
+ ItemPointer tid ,
155
+ #else
156
+ HeapTuple hup ,
157
+ #endif
158
+ Datum * values , bool * isnull , bool tupleIsAlive , void * state )
138
159
{
139
160
HnswIndex * hnsw = (HnswIndex * ) state ;
140
161
ArrayType * array ;
141
162
int n_items ;
142
163
HnswLabel u ;
143
164
165
+ #if PG_VERSION_NUM < 130000
166
+ ItemPointer tid = & hup -> t_self ;
167
+ #endif
168
+
144
169
/* Skip nulls */
145
170
if (isnull [0 ])
146
171
return ;
@@ -388,10 +413,24 @@ hnsw_options(Datum reloptions, bool validate)
388
413
{"m" , RELOPT_TYPE_INT , offsetof(HnswOptions , M )}
389
414
};
390
415
416
+ #if PG_VERSION_NUM >= 130000
391
417
return (bytea * ) build_reloptions (reloptions , validate ,
392
418
hnsw_relopt_kind ,
393
419
sizeof (HnswOptions ),
394
420
tab , lengthof (tab ));
421
+ #else
422
+ relopt_value * options ;
423
+ HnswOptions * rdopts ;
424
+ int numoptions ;
425
+
426
+ options = parseRelOptions (reloptions , validate , hnsw_relopt_kind , & numoptions );
427
+
428
+ rdopts = allocateReloptStruct (sizeof (HnswOptions ), options , numoptions );
429
+
430
+ fillRelOptions ((void * ) rdopts , sizeof (HnswOptions ), options , numoptions , validate , tab , lengthof (tab ));
431
+
432
+ return (bytea * ) rdopts ;
433
+ #endif
395
434
}
396
435
397
436
/*
@@ -476,7 +515,9 @@ hnsw_build(Relation heap, Relation index, IndexInfo *indexInfo)
476
515
static bool
477
516
hnsw_insert (Relation index , Datum * values , bool * isnull , ItemPointer heap_tid ,
478
517
Relation heap , IndexUniqueCheck checkUnique ,
518
+ #if PG_VERSION_NUM >= 140000
479
519
bool indexUnchanged ,
520
+ #endif
480
521
IndexInfo * indexInfo )
481
522
{
482
523
ArrayType * array ;
@@ -883,7 +924,9 @@ hnsw_handler(PG_FUNCTION_ARGS)
883
924
884
925
amroutine -> amstrategies = 0 ;
885
926
amroutine -> amsupport = 1 ;
927
+ #if PG_VERSION_NUM >= 130000
886
928
amroutine -> amoptsprocnum = 0 ;
929
+ #endif
887
930
amroutine -> amcanorder = false;
888
931
amroutine -> amcanorderbyop = true;
889
932
amroutine -> amcanbackward = false; /* can change direction mid-scan */
@@ -897,8 +940,10 @@ hnsw_handler(PG_FUNCTION_ARGS)
897
940
amroutine -> ampredlocks = false;
898
941
amroutine -> amcanparallel = false;
899
942
amroutine -> amcaninclude = false;
943
+ #if PG_VERSION_NUM >= 130000
900
944
amroutine -> amusemaintenanceworkmem = false; /* not used during VACUUM */
901
945
amroutine -> amparallelvacuumoptions = VACUUM_OPTION_PARALLEL_BULKDEL ;
946
+ #endif
902
947
amroutine -> amkeytype = InvalidOid ;
903
948
904
949
/* Interface functions */
@@ -913,7 +958,9 @@ hnsw_handler(PG_FUNCTION_ARGS)
913
958
amroutine -> amproperty = NULL ; /* TODO AMPROP_DISTANCE_ORDERABLE */
914
959
amroutine -> ambuildphasename = NULL ;
915
960
amroutine -> amvalidate = hnsw_validate ;
961
+ #if PG_VERSION_NUM >= 140000
916
962
amroutine -> amadjustmembers = NULL ;
963
+ #endif
917
964
amroutine -> ambeginscan = hnsw_beginscan ;
918
965
amroutine -> amrescan = hnsw_rescan ;
919
966
amroutine -> amgettuple = hnsw_gettuple ;
0 commit comments