1
0
mirror of https://github.com/pgvector/pgvector.git synced 2026-10-23 10:48:54 +03:00

Added useFsm flag [skip ci]

This commit is contained in:
Andrew Kane
2026-10-06 12:55:51 -07:00
parent 4da0270d86
commit 6aaaec0eef
4 changed files with 26 additions and 10 deletions

View File

@@ -294,6 +294,7 @@ typedef struct HnswTypeInfo
Datum (*dimensions) (PG_FUNCTION_ARGS);
Datum (*normalize) (PG_FUNCTION_ARGS);
void (*checkValue) (Pointer v);
bool useFsm;
} HnswTypeInfo;
typedef struct HnswSupport

View File

@@ -163,7 +163,8 @@ AddElementOnDisk(Relation index, HnswElement e, int m, BlockNumber insertPage, B
BlockNumber newInsertPage = InvalidBlockNumber;
uint8 tupleVersion;
char *base = NULL;
bool tryFsm = !building;
bool useFsm = !building && HnswGetTypeInfo(index)->useFsm;
bool tryFsm = useFsm;
int fsmTries = 0;
/* Calculate sizes */
@@ -346,7 +347,7 @@ AddElementOnDisk(Relation index, HnswElement e, int m, BlockNumber insertPage, B
}
/* Update free space map */
if (!building)
if (useFsm)
HnswRecordPageWithFreeSpace(index, e->blkno, page);
/* Commit */

View File

@@ -1440,7 +1440,8 @@ HnswGetTypeInfo(Relation index)
.maxDimensions = HNSW_MAX_DIM,
.dimensions = vector_dims,
.normalize = l2_normalize,
.checkValue = NULL
.checkValue = NULL,
.useFsm = false
};
return (&typeInfo);
@@ -1457,7 +1458,8 @@ hnsw_halfvec_support(PG_FUNCTION_ARGS)
.maxDimensions = HNSW_MAX_DIM * 2,
.dimensions = halfvec_vector_dims,
.normalize = halfvec_l2_normalize,
.checkValue = NULL
.checkValue = NULL,
.useFsm = false
};
PG_RETURN_POINTER(&typeInfo);
@@ -1471,7 +1473,8 @@ hnsw_bit_support(PG_FUNCTION_ARGS)
.maxDimensions = HNSW_MAX_DIM * 32,
.dimensions = bitlength,
.normalize = NULL,
.checkValue = NULL
.checkValue = NULL,
.useFsm = false
};
PG_RETURN_POINTER(&typeInfo);
@@ -1485,7 +1488,8 @@ hnsw_sparsevec_support(PG_FUNCTION_ARGS)
.maxDimensions = SPARSEVEC_MAX_DIM,
.dimensions = sparsevec_vector_dims,
.normalize = sparsevec_l2_normalize,
.checkValue = SparsevecCheckValue
.checkValue = SparsevecCheckValue,
.useFsm = true
};
PG_RETURN_POINTER(&typeInfo);

View File

@@ -599,6 +599,7 @@ MarkDeleted(HnswVacuumState * vacuumstate)
BlockNumber insertPage = InvalidBlockNumber;
Relation index = vacuumstate->index;
BufferAccessStrategy bas = vacuumstate->bas;
bool useFsm = HnswGetTypeInfo(index)->useFsm;
/*
* Wait for inserts and index scans to complete. Inserts and scans before
@@ -710,15 +711,23 @@ MarkDeleted(HnswVacuumState * vacuumstate)
if (nbuf != buf)
UnlockReleaseBuffer(nbuf);
/* Set to first free page */
if (!useFsm && !BlockNumberIsValid(insertPage))
insertPage = blkno;
/* Prepare new xlog */
state = GenericXLogStart(index);
page = GenericXLogRegisterBuffer(state, buf, 0);
}
HnswRecordPageWithFreeSpace(index, blkno, page);
if (useFsm)
{
/* Update free space map */
HnswRecordPageWithFreeSpace(index, blkno, page);
/* Set to last page */
insertPage = blkno;
/* Set to last page */
insertPage = blkno;
}
blkno = HnswPageGetOpaque(page)->nextblkno;
@@ -726,7 +735,8 @@ MarkDeleted(HnswVacuumState * vacuumstate)
UnlockReleaseBuffer(buf);
}
FreeSpaceMapVacuum(index);
if (useFsm)
FreeSpaceMapVacuum(index);
/* Update insert page last, after everything has been marked as deleted */
HnswUpdateMetaPage(index, 0, NULL, insertPage, MAIN_FORKNUM, false);