diff --git a/src/hnsw.c b/src/hnsw.c index 2b6d8b1..bd05719 100644 --- a/src/hnsw.c +++ b/src/hnsw.c @@ -207,7 +207,7 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, get_tablespace_page_costs(path->indexinfo->reltablespace, NULL, &spc_seq_page_cost); /* Adjust cost if needed since TOAST not included in seq scan cost */ - if (costs.numIndexPages > path->indexinfo->rel->pages) + if (costs.numIndexPages > path->indexinfo->rel->pages && costs.numIndexTuples / (path->indexinfo->tuples + 1) < 0.5) { /* Change all page cost from random to sequential */ costs.indexTotalCost -= costs.numIndexPages * (costs.spc_random_page_cost - spc_seq_page_cost);