diff --git a/src/hnsw.h b/src/hnsw.h index dd1ba4f..09e90f3 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -60,6 +60,7 @@ #define PROGRESS_HNSW_PHASE_LOAD 2 #define HNSW_MAX_SIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)) - sizeof(ItemIdData)) +#define HNSW_TUPLE_ALLOC_SIZE BLCKSZ #define HNSW_ELEMENT_TUPLE_SIZE(size) MAXALIGN(offsetof(HnswElementTupleData, data) + (size)) #define HNSW_NEIGHBOR_TUPLE_SIZE(level, m) MAXALIGN(offsetof(HnswNeighborTupleData, indextids) + ((level) + 2) * (m) * sizeof(ItemPointerData)) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 18a8258..2e44031 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -148,7 +148,6 @@ CreateGraphPages(HnswBuildState * buildstate) { Relation index = buildstate->index; ForkNumber forkNum = buildstate->forkNum; - Size etupAllocSize; Size maxSize; HnswElementTuple etup; HnswNeighborTuple ntup; @@ -160,12 +159,11 @@ CreateGraphPages(HnswBuildState * buildstate) char *base = buildstate->hnswarea; /* Calculate sizes */ - etupAllocSize = BLCKSZ; maxSize = HNSW_MAX_SIZE; /* Allocate once */ - etup = palloc0(etupAllocSize); - ntup = palloc0(BLCKSZ); + etup = palloc0(HNSW_TUPLE_ALLOC_SIZE); + ntup = palloc0(HNSW_TUPLE_ALLOC_SIZE); /* Prepare first page */ buf = HnswNewBuffer(index, forkNum); @@ -184,7 +182,7 @@ CreateGraphPages(HnswBuildState * buildstate) iter = element->next; /* Zero memory for each element */ - MemSet(etup, 0, etupAllocSize); + MemSet(etup, 0, HNSW_TUPLE_ALLOC_SIZE); /* Calculate sizes */ etupSize = HNSW_ELEMENT_TUPLE_SIZE(VARSIZE_ANY(valuePtr)); @@ -192,7 +190,7 @@ CreateGraphPages(HnswBuildState * buildstate) combinedSize = etupSize + ntupSize + sizeof(ItemIdData); /* Initial size check */ - if (etupSize > etupAllocSize) + if (etupSize > HNSW_TUPLE_ALLOC_SIZE) elog(ERROR, "index tuple too large"); HnswSetElementTuple(base, etup, element); @@ -257,7 +255,7 @@ WriteNeighborTuples(HnswBuildState * buildstate) HnswNeighborTuple ntup; /* Allocate once */ - ntup = palloc0(BLCKSZ); + ntup = palloc0(HNSW_TUPLE_ALLOC_SIZE); while (!HnswPtrIsNull(base, iter)) { diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c index 53b2a18..fb8ec4f 100644 --- a/src/hnswvacuum.c +++ b/src/hnswvacuum.c @@ -571,7 +571,7 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD vacuumstate->bas = GetAccessStrategy(BAS_BULKREAD); vacuumstate->procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC); vacuumstate->collation = index->rd_indcollation[0]; - vacuumstate->ntup = palloc0(BLCKSZ); + vacuumstate->ntup = palloc0(HNSW_TUPLE_ALLOC_SIZE); vacuumstate->tmpCtx = AllocSetContextCreate(CurrentMemoryContext, "Hnsw vacuum temporary context", ALLOCSET_DEFAULT_SIZES);