mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-14 08:36:54 +08:00
Ran pgindent [skip ci]
This commit is contained in:
29
src/hnsw.c
29
src/hnsw.c
@@ -99,8 +99,8 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
{
|
{
|
||||||
GenericCosts costs;
|
GenericCosts costs;
|
||||||
int m;
|
int m;
|
||||||
int entryLevel;
|
int entryLevel;
|
||||||
int layer0TuplesMax;
|
int layer0TuplesMax;
|
||||||
double layer0Selectivity;
|
double layer0Selectivity;
|
||||||
double scalingFactor = 0.55;
|
double scalingFactor = 0.55;
|
||||||
Relation index;
|
Relation index;
|
||||||
@@ -124,22 +124,21 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* HNSW cost estimation follows a formula that accounts for the total
|
* HNSW cost estimation follows a formula that accounts for the total
|
||||||
* number of tuples indexed combined with the parameters that most influence
|
* number of tuples indexed combined with the parameters that most
|
||||||
* the duration of the index scan, namely:
|
* influence the duration of the index scan, namely: m - the number of
|
||||||
* m - the number of tuples that are scanned in each step of the HNSW
|
* tuples that are scanned in each step of the HNSW graph traversal
|
||||||
* graph traversal
|
* ef_search - which influences the total number of steps taken at layer 0
|
||||||
* ef_search - which influences the total number of steps taken at layer 0
|
|
||||||
*
|
*
|
||||||
* The source of the vector data can impact how many steps it takes to
|
* The source of the vector data can impact how many steps it takes to
|
||||||
* converge on the set of vectors to return to the executor. Currently,
|
* converge on the set of vectors to return to the executor. Currently, we
|
||||||
* we use a hardcoded scaling factor (HNSWScanScalingFactor) to help
|
* use a hardcoded scaling factor (HNSWScanScalingFactor) to help
|
||||||
* influence that, but this could later become a configurable parameter
|
* influence that, but this could later become a configurable parameter
|
||||||
* based on the cost estimations.
|
* based on the cost estimations.
|
||||||
*
|
*
|
||||||
* The tuple estimator formula is below:
|
* The tuple estimator formula is below:
|
||||||
*
|
*
|
||||||
* numIndexTuples = (entryLevel * m) +
|
* numIndexTuples = (entryLevel * m) + (layer0TuplesMax *
|
||||||
* (layer0TuplesMax * layer0Selectivity)
|
* layer0Selectivity)
|
||||||
*
|
*
|
||||||
* "entryLevel * m" represents the floor of tuples we need to scan to get
|
* "entryLevel * m" represents the floor of tuples we need to scan to get
|
||||||
* to layer 0 (L0).
|
* to layer 0 (L0).
|
||||||
@@ -153,7 +152,7 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
*/
|
*/
|
||||||
entryLevel = (int) floor(log(path->indexinfo->tuples + 1) * HnswGetMl(m));
|
entryLevel = (int) floor(log(path->indexinfo->tuples + 1) * HnswGetMl(m));
|
||||||
layer0TuplesMax = HnswGetLayerM(m, 0) * hnsw_ef_search;
|
layer0TuplesMax = HnswGetLayerM(m, 0) * hnsw_ef_search;
|
||||||
layer0Selectivity = (scalingFactor * log(path->indexinfo->tuples + 1)) /
|
layer0Selectivity = (scalingFactor * log(path->indexinfo->tuples + 1)) /
|
||||||
(log(m) * (1 + log(hnsw_ef_search)));
|
(log(m) * (1 + log(hnsw_ef_search)));
|
||||||
|
|
||||||
costs.numIndexTuples = (entryLevel * m) +
|
costs.numIndexTuples = (entryLevel * m) +
|
||||||
|
|||||||
Reference in New Issue
Block a user