pgvector.git / summary / log / commit / refs
commit 4ce915cf162b91c4f70c8c6683c2a12016e95cca
Author: Andrew Kane <andrew@ankane.org>
Date: Sat Jun 10 04:11:16 2023 +0000
Improved cost estimate - #133
src/ivfflat.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/ivfflat.c b/src/ivfflat.c
index 5c5ff07b..a35f6e81 100644
--- a/src/ivfflat.c
+++ b/src/ivfflat.c
@@ -115,17 +115,22 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
startupCost = costs.indexTotalCost;
+ 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 && ratio < 0.5)
{
- get_tablespace_page_costs(path->indexinfo->reltablespace, NULL, &spc_seq_page_cost);
-
/* Change page cost from random to sequential */
startupCost -= costs.numIndexPages * (costs.spc_random_page_cost - spc_seq_page_cost);
/* Remove cost of extra pages */
startupCost -= (costs.numIndexPages - path->indexinfo->rel->pages) * spc_seq_page_cost;
}
+ else if (ratio < 0.5)
+ {
+ /* Change some page cost from random to sequential */
+ startupCost -= 0.5 * costs.numIndexPages * (costs.spc_random_page_cost - spc_seq_page_cost);
+ }
/*
* If the list selectivity is lower than what is returned from the generic
[parent: 41b766c24bf5]