mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-01 02:02:10 +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;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Never use index without order or limit, or if limit + offset >
|
||||
* ef_search
|
||||
*/
|
||||
if (path->indexorderbys == NULL || root->limit_tuples < 0 || root->limit_tuples > hnsw_ef_search)
|
||||
/* Never use index without order or limit */
|
||||
if (path->indexorderbys == NULL || root->limit_tuples < 0)
|
||||
{
|
||||
*indexStartupCost = DBL_MAX;
|
||||
*indexTotalCost = DBL_MAX;
|
||||
@@ -97,6 +94,20 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
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));
|
||||
|
||||
index = index_open(path->indexinfo->indexoid, NoLock);
|
||||
|
||||
@@ -23,11 +23,10 @@ sub insert_vectors
|
||||
|
||||
sub test_duplicates
|
||||
{
|
||||
# TODO Improve
|
||||
my $res = $node->safe_psql("postgres", qq(
|
||||
SET enable_seqscan = off;
|
||||
SET hnsw.ef_search = 10;
|
||||
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]' LIMIT 10) t;
|
||||
SET hnsw.ef_search = 1;
|
||||
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]' LIMIT 20) t;
|
||||
));
|
||||
is($res, 10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user