mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 07:06:57 +08:00
Added tuple stats for HNSW [skip ci]
This commit is contained in:
@@ -20,6 +20,10 @@ int hnsw_ef_search;
|
|||||||
int hnsw_lock_tranche_id;
|
int hnsw_lock_tranche_id;
|
||||||
static relopt_kind hnsw_relopt_kind;
|
static relopt_kind hnsw_relopt_kind;
|
||||||
|
|
||||||
|
#ifdef HNSW_STATS
|
||||||
|
int hnsw_tuples;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assign a tranche ID for our LWLocks. This only needs to be done by one
|
* Assign a tranche ID for our LWLocks. This only needs to be done by one
|
||||||
* backend, as the tranche ID is remembered in shared memory.
|
* backend, as the tranche ID is remembered in shared memory.
|
||||||
@@ -135,6 +139,10 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
|
|
||||||
genericcostestimate(root, path, loop_count, &costs);
|
genericcostestimate(root, path, loop_count, &costs);
|
||||||
|
|
||||||
|
#ifdef HNSW_STATS
|
||||||
|
elog(INFO, "estimated tuples = %0.f", costs.numIndexTuples);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Use total cost since most work happens before first tuple is returned */
|
/* Use total cost since most work happens before first tuple is returned */
|
||||||
*indexStartupCost = costs.indexTotalCost;
|
*indexStartupCost = costs.indexTotalCost;
|
||||||
*indexTotalCost = costs.indexTotalCost;
|
*indexTotalCost = costs.indexTotalCost;
|
||||||
|
|||||||
@@ -113,6 +113,10 @@
|
|||||||
extern int hnsw_ef_search;
|
extern int hnsw_ef_search;
|
||||||
extern int hnsw_lock_tranche_id;
|
extern int hnsw_lock_tranche_id;
|
||||||
|
|
||||||
|
#ifdef HNSW_STATS
|
||||||
|
extern int hnsw_tuples;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct HnswElementData HnswElementData;
|
typedef struct HnswElementData HnswElementData;
|
||||||
typedef struct HnswNeighborArray HnswNeighborArray;
|
typedef struct HnswNeighborArray HnswNeighborArray;
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,23 @@ GetScanItems(IndexScanDesc scan, Datum q)
|
|||||||
|
|
||||||
ep = list_make1(HnswEntryCandidate(base, entryPoint, q, index, procinfo, collation, false));
|
ep = list_make1(HnswEntryCandidate(base, entryPoint, q, index, procinfo, collation, false));
|
||||||
|
|
||||||
|
#ifdef HNSW_STATS
|
||||||
|
hnsw_tuples = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int lc = entryPoint->level; lc >= 1; lc--)
|
for (int lc = entryPoint->level; lc >= 1; lc--)
|
||||||
{
|
{
|
||||||
w = HnswSearchLayer(base, q, ep, 1, lc, index, procinfo, collation, m, false, NULL);
|
w = HnswSearchLayer(base, q, ep, 1, lc, index, procinfo, collation, m, false, NULL);
|
||||||
ep = w;
|
ep = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
return HnswSearchLayer(base, q, ep, hnsw_ef_search, 0, index, procinfo, collation, m, false, NULL);
|
w = HnswSearchLayer(base, q, ep, hnsw_ef_search, 0, index, procinfo, collation, m, false, NULL);
|
||||||
|
|
||||||
|
#ifdef HNSW_STATS
|
||||||
|
elog(INFO, "total tuples = %d", hnsw_tuples);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -801,6 +801,11 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
|
|||||||
HnswElement eElement = HnswPtrAccess(base, e->element);
|
HnswElement eElement = HnswPtrAccess(base, e->element);
|
||||||
bool alwaysAdd = wlen < ef;
|
bool alwaysAdd = wlen < ef;
|
||||||
|
|
||||||
|
#ifdef HNSW_STATS
|
||||||
|
if (!inserting)
|
||||||
|
hnsw_tuples++;
|
||||||
|
#endif
|
||||||
|
|
||||||
f = ((HnswPairingHeapNode *) pairingheap_first(W))->inner;
|
f = ((HnswPairingHeapNode *) pairingheap_first(W))->inner;
|
||||||
|
|
||||||
if (index == NULL)
|
if (index == NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user