From bed40ec0b5f5e7abc5ce511e1d0a60a5bbe06069 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 11 Apr 2024 09:20:10 -0700 Subject: [PATCH] Moved code to get scan value to separate function for IVFFlat [skip ci] --- src/ivfscan.c | 56 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/ivfscan.c b/src/ivfscan.c index ae05f2d..ce80f28 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -177,6 +177,40 @@ GetScanItems(IndexScanDesc scan, Datum value) tuplesort_performsort(so->sortstate); } +/* + * Get scan value + */ +static Datum +GetScanValue(IndexScanDesc scan) +{ + IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque; + Datum value; + + if (scan->orderByData->sk_flags & SK_ISNULL) + { + IvfflatType type = IvfflatGetType(scan->indexRelation); + + if (type == IVFFLAT_TYPE_VECTOR) + value = PointerGetDatum(InitVector(so->dimensions)); + else + elog(ERROR, "Unsupported type"); + } + 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) + IvfflatNormValue(so->normprocinfo, so->collation, &value, IvfflatGetType(scan->indexRelation)); + } + + return value; +} + /* * Prepare for an index scan */ @@ -268,7 +302,6 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir) if (so->first) { Datum value; - IvfflatType type = IvfflatGetType(scan->indexRelation); /* Count index scan for stats */ pgstat_count_index_scan(scan->indexRelation); @@ -282,26 +315,7 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir) if (!IsMVCCSnapshot(scan->xs_snapshot)) elog(ERROR, "non-MVCC snapshots are not supported with ivfflat"); - if (scan->orderByData->sk_flags & SK_ISNULL) - { - if (type == IVFFLAT_TYPE_VECTOR) - value = PointerGetDatum(InitVector(so->dimensions)); - else - elog(ERROR, "Unsupported type"); - } - 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) - IvfflatNormValue(so->normprocinfo, so->collation, &value, type); - } - + value = GetScanValue(scan); IvfflatBench("GetScanLists", GetScanLists(scan, value)); IvfflatBench("GetScanItems", GetScanItems(scan, value)); so->first = false;