mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-25 05:12:43 +08:00
Compare commits
1 Commits
amgetbatch
...
amgettuple
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47c7fa715c |
11
src/hnsw.c
11
src/hnsw.c
@@ -258,11 +258,6 @@ hnswvalidate(Oid opclassoid)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
hnswunguardbatch(IndexScanDesc scan, IndexScanBatch batch)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define index handler
|
* Define index handler
|
||||||
*
|
*
|
||||||
@@ -317,9 +312,9 @@ hnswhandler(PG_FUNCTION_ARGS)
|
|||||||
.amadjustmembers = NULL,
|
.amadjustmembers = NULL,
|
||||||
.ambeginscan = hnswbeginscan,
|
.ambeginscan = hnswbeginscan,
|
||||||
.amrescan = hnswrescan,
|
.amrescan = hnswrescan,
|
||||||
.amgettuple = NULL,
|
.amgettuple = hnswgettuple,
|
||||||
.amgetbatch = hnswgetbatch,
|
.amgetbatch = NULL,
|
||||||
.amunguardbatch = hnswunguardbatch,
|
.amunguardbatch = NULL,
|
||||||
.amkillitemsbatch = NULL,
|
.amkillitemsbatch = NULL,
|
||||||
.amgettransform = NULL,
|
.amgettransform = NULL,
|
||||||
.amgetbitmap = NULL,
|
.amgetbitmap = NULL,
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ IndexBulkDeleteResult *hnswbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResu
|
|||||||
IndexBulkDeleteResult *hnswvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
|
IndexBulkDeleteResult *hnswvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
|
||||||
IndexScanDesc hnswbeginscan(Relation index, int nkeys, int norderbys);
|
IndexScanDesc hnswbeginscan(Relation index, int nkeys, int norderbys);
|
||||||
void hnswrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys);
|
void hnswrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys);
|
||||||
IndexScanBatch hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir);
|
bool hnswgettuple(IndexScanDesc scan, ScanDirection dir);
|
||||||
void hnswendscan(IndexScanDesc scan);
|
void hnswendscan(IndexScanDesc scan);
|
||||||
|
|
||||||
static inline HnswNeighborArray *
|
static inline HnswNeighborArray *
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "access/genam.h"
|
#include "access/genam.h"
|
||||||
#include "access/indexbatch.h"
|
|
||||||
#include "access/relscan.h"
|
#include "access/relscan.h"
|
||||||
#include "hnsw.h"
|
#include "hnsw.h"
|
||||||
#include "lib/pairingheap.h"
|
#include "lib/pairingheap.h"
|
||||||
@@ -136,11 +135,6 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
|
|||||||
double maxMemory;
|
double maxMemory;
|
||||||
|
|
||||||
scan = RelationGetIndexScan(index, nkeys, norderbys);
|
scan = RelationGetIndexScan(index, nkeys, norderbys);
|
||||||
scan->maxitemsbatch = hnsw_ef_search * HNSW_HEAPTIDS;
|
|
||||||
/* unused but must be > 0 */
|
|
||||||
scan->batch_index_opaque_static = MAXALIGN(1);
|
|
||||||
scan->batch_index_opaque_dyn = 0;
|
|
||||||
scan->batch_tuples_workspace = 0;
|
|
||||||
|
|
||||||
so = (HnswScanOpaque) palloc(sizeof(HnswScanOpaqueData));
|
so = (HnswScanOpaque) palloc(sizeof(HnswScanOpaqueData));
|
||||||
so->typeInfo = HnswGetTypeInfo(index);
|
so->typeInfo = HnswGetTypeInfo(index);
|
||||||
@@ -190,13 +184,12 @@ hnswrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int no
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fetch the next batch in the given scan
|
* Fetch the next tuple in the given scan
|
||||||
*/
|
*/
|
||||||
IndexScanBatch
|
bool
|
||||||
hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
|
hnswgettuple(IndexScanDesc scan, ScanDirection dir)
|
||||||
{
|
{
|
||||||
HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
|
HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
|
||||||
IndexScanBatch batch = indexam_util_alloc_batch(scan);
|
|
||||||
MemoryContext oldCtx = MemoryContextSwitchTo(so->tmpCtx);
|
MemoryContext oldCtx = MemoryContextSwitchTo(so->tmpCtx);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -252,7 +245,6 @@ hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
|
|||||||
HnswSearchCandidate *sc;
|
HnswSearchCandidate *sc;
|
||||||
HnswElement element;
|
HnswElement element;
|
||||||
ItemPointer heaptid;
|
ItemPointer heaptid;
|
||||||
int nitems = 0;
|
|
||||||
|
|
||||||
if (list_length(so->w) == 0)
|
if (list_length(so->w) == 0)
|
||||||
{
|
{
|
||||||
@@ -298,8 +290,6 @@ hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (list_length(so->w) != 0)
|
|
||||||
{
|
|
||||||
sc = llast(so->w);
|
sc = llast(so->w);
|
||||||
element = HnswPtrAccess(base, sc->element);
|
element = HnswPtrAccess(base, sc->element);
|
||||||
|
|
||||||
@@ -328,34 +318,16 @@ hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
|
|||||||
so->previousDistance = sc->distance;
|
so->previousDistance = sc->distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch->items[nitems].tableTid = *heaptid;
|
|
||||||
batch->items[nitems].indexOffset = -1;
|
|
||||||
batch->items[nitems].tupleOffset = 0;
|
|
||||||
nitems++;
|
|
||||||
|
|
||||||
/* Keep batch size flexible */
|
|
||||||
if (nitems == scan->maxitemsbatch)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Needed for strict iterative scans */
|
|
||||||
if (nitems == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldCtx);
|
MemoryContextSwitchTo(oldCtx);
|
||||||
|
|
||||||
|
scan->xs_heaptid = *heaptid;
|
||||||
scan->xs_recheck = false;
|
scan->xs_recheck = false;
|
||||||
scan->xs_recheckorderby = false;
|
scan->xs_recheckorderby = false;
|
||||||
|
return true;
|
||||||
batch->firstItem = 0;
|
|
||||||
batch->lastItem = nitems - 1;
|
|
||||||
batch->dir = ForwardScanDirection;
|
|
||||||
return batch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldCtx);
|
MemoryContextSwitchTo(oldCtx);
|
||||||
indexam_util_release_batch(scan, batch);
|
return false;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -175,11 +175,6 @@ ivfflatvalidate(Oid opclassoid)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
ivfflatunguardbatch(IndexScanDesc scan, IndexScanBatch batch)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define index handler
|
* Define index handler
|
||||||
*
|
*
|
||||||
@@ -234,9 +229,9 @@ ivfflathandler(PG_FUNCTION_ARGS)
|
|||||||
.amadjustmembers = NULL,
|
.amadjustmembers = NULL,
|
||||||
.ambeginscan = ivfflatbeginscan,
|
.ambeginscan = ivfflatbeginscan,
|
||||||
.amrescan = ivfflatrescan,
|
.amrescan = ivfflatrescan,
|
||||||
.amgettuple = NULL,
|
.amgettuple = ivfflatgettuple,
|
||||||
.amgetbatch = ivfflatgetbatch,
|
.amgetbatch = NULL,
|
||||||
.amunguardbatch = ivfflatunguardbatch,
|
.amunguardbatch = NULL,
|
||||||
.amkillitemsbatch = NULL,
|
.amkillitemsbatch = NULL,
|
||||||
.amgettransform = NULL,
|
.amgettransform = NULL,
|
||||||
.amgetbitmap = NULL,
|
.amgetbitmap = NULL,
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ IndexBulkDeleteResult *ivfflatbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteR
|
|||||||
IndexBulkDeleteResult *ivfflatvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
|
IndexBulkDeleteResult *ivfflatvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
|
||||||
IndexScanDesc ivfflatbeginscan(Relation index, int nkeys, int norderbys);
|
IndexScanDesc ivfflatbeginscan(Relation index, int nkeys, int norderbys);
|
||||||
void ivfflatrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys);
|
void ivfflatrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys);
|
||||||
IndexScanBatch ivfflatgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir);
|
bool ivfflatgettuple(IndexScanDesc scan, ScanDirection dir);
|
||||||
void ivfflatendscan(IndexScanDesc scan);
|
void ivfflatendscan(IndexScanDesc scan);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
#include "access/genam.h"
|
#include "access/genam.h"
|
||||||
#include "access/indexbatch.h"
|
|
||||||
#include "access/itup.h"
|
#include "access/itup.h"
|
||||||
#include "access/relscan.h"
|
#include "access/relscan.h"
|
||||||
#include "access/tupdesc.h"
|
#include "access/tupdesc.h"
|
||||||
@@ -262,11 +261,6 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
|
|||||||
MemoryContext oldCtx;
|
MemoryContext oldCtx;
|
||||||
|
|
||||||
scan = RelationGetIndexScan(index, nkeys, norderbys);
|
scan = RelationGetIndexScan(index, nkeys, norderbys);
|
||||||
scan->maxitemsbatch = 1000;
|
|
||||||
/* unused but must be > 0 */
|
|
||||||
scan->batch_index_opaque_static = MAXALIGN(1);
|
|
||||||
scan->batch_index_opaque_dyn = 0;
|
|
||||||
scan->batch_tuples_workspace = 0;
|
|
||||||
|
|
||||||
/* Get lists and dimensions from metapage */
|
/* Get lists and dimensions from metapage */
|
||||||
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
|
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
|
||||||
@@ -354,16 +348,14 @@ ivfflatrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fetch the next batch in the given scan
|
* Fetch the next tuple in the given scan
|
||||||
*/
|
*/
|
||||||
IndexScanBatch
|
bool
|
||||||
ivfflatgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
|
ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
|
||||||
{
|
{
|
||||||
IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque;
|
IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque;
|
||||||
IndexScanBatch batch = indexam_util_alloc_batch(scan);
|
|
||||||
ItemPointer heaptid;
|
ItemPointer heaptid;
|
||||||
bool isnull;
|
bool isnull;
|
||||||
int nitems = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Index can be used to scan backward, but Postgres doesn't support
|
* Index can be used to scan backward, but Postgres doesn't support
|
||||||
@@ -401,37 +393,17 @@ ivfflatgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir
|
|||||||
while (!tuplesort_gettupleslot(so->sortstate, true, false, so->mslot, NULL))
|
while (!tuplesort_gettupleslot(so->sortstate, true, false, so->mslot, NULL))
|
||||||
{
|
{
|
||||||
if (so->listIndex == so->maxProbes)
|
if (so->listIndex == so->maxProbes)
|
||||||
{
|
return false;
|
||||||
indexam_util_release_batch(scan, batch);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
IvfflatBench("GetScanItems", GetScanItems(scan, so->value));
|
IvfflatBench("GetScanItems", GetScanItems(scan, so->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
heaptid = (ItemPointer) DatumGetPointer(slot_getattr(so->mslot, 2, &isnull));
|
heaptid = (ItemPointer) DatumGetPointer(slot_getattr(so->mslot, 2, &isnull));
|
||||||
|
|
||||||
batch->items[nitems].tableTid = *heaptid;
|
scan->xs_heaptid = *heaptid;
|
||||||
batch->items[nitems].indexOffset = -1;
|
|
||||||
batch->items[nitems].tupleOffset = 0;
|
|
||||||
nitems++;
|
|
||||||
|
|
||||||
if (nitems == scan->maxitemsbatch)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!tuplesort_gettupleslot(so->sortstate, true, false, so->mslot, NULL))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
scan->xs_recheck = false;
|
scan->xs_recheck = false;
|
||||||
scan->xs_recheckorderby = false;
|
scan->xs_recheckorderby = false;
|
||||||
|
return true;
|
||||||
batch->firstItem = 0;
|
|
||||||
batch->lastItem = nitems - 1;
|
|
||||||
batch->dir = ForwardScanDirection;
|
|
||||||
return batch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user