Allow override

This commit is contained in:
Andrew Kane
2024-01-20 17:07:36 -08:00
parent 57d5d07ef9
commit ac79f79637
2 changed files with 18 additions and 8 deletions

View File

@@ -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);

View File

@@ -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);
} }