From 1ecf6ada76983a7a5333bd8c607dda0ed5e951d3 Mon Sep 17 00:00:00 2001 From: Xiaoran Wang Date: Thu, 5 Oct 2023 12:26:46 +0800 Subject: [PATCH] Include `ItemIdData` when computing the maxSize for the data in a page (#274) As the data is aligned, for hnsw, the combined size won't be in the range (8156 (maxSize exlucding `ItemIdData`), 8160]. So even if the ItemIdData is not included in the maxSize, it works well now, but I think it's better to make it correct. --- src/hnswbuild.c | 2 +- src/hnswinsert.c | 2 +- src/ivfinsert.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 40fdf58..21ad8ce 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -117,7 +117,7 @@ CreateElementPages(HnswBuildState * buildstate) ListCell *lc; /* Calculate sizes */ - maxSize = BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)); + maxSize = BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)) - sizeof(ItemIdData); etupSize = HNSW_ELEMENT_TUPLE_SIZE(dimensions); /* Allocate once */ diff --git a/src/hnswinsert.c b/src/hnswinsert.c index ebdc3f4..996c021 100644 --- a/src/hnswinsert.c +++ b/src/hnswinsert.c @@ -135,7 +135,7 @@ WriteNewElementPages(Relation index, HnswElement e, int m, BlockNumber insertPag etupSize = HNSW_ELEMENT_TUPLE_SIZE(dimensions); ntupSize = HNSW_NEIGHBOR_TUPLE_SIZE(e->level, m); combinedSize = etupSize + ntupSize + sizeof(ItemIdData); - maxSize = BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)); + maxSize = BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)) - sizeof(ItemIdData); minCombinedSize = etupSize + HNSW_NEIGHBOR_TUPLE_SIZE(0, m) + sizeof(ItemIdData); /* Prepare element tuple */ diff --git a/src/ivfinsert.c b/src/ivfinsert.c index f158592..103fe49 100644 --- a/src/ivfinsert.c +++ b/src/ivfinsert.c @@ -99,7 +99,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, R /* Get tuple size */ itemsz = MAXALIGN(IndexTupleSize(itup)); - Assert(itemsz <= BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(IvfflatPageOpaqueData))); + Assert(itemsz <= BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(IvfflatPageOpaqueData)) - sizeof(ItemIdData)); /* Find a page to insert the item */ for (;;)