From b738ffecc118078cfbe78baa376e0b4726c137ba Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 19 Sep 2024 18:13:54 -0700 Subject: [PATCH] Dropped support for Postgres 12 --- .github/workflows/build.yml | 6 ++---- CHANGELOG.md | 1 + src/bitutils.h | 4 ++-- src/halfvec.c | 5 ----- src/hnsw.c | 31 ++----------------------------- src/hnsw.h | 5 ----- src/hnswbuild.c | 20 +------------------- src/hnswscan.c | 2 +- src/hnswutils.c | 33 +-------------------------------- src/ivfbuild.c | 14 ++------------ src/ivfflat.c | 25 +------------------------ src/ivfkmeans.c | 4 ---- src/ivfscan.c | 9 +-------- src/vector.c | 5 ----- 14 files changed, 14 insertions(+), 150 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9ec6cb..a4682e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,14 +13,12 @@ jobs: - postgres: 17 os: ubuntu-24.04 - postgres: 16 - os: ubuntu-24.04 + os: ubuntu-22.04 - postgres: 15 os: ubuntu-22.04 - postgres: 14 - os: ubuntu-22.04 - - postgres: 13 os: ubuntu-20.04 - - postgres: 12 + - postgres: 13 os: ubuntu-20.04 steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index e1dbab9..55d4ad8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.8.0 (unreleased) - Reduced memory usage for HNSW index scans +- Dropped support for Postgres 12 ## 0.7.4 (2024-08-05) diff --git a/src/bitutils.h b/src/bitutils.h index b834190..b4d85bb 100644 --- a/src/bitutils.h +++ b/src/bitutils.h @@ -4,8 +4,8 @@ #include "postgres.h" /* Check version in first header */ -#if PG_VERSION_NUM < 120000 -#error "Requires PostgreSQL 12+" +#if PG_VERSION_NUM < 130000 +#error "Requires PostgreSQL 13+" #endif extern uint64 (*BitHammingDistance) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 distance); diff --git a/src/halfvec.c b/src/halfvec.c index 2cb1127..9cd3de6 100644 --- a/src/halfvec.c +++ b/src/halfvec.c @@ -19,11 +19,6 @@ #include "utils/numeric.h" #include "vector.h" -#if PG_VERSION_NUM < 130000 -#define TYPALIGN_DOUBLE 'd' -#define TYPALIGN_INT 'i' -#endif - #define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1) #define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1)) diff --git a/src/hnsw.c b/src/hnsw.c index 9d360ab..a7b1e5f 100644 --- a/src/hnsw.c +++ b/src/hnsw.c @@ -60,17 +60,9 @@ HnswInit(void) hnsw_relopt_kind = add_reloption_kind(); add_int_reloption(hnsw_relopt_kind, "m", "Max number of connections", - HNSW_DEFAULT_M, HNSW_MIN_M, HNSW_MAX_M -#if PG_VERSION_NUM >= 130000 - ,AccessExclusiveLock -#endif - ); + HNSW_DEFAULT_M, HNSW_MIN_M, HNSW_MAX_M, AccessExclusiveLock); add_int_reloption(hnsw_relopt_kind, "ef_construction", "Size of the dynamic candidate list for construction", - HNSW_DEFAULT_EF_CONSTRUCTION, HNSW_MIN_EF_CONSTRUCTION, HNSW_MAX_EF_CONSTRUCTION -#if PG_VERSION_NUM >= 130000 - ,AccessExclusiveLock -#endif - ); + HNSW_DEFAULT_EF_CONSTRUCTION, HNSW_MIN_EF_CONSTRUCTION, HNSW_MAX_EF_CONSTRUCTION, AccessExclusiveLock); DefineCustomIntVariable("hnsw.ef_search", "Sets the size of the dynamic candidate list for search", "Valid range is 1..1000.", &hnsw_ef_search, @@ -155,23 +147,10 @@ hnswoptions(Datum reloptions, bool validate) {"ef_construction", RELOPT_TYPE_INT, offsetof(HnswOptions, efConstruction)}, }; -#if PG_VERSION_NUM >= 130000 return (bytea *) build_reloptions(reloptions, validate, hnsw_relopt_kind, sizeof(HnswOptions), tab, lengthof(tab)); -#else - relopt_value *options; - int numoptions; - HnswOptions *rdopts; - - options = parseRelOptions(reloptions, validate, hnsw_relopt_kind, &numoptions); - rdopts = allocateReloptStruct(sizeof(HnswOptions), options, numoptions); - fillRelOptions((void *) rdopts, sizeof(HnswOptions), options, numoptions, - validate, tab, lengthof(tab)); - - return (bytea *) rdopts; -#endif } /* @@ -196,9 +175,7 @@ hnswhandler(PG_FUNCTION_ARGS) amroutine->amstrategies = 0; amroutine->amsupport = 3; -#if PG_VERSION_NUM >= 130000 amroutine->amoptsprocnum = 0; -#endif amroutine->amcanorder = false; amroutine->amcanorderbyop = true; amroutine->amcanbackward = false; /* can change direction mid-scan */ @@ -215,15 +192,11 @@ hnswhandler(PG_FUNCTION_ARGS) amroutine->amcanbuildparallel = true; #endif amroutine->amcaninclude = false; -#if PG_VERSION_NUM >= 130000 amroutine->amusemaintenanceworkmem = false; /* not used during VACUUM */ -#endif #if PG_VERSION_NUM >= 160000 amroutine->amsummarizing = false; #endif -#if PG_VERSION_NUM >= 130000 amroutine->amparallelvacuumoptions = VACUUM_OPTION_PARALLEL_BULKDEL; -#endif amroutine->amkeytype = InvalidOid; /* Interface functions */ diff --git a/src/hnsw.h b/src/hnsw.h index 5ef4cbd..2f45039 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -76,11 +76,6 @@ #define SeedRandom(seed) srandom(seed) #endif -#if PG_VERSION_NUM < 130000 -#define list_delete_last(list) list_truncate(list, list_length(list) - 1) -#define list_sort(list, cmp) ((list) = list_qsort(list, cmp)) -#endif - #define HnswIsElementTuple(tup) ((tup)->type == HNSW_ELEMENT_TUPLE_TYPE) #define HnswIsNeighborTuple(tup) ((tup)->type == HNSW_NEIGHBOR_TUPLE_TYPE) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 8bd0b4a..498b5d9 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -60,12 +60,6 @@ #include "pgstat.h" #endif -#if PG_VERSION_NUM >= 130000 -#define CALLBACK_ITEM_POINTER ItemPointer tid -#else -#define CALLBACK_ITEM_POINTER HeapTuple hup -#endif - #if PG_VERSION_NUM >= 140000 #include "utils/backend_status.h" #include "utils/wait_event.h" @@ -75,10 +69,6 @@ #define PARALLEL_KEY_HNSW_AREA UINT64CONST(0xA000000000000002) #define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xA000000000000003) -#if PG_VERSION_NUM < 130000 -#define GENERATIONCHUNK_RAWSIZE (SIZEOF_SIZE_T + SIZEOF_VOID_P * 2) -#endif - /* * Create the metapage */ @@ -585,17 +575,13 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn * Callback for table_index_build_scan */ static void -BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values, +BuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state) { HnswBuildState *buildstate = (HnswBuildState *) state; HnswGraph *graph = buildstate->graph; MemoryContext oldCtx; -#if PG_VERSION_NUM < 130000 - ItemPointer tid = &hup->t_self; -#endif - /* Skip nulls */ if (isnull[0]) return; @@ -658,11 +644,7 @@ HnswMemoryContextAlloc(Size size, void *state) HnswBuildState *buildstate = (HnswBuildState *) state; void *chunk = MemoryContextAlloc(buildstate->graphCtx, size); -#if PG_VERSION_NUM >= 130000 buildstate->graphData.memoryUsed = MemoryContextMemAllocated(buildstate->graphCtx, false); -#else - buildstate->graphData.memoryUsed += MAXALIGN(size); -#endif return chunk; } diff --git a/src/hnswscan.c b/src/hnswscan.c index 0efbaa1..0463a89 100644 --- a/src/hnswscan.c +++ b/src/hnswscan.c @@ -160,7 +160,7 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir) so->first = false; -#if defined(HNSW_MEMORY) && PG_VERSION_NUM >= 130000 +#if defined(HNSW_MEMORY) elog(INFO, "memory: %zu MB", MemoryContextMemAllocated(so->tmpCtx, false) / (1024 * 1024)); #endif } diff --git a/src/hnswutils.c b/src/hnswutils.c index 53e3096..fadd90d 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -5,6 +5,7 @@ #include "access/generic_xlog.h" #include "catalog/pg_type.h" #include "catalog/pg_type_d.h" +#include "common/hashfn.h" #include "fmgr.h" #include "hnsw.h" #include "lib/pairingheap.h" @@ -14,12 +15,6 @@ #include "utils/memdebug.h" #include "utils/rel.h" -#if PG_VERSION_NUM >= 130000 -#include "common/hashfn.h" -#else -#include "utils/hashutils.h" -#endif - #if PG_VERSION_NUM < 170000 static inline uint64 murmurhash64(uint64 data) @@ -701,23 +696,15 @@ AddToVisited(char *base, visited_hash * v, HnswElementPtr elementPtr, Relation i } else if (base != NULL) { -#if PG_VERSION_NUM >= 130000 HnswElement element = HnswPtrAccess(base, elementPtr); offsethash_insert_hash(v->offsets, HnswPtrOffset(elementPtr), element->hash, found); -#else - offsethash_insert(v->offsets, HnswPtrOffset(elementPtr), found); -#endif } else { -#if PG_VERSION_NUM >= 130000 HnswElement element = HnswPtrAccess(base, elementPtr); pointerhash_insert_hash(v->pointers, (uintptr_t) HnswPtrPointer(elementPtr), element->hash, found); -#else - pointerhash_insert(v->pointers, (uintptr_t) HnswPtrPointer(elementPtr), found); -#endif } } @@ -948,17 +935,10 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F * Compare candidate distances with pointer tie-breaker */ static int -#if PG_VERSION_NUM >= 130000 CompareCandidateDistances(const ListCell *a, const ListCell *b) { HnswCandidate *hca = lfirst(a); HnswCandidate *hcb = lfirst(b); -#else -CompareCandidateDistances(const void *a, const void *b) -{ - HnswCandidate *hca = lfirst(*(ListCell **) a); - HnswCandidate *hcb = lfirst(*(ListCell **) b); -#endif if (hca->distance < hcb->distance) return 1; @@ -979,17 +959,10 @@ CompareCandidateDistances(const void *a, const void *b) * Compare candidate distances with offset tie-breaker */ static int -#if PG_VERSION_NUM >= 130000 CompareCandidateDistancesOffset(const ListCell *a, const ListCell *b) { HnswCandidate *hca = lfirst(a); HnswCandidate *hcb = lfirst(b); -#else -CompareCandidateDistancesOffset(const void *a, const void *b) -{ - HnswCandidate *hca = lfirst(*(ListCell **) a); - HnswCandidate *hcb = lfirst(*(ListCell **) b); -#endif if (hca->distance < hcb->distance) return 1; @@ -1271,7 +1244,6 @@ RemoveElements(char *base, List *w, HnswElement skipElement) return w2; } -#if PG_VERSION_NUM >= 130000 /* * Precompute hash */ @@ -1287,7 +1259,6 @@ PrecomputeHash(char *base, HnswElement element) else element->hash = hash_offset(HnswPtrOffset(ptr)); } -#endif /* * Algorithm 1 from paper @@ -1302,11 +1273,9 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint Datum q = HnswGetValue(base, element); HnswElement skipElement = existing ? element : NULL; -#if PG_VERSION_NUM >= 130000 /* Precompute hash */ if (index == NULL) PrecomputeHash(base, element); -#endif /* No neighbors if no entry point */ if (entryPoint == NULL) diff --git a/src/ivfbuild.c b/src/ivfbuild.c index 5333588..85a247f 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -26,12 +26,6 @@ #include "pgstat.h" #endif -#if PG_VERSION_NUM >= 130000 -#define CALLBACK_ITEM_POINTER ItemPointer tid -#else -#define CALLBACK_ITEM_POINTER HeapTuple hup -#endif - #if PG_VERSION_NUM >= 140000 #include "utils/backend_status.h" #include "utils/wait_event.h" @@ -96,7 +90,7 @@ AddSample(Datum *values, IvfflatBuildState * buildstate) * Callback for sampling */ static void -SampleCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values, +SampleCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state) { IvfflatBuildState *buildstate = (IvfflatBuildState *) state; @@ -207,16 +201,12 @@ AddTupleToSort(Relation index, ItemPointer tid, Datum *values, IvfflatBuildState * Callback for table_index_build_scan */ static void -BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values, +BuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state) { IvfflatBuildState *buildstate = (IvfflatBuildState *) state; MemoryContext oldCtx; -#if PG_VERSION_NUM < 130000 - ItemPointer tid = &hup->t_self; -#endif - /* Skip nulls */ if (isnull[0]) return; diff --git a/src/ivfflat.c b/src/ivfflat.c index 3bb9082..4e9b9a4 100644 --- a/src/ivfflat.c +++ b/src/ivfflat.c @@ -27,11 +27,7 @@ IvfflatInit(void) { ivfflat_relopt_kind = add_reloption_kind(); add_int_reloption(ivfflat_relopt_kind, "lists", "Number of inverted lists", - IVFFLAT_DEFAULT_LISTS, IVFFLAT_MIN_LISTS, IVFFLAT_MAX_LISTS -#if PG_VERSION_NUM >= 130000 - ,AccessExclusiveLock -#endif - ); + IVFFLAT_DEFAULT_LISTS, IVFFLAT_MIN_LISTS, IVFFLAT_MAX_LISTS, AccessExclusiveLock); DefineCustomIntVariable("ivfflat.probes", "Sets the number of probes", "Valid range is 1..lists.", &ivfflat_probes, @@ -149,23 +145,10 @@ ivfflatoptions(Datum reloptions, bool validate) {"lists", RELOPT_TYPE_INT, offsetof(IvfflatOptions, lists)}, }; -#if PG_VERSION_NUM >= 130000 return (bytea *) build_reloptions(reloptions, validate, ivfflat_relopt_kind, sizeof(IvfflatOptions), tab, lengthof(tab)); -#else - relopt_value *options; - int numoptions; - IvfflatOptions *rdopts; - - options = parseRelOptions(reloptions, validate, ivfflat_relopt_kind, &numoptions); - rdopts = allocateReloptStruct(sizeof(IvfflatOptions), options, numoptions); - fillRelOptions((void *) rdopts, sizeof(IvfflatOptions), options, numoptions, - validate, tab, lengthof(tab)); - - return (bytea *) rdopts; -#endif } /* @@ -190,9 +173,7 @@ ivfflathandler(PG_FUNCTION_ARGS) amroutine->amstrategies = 0; amroutine->amsupport = 5; -#if PG_VERSION_NUM >= 130000 amroutine->amoptsprocnum = 0; -#endif amroutine->amcanorder = false; amroutine->amcanorderbyop = true; amroutine->amcanbackward = false; /* can change direction mid-scan */ @@ -209,15 +190,11 @@ ivfflathandler(PG_FUNCTION_ARGS) amroutine->amcanbuildparallel = true; #endif amroutine->amcaninclude = false; -#if PG_VERSION_NUM >= 130000 amroutine->amusemaintenanceworkmem = false; /* not used during VACUUM */ -#endif #if PG_VERSION_NUM >= 160000 amroutine->amsummarizing = false; #endif -#if PG_VERSION_NUM >= 130000 amroutine->amparallelvacuumoptions = VACUUM_OPTION_PARALLEL_BULKDEL; -#endif amroutine->amkeytype = InvalidOid; /* Interface functions */ diff --git a/src/ivfkmeans.c b/src/ivfkmeans.c index 003d55d..4b6d14f 100644 --- a/src/ivfkmeans.c +++ b/src/ivfkmeans.c @@ -151,12 +151,8 @@ RandomCenters(Relation index, VectorArray centers, const IvfflatTypeInfo * typeI static void ShowMemoryUsage(MemoryContext context, Size estimatedSize) { -#if PG_VERSION_NUM >= 130000 elog(INFO, "total memory: %zu MB", MemoryContextMemAllocated(context, true) / (1024 * 1024)); -#else - MemoryContextStats(context); -#endif elog(INFO, "estimated memory: %zu MB", estimatedSize / (1024 * 1024)); } #endif diff --git a/src/ivfscan.c b/src/ivfscan.c index 78f949e..1e95cd6 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -292,14 +292,7 @@ ivfflatrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque; if (!so->first) - { -#if PG_VERSION_NUM >= 130000 tuplesort_reset(so->sortstate); -#else - tuplesort_end(so->sortstate); - so->sortstate = InitScanSortState(so->tupdesc); -#endif - } so->first = true; pairingheap_reset(so->listQueue); @@ -346,7 +339,7 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir) IvfflatBench("GetScanItems", GetScanItems(scan, value)); so->first = false; -#if defined(IVFFLAT_MEMORY) && PG_VERSION_NUM >= 130000 +#if defined(IVFFLAT_MEMORY) elog(INFO, "memory: %zu MB", MemoryContextMemAllocated(CurrentMemoryContext, true) / (1024 * 1024)); #endif diff --git a/src/vector.c b/src/vector.c index a0e2c3f..facc07e 100644 --- a/src/vector.c +++ b/src/vector.c @@ -26,11 +26,6 @@ #include "varatt.h" #endif -#if PG_VERSION_NUM < 130000 -#define TYPALIGN_DOUBLE 'd' -#define TYPALIGN_INT 'i' -#endif - #define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1) #define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1))