Skip to content

Commit 7d0e4ad

Browse files
author
hackorum
committed
Apply cost_EXISTS_SUBLINKs_as_half_total_cost.patch
1 parent b597835 commit 7d0e4ad

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/backend/optimizer/path/costsize.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4753,8 +4753,13 @@ cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
47534753

47544754
if (subplan->subLinkType == EXISTS_SUBLINK)
47554755
{
4756-
/* we only need to fetch 1 tuple; clamp to avoid zero divide */
4757-
sp_cost.per_tuple += plan_run_cost / clamp_row_est(plan->plan_rows);
4756+
/*
4757+
* We do only need to fetch 1 tuple, however, finding that 1 tuple
4758+
* may not be proportional to plan_run_cost / plan->plan_rows, so we
4759+
* play it safe here and assume the subplan will need to incur 50%
4760+
* of it's total cost to supply us with the first tuple.
4761+
*/
4762+
sp_cost.per_tuple += 0.50 * plan_run_cost;
47584763
}
47594764
else if (subplan->subLinkType == ALL_SUBLINK ||
47604765
subplan->subLinkType == ANY_SUBLINK)

0 commit comments

Comments
 (0)