pgvector.git / summary / log / commit / refs
commit d078db3d25351e159c3a4f846f70db313587f8cb
Author: Andrew Kane <andrew@ankane.org>
Date: Fri Nov 10 02:28:25 2023 +0000
Switched HnswElementTuple to generic data and zero full section
src/hnsw.h | 4 ++--
src/hnswutils.c | 8 ++++----
src/hnswvacuum.c | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/hnsw.h b/src/hnsw.h
index e6b45a46..a0e53188 100644
--- a/src/hnsw.h
+++ b/src/hnsw.h
@@ -59,7 +59,7 @@
#define HNSW_MAX_SIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)) - sizeof(ItemIdData))
-#define HNSW_ELEMENT_TUPLE_SIZE(size) MAXALIGN(offsetof(HnswElementTupleData, vec) + (size))
+#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))
#define HnswPageGetOpaque(page) ((HnswPageOpaque) PageGetSpecialPointer(page))
@@ -204,7 +204,7 @@ typedef struct HnswElementTupleData
ItemPointerData heaptids[HNSW_HEAPTIDS];
ItemPointerData neighbortid;
uint16 unused2;
- Vector vec;
+ char data[FLEXIBLE_ARRAY_MEMBER];
} HnswElementTupleData;
typedef HnswElementTupleData * HnswElementTuple;
diff --git a/src/hnswutils.c b/src/hnswutils.c
index 836e95e5..1e41372e 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -325,7 +325,7 @@ HnswSetElementTuple(HnswElementTuple etup, HnswElement element)
else
ItemPointerSetInvalid(&etup->heaptids[i]);
}
- memcpy(&etup->vec, DatumGetPointer(element->value), VARSIZE_ANY(DatumGetPointer(element->value)));
+ memcpy(&etup->data, DatumGetPointer(element->value), VARSIZE_ANY(DatumGetPointer(element->value)));
}
/*
@@ -448,9 +448,9 @@ HnswLoadElementFromTuple(HnswElement element, HnswElementTuple etup, bool loadHe
if (loadVec)
{
- Vector *vec = palloc(VARSIZE_ANY(&etup->vec));
+ Vector *vec = palloc(VARSIZE_ANY(&etup->data));
- memcpy(vec, &etup->vec, VARSIZE_ANY(&etup->vec));
+ memcpy(vec, &etup->data, VARSIZE_ANY(&etup->data));
element->value = PointerGetDatum(vec);
}
}
@@ -479,7 +479,7 @@ HnswLoadElement(HnswElement element, float *distance, Datum *q, Relation index,
/* Calculate distance */
if (distance != NULL)
- *distance = (float) DatumGetFloat8(FunctionCall2Coll(procinfo, collation, *q, PointerGetDatum(&etup->vec)));
+ *distance = (float) DatumGetFloat8(FunctionCall2Coll(procinfo, collation, *q, PointerGetDatum(&etup->data)));
UnlockReleaseBuffer(buf);
}
diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c
index b2f361de..8fd5d4f1 100644
--- a/src/hnswvacuum.c
+++ b/src/hnswvacuum.c
@@ -530,7 +530,7 @@ MarkDeleted(HnswVacuumState * vacuumstate)
/* Overwrite element */
etup->deleted = 1;
- MemSet(&etup->vec.x, 0, etup->vec.dim * sizeof(float));
+ MemSet(&etup->data, 0, VARSIZE_ANY(&etup->data));
/* Overwrite neighbors */
for (int i = 0; i < ntup->count; i++)
[parent: fbb904ae2fcd]