pgvector.git / summary / log / commit / refs
commit a33e72d58e51947cc1346b739aaed2a7da5cd9e9
Author: Andrew Kane <andrew@ankane.org>
Date: Sat Jun 10 09:10:53 2023 +0000
Always change some cost to sequential, and always update total cost
src/ivfflat.c | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/src/ivfflat.c b/src/ivfflat.c
index 832d8056..196b763b 100644
--- a/src/ivfflat.c
+++ b/src/ivfflat.c
@@ -71,8 +71,8 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
int lists;
double ratio;
double spc_seq_page_cost;
+ double seqPageRatio = 0.5;
Relation indexRel;
- Cost startupCost;
#if PG_VERSION_NUM < 120000
List *qinfos;
#endif
@@ -115,25 +115,17 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
get_tablespace_page_costs(path->indexinfo->reltablespace, NULL, &spc_seq_page_cost);
- /* Use total cost since most work happens before first tuple is returned */
- startupCost = costs.indexTotalCost;
+ /* Change some page cost from random to sequential */
+ costs.indexTotalCost -= seqPageRatio * costs.numIndexPages * (costs.spc_random_page_cost - spc_seq_page_cost);
- if (costs.spc_random_page_cost >= 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)
{
- /* Adjust cost if needed since TOAST not included in seq scan cost */
- if (costs.numIndexPages > path->indexinfo->rel->pages && ratio < 0.5)
- {
- /* Change page cost from random to sequential */
- startupCost -= costs.numIndexPages * (costs.spc_random_page_cost - spc_seq_page_cost);
+ /* Change rest of page cost from random to sequential */
+ costs.indexTotalCost -= (1 - seqPageRatio) * 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);
- }
+ /* Remove cost of extra pages */
+ costs.indexTotalCost -= (costs.numIndexPages - path->indexinfo->rel->pages) * spc_seq_page_cost;
}
/*
@@ -143,7 +135,8 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
if (ratio < costs.indexSelectivity)
costs.indexSelectivity = ratio;
- *indexStartupCost = startupCost;
+ /* Use total cost since most work happens before first tuple is returned */
+ *indexStartupCost = costs.indexTotalCost;
*indexTotalCost = costs.indexTotalCost;
*indexSelectivity = costs.indexSelectivity;
*indexCorrelation = costs.indexCorrelation;
[parent: 49e6a72d361e]