Only adjust cost if scanning less than half of the tuples [skip ci]

This commit is contained in:
Andrew Kane
2024-09-28 12:21:20 -07:00
parent 7265927fd6
commit 9b42662188

View File

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