Compare commits

..

1 Commits

Author SHA1 Message Date
Andrew Kane
47c7fa715c Updated IndexAmRoutine [skip ci] 2026-06-10 11:50:45 -07:00
6 changed files with 41 additions and 107 deletions

View File

@@ -258,11 +258,6 @@ hnswvalidate(Oid opclassoid)
return true;
}
static void
hnswunguardbatch(IndexScanDesc scan, IndexScanBatch batch)
{
}
/*
* Define index handler
*
@@ -317,9 +312,9 @@ hnswhandler(PG_FUNCTION_ARGS)
.amadjustmembers = NULL,
.ambeginscan = hnswbeginscan,
.amrescan = hnswrescan,
.amgettuple = NULL,
.amgetbatch = hnswgetbatch,
.amunguardbatch = hnswunguardbatch,
.amgettuple = hnswgettuple,
.amgetbatch = NULL,
.amunguardbatch = NULL,
.amkillitemsbatch = NULL,
.amgettransform = NULL,
.amgetbitmap = NULL,

View File

@@ -465,7 +465,7 @@ IndexBulkDeleteResult *hnswbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResu
IndexBulkDeleteResult *hnswvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
IndexScanDesc hnswbeginscan(Relation index, int nkeys, 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);
static inline HnswNeighborArray *

View File

@@ -3,7 +3,6 @@
#include <limits.h>
#include "access/genam.h"
#include "access/indexbatch.h"
#include "access/relscan.h"
#include "hnsw.h"
#include "lib/pairingheap.h"
@@ -136,11 +135,6 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
double maxMemory;
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->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
hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
bool
hnswgettuple(IndexScanDesc scan, ScanDirection dir)
{
HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
IndexScanBatch batch = indexam_util_alloc_batch(scan);
MemoryContext oldCtx = MemoryContextSwitchTo(so->tmpCtx);
/*
@@ -252,7 +245,6 @@ hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
HnswSearchCandidate *sc;
HnswElement element;
ItemPointer heaptid;
int nitems = 0;
if (list_length(so->w) == 0)
{
@@ -298,64 +290,44 @@ hnswgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
break;
}
while (list_length(so->w) != 0)
sc = llast(so->w);
element = HnswPtrAccess(base, sc->element);
/* Move to next element if no valid heap TIDs */
if (element->heaptidsLength == 0)
{
sc = llast(so->w);
element = HnswPtrAccess(base, sc->element);
so->w = list_delete_last(so->w);
/* Move to next element if no valid heap TIDs */
if (element->heaptidsLength == 0)
/* Mark memory as free for next iteration */
if (hnsw_iterative_scan != HNSW_ITERATIVE_SCAN_OFF)
{
so->w = list_delete_last(so->w);
/* Mark memory as free for next iteration */
if (hnsw_iterative_scan != HNSW_ITERATIVE_SCAN_OFF)
{
pfree(element);
pfree(sc);
}
continue;
pfree(element);
pfree(sc);
}
heaptid = &element->heaptids[--element->heaptidsLength];
if (hnsw_iterative_scan == HNSW_ITERATIVE_SCAN_STRICT)
{
if (sc->distance < so->previousDistance)
continue;
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;
continue;
}
/* Needed for strict iterative scans */
if (nitems == 0)
continue;
heaptid = &element->heaptids[--element->heaptidsLength];
if (hnsw_iterative_scan == HNSW_ITERATIVE_SCAN_STRICT)
{
if (sc->distance < so->previousDistance)
continue;
so->previousDistance = sc->distance;
}
MemoryContextSwitchTo(oldCtx);
scan->xs_heaptid = *heaptid;
scan->xs_recheck = false;
scan->xs_recheckorderby = false;
batch->firstItem = 0;
batch->lastItem = nitems - 1;
batch->dir = ForwardScanDirection;
return batch;
return true;
}
MemoryContextSwitchTo(oldCtx);
indexam_util_release_batch(scan, batch);
return NULL;
return false;
}
/*

View File

@@ -175,11 +175,6 @@ ivfflatvalidate(Oid opclassoid)
return true;
}
static void
ivfflatunguardbatch(IndexScanDesc scan, IndexScanBatch batch)
{
}
/*
* Define index handler
*
@@ -234,9 +229,9 @@ ivfflathandler(PG_FUNCTION_ARGS)
.amadjustmembers = NULL,
.ambeginscan = ivfflatbeginscan,
.amrescan = ivfflatrescan,
.amgettuple = NULL,
.amgetbatch = ivfflatgetbatch,
.amunguardbatch = ivfflatunguardbatch,
.amgettuple = ivfflatgettuple,
.amgetbatch = NULL,
.amunguardbatch = NULL,
.amkillitemsbatch = NULL,
.amgettransform = NULL,
.amgetbitmap = NULL,

View File

@@ -344,7 +344,7 @@ IndexBulkDeleteResult *ivfflatbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteR
IndexBulkDeleteResult *ivfflatvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
IndexScanDesc ivfflatbeginscan(Relation index, int nkeys, 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);
#endif

View File

@@ -3,7 +3,6 @@
#include <float.h>
#include "access/genam.h"
#include "access/indexbatch.h"
#include "access/itup.h"
#include "access/relscan.h"
#include "access/tupdesc.h"
@@ -262,11 +261,6 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
MemoryContext oldCtx;
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 */
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
ivfflatgetbatch(IndexScanDesc scan, IndexScanBatch priorbatch, ScanDirection dir)
bool
ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
{
IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque;
IndexScanBatch batch = indexam_util_alloc_batch(scan);
ItemPointer heaptid;
bool isnull;
int nitems = 0;
/*
* 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))
{
if (so->listIndex == so->maxProbes)
{
indexam_util_release_batch(scan, batch);
return NULL;
}
return false;
IvfflatBench("GetScanItems", GetScanItems(scan, so->value));
}
for (;;)
{
heaptid = (ItemPointer) DatumGetPointer(slot_getattr(so->mslot, 2, &isnull));
batch->items[nitems].tableTid = *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;
}
heaptid = (ItemPointer) DatumGetPointer(slot_getattr(so->mslot, 2, &isnull));
scan->xs_heaptid = *heaptid;
scan->xs_recheck = false;
scan->xs_recheckorderby = false;
batch->firstItem = 0;
batch->lastItem = nitems - 1;
batch->dir = ForwardScanDirection;
return batch;
return true;
}
/*