Skip to content

Commit b738ffe

Browse files
committed
Dropped support for Postgres 12
1 parent 7117513 commit b738ffe

14 files changed

+14
-150
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ jobs:
1313
- postgres: 17
1414
os: ubuntu-24.04
1515
- postgres: 16
16-
os: ubuntu-24.04
16+
os: ubuntu-22.04
1717
- postgres: 15
1818
os: ubuntu-22.04
1919
- postgres: 14
20-
os: ubuntu-22.04
21-
- postgres: 13
2220
os: ubuntu-20.04
23-
- postgres: 12
21+
- postgres: 13
2422
os: ubuntu-20.04
2523
steps:
2624
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.8.0 (unreleased)
22

33
- Reduced memory usage for HNSW index scans
4+
- Dropped support for Postgres 12
45

56
## 0.7.4 (2024-08-05)
67

src/bitutils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "postgres.h"
55

66
/* Check version in first header */
7-
#if PG_VERSION_NUM < 120000
8-
#error "Requires PostgreSQL 12+"
7+
#if PG_VERSION_NUM < 130000
8+
#error "Requires PostgreSQL 13+"
99
#endif
1010

1111
extern uint64 (*BitHammingDistance) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 distance);

src/halfvec.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
#include "utils/numeric.h"
2020
#include "vector.h"
2121

22-
#if PG_VERSION_NUM < 130000
23-
#define TYPALIGN_DOUBLE 'd'
24-
#define TYPALIGN_INT 'i'
25-
#endif
26-
2722
#define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1)
2823
#define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1))
2924

src/hnsw.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,9 @@ HnswInit(void)
6060

6161
hnsw_relopt_kind = add_reloption_kind();
6262
add_int_reloption(hnsw_relopt_kind, "m", "Max number of connections",
63-
HNSW_DEFAULT_M, HNSW_MIN_M, HNSW_MAX_M
64-
#if PG_VERSION_NUM >= 130000
65-
,AccessExclusiveLock
66-
#endif
67-
);
63+
HNSW_DEFAULT_M, HNSW_MIN_M, HNSW_MAX_M, AccessExclusiveLock);
6864
add_int_reloption(hnsw_relopt_kind, "ef_construction", "Size of the dynamic candidate list for construction",
69-
HNSW_DEFAULT_EF_CONSTRUCTION, HNSW_MIN_EF_CONSTRUCTION, HNSW_MAX_EF_CONSTRUCTION
70-
#if PG_VERSION_NUM >= 130000
71-
,AccessExclusiveLock
72-
#endif
73-
);
65+
HNSW_DEFAULT_EF_CONSTRUCTION, HNSW_MIN_EF_CONSTRUCTION, HNSW_MAX_EF_CONSTRUCTION, AccessExclusiveLock);
7466

7567
DefineCustomIntVariable("hnsw.ef_search", "Sets the size of the dynamic candidate list for search",
7668
"Valid range is 1..1000.", &hnsw_ef_search,
@@ -155,23 +147,10 @@ hnswoptions(Datum reloptions, bool validate)
155147
{"ef_construction", RELOPT_TYPE_INT, offsetof(HnswOptions, efConstruction)},
156148
};
157149

158-
#if PG_VERSION_NUM >= 130000
159150
return (bytea *) build_reloptions(reloptions, validate,
160151
hnsw_relopt_kind,
161152
sizeof(HnswOptions),
162153
tab, lengthof(tab));
163-
#else
164-
relopt_value *options;
165-
int numoptions;
166-
HnswOptions *rdopts;
167-
168-
options = parseRelOptions(reloptions, validate, hnsw_relopt_kind, &numoptions);
169-
rdopts = allocateReloptStruct(sizeof(HnswOptions), options, numoptions);
170-
fillRelOptions((void *) rdopts, sizeof(HnswOptions), options, numoptions,
171-
validate, tab, lengthof(tab));
172-
173-
return (bytea *) rdopts;
174-
#endif
175154
}
176155

177156
/*
@@ -196,9 +175,7 @@ hnswhandler(PG_FUNCTION_ARGS)
196175

197176
amroutine->amstrategies = 0;
198177
amroutine->amsupport = 3;
199-
#if PG_VERSION_NUM >= 130000
200178
amroutine->amoptsprocnum = 0;
201-
#endif
202179
amroutine->amcanorder = false;
203180
amroutine->amcanorderbyop = true;
204181
amroutine->amcanbackward = false; /* can change direction mid-scan */
@@ -215,15 +192,11 @@ hnswhandler(PG_FUNCTION_ARGS)
215192
amroutine->amcanbuildparallel = true;
216193
#endif
217194
amroutine->amcaninclude = false;
218-
#if PG_VERSION_NUM >= 130000
219195
amroutine->amusemaintenanceworkmem = false; /* not used during VACUUM */
220-
#endif
221196
#if PG_VERSION_NUM >= 160000
222197
amroutine->amsummarizing = false;
223198
#endif
224-
#if PG_VERSION_NUM >= 130000
225199
amroutine->amparallelvacuumoptions = VACUUM_OPTION_PARALLEL_BULKDEL;
226-
#endif
227200
amroutine->amkeytype = InvalidOid;
228201

229202
/* Interface functions */

src/hnsw.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@
7676
#define SeedRandom(seed) srandom(seed)
7777
#endif
7878

79-
#if PG_VERSION_NUM < 130000
80-
#define list_delete_last(list) list_truncate(list, list_length(list) - 1)
81-
#define list_sort(list, cmp) ((list) = list_qsort(list, cmp))
82-
#endif
83-
8479
#define HnswIsElementTuple(tup) ((tup)->type == HNSW_ELEMENT_TUPLE_TYPE)
8580
#define HnswIsNeighborTuple(tup) ((tup)->type == HNSW_NEIGHBOR_TUPLE_TYPE)
8681

src/hnswbuild.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060
#include "pgstat.h"
6161
#endif
6262

63-
#if PG_VERSION_NUM >= 130000
64-
#define CALLBACK_ITEM_POINTER ItemPointer tid
65-
#else
66-
#define CALLBACK_ITEM_POINTER HeapTuple hup
67-
#endif
68-
6963
#if PG_VERSION_NUM >= 140000
7064
#include "utils/backend_status.h"
7165
#include "utils/wait_event.h"
@@ -75,10 +69,6 @@
7569
#define PARALLEL_KEY_HNSW_AREA UINT64CONST(0xA000000000000002)
7670
#define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xA000000000000003)
7771

78-
#if PG_VERSION_NUM < 130000
79-
#define GENERATIONCHUNK_RAWSIZE (SIZEOF_SIZE_T + SIZEOF_VOID_P * 2)
80-
#endif
81-
8272
/*
8373
* Create the metapage
8474
*/
@@ -585,17 +575,13 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn
585575
* Callback for table_index_build_scan
586576
*/
587577
static void
588-
BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
578+
BuildCallback(Relation index, ItemPointer tid, Datum *values,
589579
bool *isnull, bool tupleIsAlive, void *state)
590580
{
591581
HnswBuildState *buildstate = (HnswBuildState *) state;
592582
HnswGraph *graph = buildstate->graph;
593583
MemoryContext oldCtx;
594584

595-
#if PG_VERSION_NUM < 130000
596-
ItemPointer tid = &hup->t_self;
597-
#endif
598-
599585
/* Skip nulls */
600586
if (isnull[0])
601587
return;
@@ -658,11 +644,7 @@ HnswMemoryContextAlloc(Size size, void *state)
658644
HnswBuildState *buildstate = (HnswBuildState *) state;
659645
void *chunk = MemoryContextAlloc(buildstate->graphCtx, size);
660646

661-
#if PG_VERSION_NUM >= 130000
662647
buildstate->graphData.memoryUsed = MemoryContextMemAllocated(buildstate->graphCtx, false);
663-
#else
664-
buildstate->graphData.memoryUsed += MAXALIGN(size);
665-
#endif
666648

667649
return chunk;
668650
}

src/hnswscan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
160160

161161
so->first = false;
162162

163-
#if defined(HNSW_MEMORY) && PG_VERSION_NUM >= 130000
163+
#if defined(HNSW_MEMORY)
164164
elog(INFO, "memory: %zu MB", MemoryContextMemAllocated(so->tmpCtx, false) / (1024 * 1024));
165165
#endif
166166
}

src/hnswutils.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "access/generic_xlog.h"
66
#include "catalog/pg_type.h"
77
#include "catalog/pg_type_d.h"
8+
#include "common/hashfn.h"
89
#include "fmgr.h"
910
#include "hnsw.h"
1011
#include "lib/pairingheap.h"
@@ -14,12 +15,6 @@
1415
#include "utils/memdebug.h"
1516
#include "utils/rel.h"
1617

17-
#if PG_VERSION_NUM >= 130000
18-
#include "common/hashfn.h"
19-
#else
20-
#include "utils/hashutils.h"
21-
#endif
22-
2318
#if PG_VERSION_NUM < 170000
2419
static inline uint64
2520
murmurhash64(uint64 data)
@@ -701,23 +696,15 @@ AddToVisited(char *base, visited_hash * v, HnswElementPtr elementPtr, Relation i
701696
}
702697
else if (base != NULL)
703698
{
704-
#if PG_VERSION_NUM >= 130000
705699
HnswElement element = HnswPtrAccess(base, elementPtr);
706700

707701
offsethash_insert_hash(v->offsets, HnswPtrOffset(elementPtr), element->hash, found);
708-
#else
709-
offsethash_insert(v->offsets, HnswPtrOffset(elementPtr), found);
710-
#endif
711702
}
712703
else
713704
{
714-
#if PG_VERSION_NUM >= 130000
715705
HnswElement element = HnswPtrAccess(base, elementPtr);
716706

717707
pointerhash_insert_hash(v->pointers, (uintptr_t) HnswPtrPointer(elementPtr), element->hash, found);
718-
#else
719-
pointerhash_insert(v->pointers, (uintptr_t) HnswPtrPointer(elementPtr), found);
720-
#endif
721708
}
722709
}
723710

@@ -948,17 +935,10 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
948935
* Compare candidate distances with pointer tie-breaker
949936
*/
950937
static int
951-
#if PG_VERSION_NUM >= 130000
952938
CompareCandidateDistances(const ListCell *a, const ListCell *b)
953939
{
954940
HnswCandidate *hca = lfirst(a);
955941
HnswCandidate *hcb = lfirst(b);
956-
#else
957-
CompareCandidateDistances(const void *a, const void *b)
958-
{
959-
HnswCandidate *hca = lfirst(*(ListCell **) a);
960-
HnswCandidate *hcb = lfirst(*(ListCell **) b);
961-
#endif
962942

963943
if (hca->distance < hcb->distance)
964944
return 1;
@@ -979,17 +959,10 @@ CompareCandidateDistances(const void *a, const void *b)
979959
* Compare candidate distances with offset tie-breaker
980960
*/
981961
static int
982-
#if PG_VERSION_NUM >= 130000
983962
CompareCandidateDistancesOffset(const ListCell *a, const ListCell *b)
984963
{
985964
HnswCandidate *hca = lfirst(a);
986965
HnswCandidate *hcb = lfirst(b);
987-
#else
988-
CompareCandidateDistancesOffset(const void *a, const void *b)
989-
{
990-
HnswCandidate *hca = lfirst(*(ListCell **) a);
991-
HnswCandidate *hcb = lfirst(*(ListCell **) b);
992-
#endif
993966

994967
if (hca->distance < hcb->distance)
995968
return 1;
@@ -1271,7 +1244,6 @@ RemoveElements(char *base, List *w, HnswElement skipElement)
12711244
return w2;
12721245
}
12731246

1274-
#if PG_VERSION_NUM >= 130000
12751247
/*
12761248
* Precompute hash
12771249
*/
@@ -1287,7 +1259,6 @@ PrecomputeHash(char *base, HnswElement element)
12871259
else
12881260
element->hash = hash_offset(HnswPtrOffset(ptr));
12891261
}
1290-
#endif
12911262

12921263
/*
12931264
* Algorithm 1 from paper
@@ -1302,11 +1273,9 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
13021273
Datum q = HnswGetValue(base, element);
13031274
HnswElement skipElement = existing ? element : NULL;
13041275

1305-
#if PG_VERSION_NUM >= 130000
13061276
/* Precompute hash */
13071277
if (index == NULL)
13081278
PrecomputeHash(base, element);
1309-
#endif
13101279

13111280
/* No neighbors if no entry point */
13121281
if (entryPoint == NULL)

src/ivfbuild.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
#include "pgstat.h"
2727
#endif
2828

29-
#if PG_VERSION_NUM >= 130000
30-
#define CALLBACK_ITEM_POINTER ItemPointer tid
31-
#else
32-
#define CALLBACK_ITEM_POINTER HeapTuple hup
33-
#endif
34-
3529
#if PG_VERSION_NUM >= 140000
3630
#include "utils/backend_status.h"
3731
#include "utils/wait_event.h"
@@ -96,7 +90,7 @@ AddSample(Datum *values, IvfflatBuildState * buildstate)
9690
* Callback for sampling
9791
*/
9892
static void
99-
SampleCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
93+
SampleCallback(Relation index, ItemPointer tid, Datum *values,
10094
bool *isnull, bool tupleIsAlive, void *state)
10195
{
10296
IvfflatBuildState *buildstate = (IvfflatBuildState *) state;
@@ -207,16 +201,12 @@ AddTupleToSort(Relation index, ItemPointer tid, Datum *values, IvfflatBuildState
207201
* Callback for table_index_build_scan
208202
*/
209203
static void
210-
BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
204+
BuildCallback(Relation index, ItemPointer tid, Datum *values,
211205
bool *isnull, bool tupleIsAlive, void *state)
212206
{
213207
IvfflatBuildState *buildstate = (IvfflatBuildState *) state;
214208
MemoryContext oldCtx;
215209

216-
#if PG_VERSION_NUM < 130000
217-
ItemPointer tid = &hup->t_self;
218-
#endif
219-
220210
/* Skip nulls */
221211
if (isnull[0])
222212
return;

0 commit comments

Comments
 (0)