Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit e1db3a5

Browse files
authored
Support Postgres 12, 13 and upcoming 16 (#32)
1 parent 9ea43ca commit e1db3a5

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

.github/workflows/build_and_test.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
os: [ ubuntu-22.04, macos-13 ]
19-
postgresql: [ 14, 15 ]
18+
os: [ ubuntu-22.04 ]
19+
postgresql: [ 12, 13, 14, 15, 16 ]
20+
include:
21+
- os: macos-13
22+
postgresql: 15
23+
- os: macos-13
24+
postgresql: 16
2025

2126
runs-on: ${{ matrix.os }}
2227

2328
steps:
2429
- uses: Homebrew/actions/setup-homebrew@master
2530

31+
# TODO: Remove after postgresql@16 is available in homebrew/core
32+
- if: matrix.postgresql == 16
33+
run: brew tap bayandin/tap
34+
2635
- name: brew install postgresql
2736
run: |
2837
brew install ${FORMULA}
@@ -39,4 +48,4 @@ jobs:
3948
- run: make installcheck
4049

4150
- if: failure()
42-
run: cat regression.diffs
51+
run: cat regression.diffs || true

embedding.c

+53-6
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,50 @@ _PG_init(void)
122122
{
123123
hnsw_relopt_kind = add_reloption_kind();
124124
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+
);
126130
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+
);
128136
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+
);
130142
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+
);
132148
hnsw_init_dist_func();
133149
}
134150

135151
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)
138159
{
139160
HnswIndex* hnsw = (HnswIndex*) state;
140161
ArrayType* array;
141162
int n_items;
142163
HnswLabel u;
143164

165+
#if PG_VERSION_NUM < 130000
166+
ItemPointer tid = &hup->t_self;
167+
#endif
168+
144169
/* Skip nulls */
145170
if (isnull[0])
146171
return;
@@ -388,10 +413,24 @@ hnsw_options(Datum reloptions, bool validate)
388413
{"m", RELOPT_TYPE_INT, offsetof(HnswOptions, M)}
389414
};
390415

416+
#if PG_VERSION_NUM >= 130000
391417
return (bytea *) build_reloptions(reloptions, validate,
392418
hnsw_relopt_kind,
393419
sizeof(HnswOptions),
394420
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
395434
}
396435

397436
/*
@@ -476,7 +515,9 @@ hnsw_build(Relation heap, Relation index, IndexInfo *indexInfo)
476515
static bool
477516
hnsw_insert(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid,
478517
Relation heap, IndexUniqueCheck checkUnique,
518+
#if PG_VERSION_NUM >= 140000
479519
bool indexUnchanged,
520+
#endif
480521
IndexInfo *indexInfo)
481522
{
482523
ArrayType* array;
@@ -883,7 +924,9 @@ hnsw_handler(PG_FUNCTION_ARGS)
883924

884925
amroutine->amstrategies = 0;
885926
amroutine->amsupport = 1;
927+
#if PG_VERSION_NUM >= 130000
886928
amroutine->amoptsprocnum = 0;
929+
#endif
887930
amroutine->amcanorder = false;
888931
amroutine->amcanorderbyop = true;
889932
amroutine->amcanbackward = false; /* can change direction mid-scan */
@@ -897,8 +940,10 @@ hnsw_handler(PG_FUNCTION_ARGS)
897940
amroutine->ampredlocks = false;
898941
amroutine->amcanparallel = false;
899942
amroutine->amcaninclude = false;
943+
#if PG_VERSION_NUM >= 130000
900944
amroutine->amusemaintenanceworkmem = false; /* not used during VACUUM */
901945
amroutine->amparallelvacuumoptions = VACUUM_OPTION_PARALLEL_BULKDEL;
946+
#endif
902947
amroutine->amkeytype = InvalidOid;
903948

904949
/* Interface functions */
@@ -913,7 +958,9 @@ hnsw_handler(PG_FUNCTION_ARGS)
913958
amroutine->amproperty = NULL; /* TODO AMPROP_DISTANCE_ORDERABLE */
914959
amroutine->ambuildphasename = NULL;
915960
amroutine->amvalidate = hnsw_validate;
961+
#if PG_VERSION_NUM >= 140000
916962
amroutine->amadjustmembers = NULL;
963+
#endif
917964
amroutine->ambeginscan = hnsw_beginscan;
918965
amroutine->amrescan = hnsw_rescan;
919966
amroutine->amgettuple = hnsw_gettuple;

0 commit comments

Comments
 (0)