diff --git a/src/ivfbuild.c b/src/ivfbuild.c index 15ba9aa..e4fbfc8 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -506,11 +506,9 @@ CreateListPages(Relation index, VectorArray centers, int dimensions, Buffer buf; Page page; GenericXLogState *state; - Size listSize; IvfflatList list; - listSize = MAXALIGN(IVFFLAT_LIST_SIZE(dimensions)); - list = palloc(listSize); + list = palloc0(BLCKSZ); buf = IvfflatNewBuffer(index, forkNum); IvfflatInitRegisterPage(index, &buf, &page, &state); @@ -518,11 +516,13 @@ CreateListPages(Relation index, VectorArray centers, int dimensions, for (int i = 0; i < lists; i++) { OffsetNumber offno; + Datum center = PointerGetDatum(VectorArrayGet(centers, i)); + Size listSize = MAXALIGN(IVFFLAT_LIST_SIZE(center)); /* Load list */ list->startPage = InvalidBlockNumber; list->insertPage = InvalidBlockNumber; - memcpy(&list->center, VectorArrayGet(centers, i), VECTOR_SIZE(dimensions)); + memcpy(&list->center, DatumGetPointer(center), VARSIZE_ANY(center)); /* Ensure free space */ if (PageGetFreeSpace(page) < listSize) diff --git a/src/ivfflat.h b/src/ivfflat.h index 1b6511e..3daab57 100644 --- a/src/ivfflat.h +++ b/src/ivfflat.h @@ -52,7 +52,7 @@ #define PROGRESS_IVFFLAT_PHASE_ASSIGN 3 #define PROGRESS_IVFFLAT_PHASE_LOAD 4 -#define IVFFLAT_LIST_SIZE(_dim) (offsetof(IvfflatListData, center) + VECTOR_SIZE(_dim)) +#define IVFFLAT_LIST_SIZE(_datum) (offsetof(IvfflatListData, center) + VARSIZE_ANY(_datum)) #define IvfflatPageGetOpaque(page) ((IvfflatPageOpaque) PageGetSpecialPointer(page)) #define IvfflatPageGetMeta(page) ((IvfflatMetaPageData *) PageGetContents(page)) @@ -229,7 +229,7 @@ typedef struct IvfflatListData { BlockNumber startPage; BlockNumber insertPage; - Vector center; + char center[FLEXIBLE_ARRAY_MEMBER]; } IvfflatListData; typedef IvfflatListData * IvfflatList;