pgvector.git / summary / log / commit / refs
commit 72ea3c1210da32cad77be40375c05caa046989d1
Author: Andrew Kane <andrew@ankane.org>
Date: Sun Sep 03 08:59:27 2023 +0000
Added GetScanValue function
src/hnswscan.c | 43 +++++++++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/src/hnswscan.c b/src/hnswscan.c
index 48c53583..c0ec8ca5 100644
--- a/src/hnswscan.c
+++ b/src/hnswscan.c
@@ -62,6 +62,33 @@ GetDimensions(Relation index)
return dimensions;
}
+/*
+ * Get scan value
+ */
+static Datum
+GetScanValue(IndexScanDesc scan)
+{
+ HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+ Datum value;
+
+ if (scan->orderByData->sk_flags & SK_ISNULL)
+ value = PointerGetDatum(InitVector(GetDimensions(scan->indexRelation)));
+ else
+ {
+ value = scan->orderByData->sk_argument;
+
+ /* Value should not be compressed or toasted */
+ Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
+ Assert(!VARATT_IS_EXTENDED(DatumGetPointer(value)));
+
+ /* Fine if normalization fails */
+ if (so->normprocinfo != NULL)
+ HnswNormValue(so->normprocinfo, so->collation, &value, NULL);
+ }
+
+ return value;
+}
+
/*
* Prepare for an index scan
*/
@@ -134,20 +161,8 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
if (scan->orderByData == NULL)
elog(ERROR, "cannot scan hnsw index without order");
- if (scan->orderByData->sk_flags & SK_ISNULL)
- value = PointerGetDatum(InitVector(GetDimensions(scan->indexRelation)));
- else
- {
- value = scan->orderByData->sk_argument;
-
- /* Value should not be compressed or toasted */
- Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
- Assert(!VARATT_IS_EXTENDED(DatumGetPointer(value)));
-
- /* Fine if normalization fails */
- if (so->normprocinfo != NULL)
- HnswNormValue(so->normprocinfo, so->collation, &value, NULL);
- }
+ /* Get scan value */
+ value = GetScanValue(scan);
/*
* Get a shared lock. This allows vacuum to ensure no in-flight scans
[parent: b0801b8833c3]