mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 23:26:55 +08:00
Allow override
This commit is contained in:
21
src/hnsw.c
21
src/hnsw.c
@@ -83,11 +83,8 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
List *qinfos;
|
List *qinfos;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/* Never use index without order or limit */
|
||||||
* Never use index without order or limit, or if limit + offset >
|
if (path->indexorderbys == NULL || root->limit_tuples < 0)
|
||||||
* ef_search
|
|
||||||
*/
|
|
||||||
if (path->indexorderbys == NULL || root->limit_tuples < 0 || root->limit_tuples > hnsw_ef_search)
|
|
||||||
{
|
{
|
||||||
*indexStartupCost = DBL_MAX;
|
*indexStartupCost = DBL_MAX;
|
||||||
*indexTotalCost = DBL_MAX;
|
*indexTotalCost = DBL_MAX;
|
||||||
@@ -97,6 +94,20 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do not use index if limit + offset > ef_search unless enable_seqscan =
|
||||||
|
* off
|
||||||
|
*/
|
||||||
|
if (root->limit_tuples > hnsw_ef_search)
|
||||||
|
{
|
||||||
|
*indexStartupCost = 1.0e10 - 1;
|
||||||
|
*indexTotalCost = 1.0e10 - 1;
|
||||||
|
*indexSelectivity = 0;
|
||||||
|
*indexCorrelation = 0;
|
||||||
|
*indexPages = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MemSet(&costs, 0, sizeof(costs));
|
MemSet(&costs, 0, sizeof(costs));
|
||||||
|
|
||||||
index = index_open(path->indexinfo->indexoid, NoLock);
|
index = index_open(path->indexinfo->indexoid, NoLock);
|
||||||
|
|||||||
@@ -23,11 +23,10 @@ sub insert_vectors
|
|||||||
|
|
||||||
sub test_duplicates
|
sub test_duplicates
|
||||||
{
|
{
|
||||||
# TODO Improve
|
|
||||||
my $res = $node->safe_psql("postgres", qq(
|
my $res = $node->safe_psql("postgres", qq(
|
||||||
SET enable_seqscan = off;
|
SET enable_seqscan = off;
|
||||||
SET hnsw.ef_search = 10;
|
SET hnsw.ef_search = 1;
|
||||||
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]' LIMIT 10) t;
|
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]' LIMIT 20) t;
|
||||||
));
|
));
|
||||||
is($res, 10);
|
is($res, 10);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user