mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-12 23:56:55 +08:00
Removed type-specific code from ivfscan
This commit is contained in:
@@ -256,6 +256,7 @@ typedef struct IvfflatScanOpaqueData
|
|||||||
FmgrInfo *procinfo;
|
FmgrInfo *procinfo;
|
||||||
FmgrInfo *normprocinfo;
|
FmgrInfo *normprocinfo;
|
||||||
Oid collation;
|
Oid collation;
|
||||||
|
Datum (*distfunc) (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2);
|
||||||
|
|
||||||
/* Lists */
|
/* Lists */
|
||||||
pairingheap *listQueue;
|
pairingheap *listQueue;
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
#include "access/relscan.h"
|
#include "access/relscan.h"
|
||||||
#include "bitvec.h"
|
|
||||||
#include "catalog/pg_operator_d.h"
|
#include "catalog/pg_operator_d.h"
|
||||||
#include "catalog/pg_type_d.h"
|
#include "catalog/pg_type_d.h"
|
||||||
#include "halfvec.h"
|
|
||||||
#include "lib/pairingheap.h"
|
#include "lib/pairingheap.h"
|
||||||
#include "ivfflat.h"
|
#include "ivfflat.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
@@ -58,7 +56,7 @@ GetScanLists(IndexScanDesc scan, Datum value)
|
|||||||
double distance;
|
double distance;
|
||||||
|
|
||||||
/* Use procinfo from the index instead of scan key for performance */
|
/* Use procinfo from the index instead of scan key for performance */
|
||||||
distance = DatumGetFloat8(FunctionCall2Coll(so->procinfo, so->collation, PointerGetDatum(&list->center), value));
|
distance = DatumGetFloat8(so->distfunc(so->procinfo, so->collation, PointerGetDatum(&list->center), value));
|
||||||
|
|
||||||
if (listCount < so->probes)
|
if (listCount < so->probes)
|
||||||
{
|
{
|
||||||
@@ -151,7 +149,7 @@ GetScanItems(IndexScanDesc scan, Datum value)
|
|||||||
* performance
|
* performance
|
||||||
*/
|
*/
|
||||||
ExecClearTuple(slot);
|
ExecClearTuple(slot);
|
||||||
slot->tts_values[0] = FunctionCall2Coll(so->procinfo, so->collation, datum, value);
|
slot->tts_values[0] = so->distfunc(so->procinfo, so->collation, datum, value);
|
||||||
slot->tts_isnull[0] = false;
|
slot->tts_isnull[0] = false;
|
||||||
slot->tts_values[1] = PointerGetDatum(&itup->t_tid);
|
slot->tts_values[1] = PointerGetDatum(&itup->t_tid);
|
||||||
slot->tts_isnull[1] = false;
|
slot->tts_isnull[1] = false;
|
||||||
@@ -179,6 +177,15 @@ GetScanItems(IndexScanDesc scan, Datum value)
|
|||||||
tuplesort_performsort(so->sortstate);
|
tuplesort_performsort(so->sortstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Zero distance
|
||||||
|
*/
|
||||||
|
static Datum
|
||||||
|
ZeroDistance(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
|
||||||
|
{
|
||||||
|
return Float8GetDatum(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get scan value
|
* Get scan value
|
||||||
*/
|
*/
|
||||||
@@ -190,20 +197,13 @@ GetScanValue(IndexScanDesc scan)
|
|||||||
|
|
||||||
if (scan->orderByData->sk_flags & SK_ISNULL)
|
if (scan->orderByData->sk_flags & SK_ISNULL)
|
||||||
{
|
{
|
||||||
IvfflatType type = IvfflatGetType(scan->indexRelation);
|
value = PointerGetDatum(NULL);
|
||||||
|
so->distfunc = ZeroDistance;
|
||||||
if (type == IVFFLAT_TYPE_VECTOR)
|
|
||||||
value = PointerGetDatum(InitVector(so->dimensions));
|
|
||||||
else if (type == IVFFLAT_TYPE_HALFVEC)
|
|
||||||
value = PointerGetDatum(InitHalfVector(so->dimensions));
|
|
||||||
else if (type == IVFFLAT_TYPE_BIT)
|
|
||||||
value = PointerGetDatum(InitBitVector(so->dimensions));
|
|
||||||
else
|
|
||||||
elog(ERROR, "Unsupported type");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value = scan->orderByData->sk_argument;
|
value = scan->orderByData->sk_argument;
|
||||||
|
so->distfunc = FunctionCall2Coll;
|
||||||
|
|
||||||
/* Value should not be compressed or toasted */
|
/* Value should not be compressed or toasted */
|
||||||
Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
|
Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
|
||||||
|
|||||||
Reference in New Issue
Block a user