diff options
author | Robert Haas <rhaas@postgresql.org> | 2024-07-22 14:57:53 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2024-07-22 14:57:53 -0400 |
commit | e4326fbc60c44aab6df5849d3d67a0cba4c71cf2 (patch) | |
tree | aeb92879cd96545e37c5724c7ff8b91cfc2c72fc /src/backend/optimizer/path/costsize.c | |
parent | c0348fd0e389c89003f309918705d1daea2217b0 (diff) |
Remove grotty use of disable_cost for TID scan plans.
Previously, the code charged disable_cost for CurrentOfExpr, and then
subtracted disable_cost from the cost of a TID path that used
CurrentOfExpr as the TID qual, effectively disabling all paths except
that one. Now, we instead suppress generation of the disabled paths
entirely, and generate only the one that the executor will actually
understand.
With this approach, we do not need to rely on disable_cost being
large enough to prevent the wrong path from being chosen, and we
save some CPU cycle by avoiding generating paths that we can't
actually use. In my opinion, the code is also easier to understand
like this.
Patch by me. Review by Heikki Linnakangas.
Discussion: http://postgr.es/m/591b3596-2ea0-4b8e-99c6-fad0ef2801f5@iki.fi
Diffstat (limited to 'src/backend/optimizer/path/costsize.c')
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 26 |
1 files changed, 0 insertions, 26 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index ee23ed7835d..2021c481b46 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -1251,7 +1251,6 @@ cost_tidscan(Path *path, PlannerInfo *root, { Cost startup_cost = 0; Cost run_cost = 0; - bool isCurrentOf = false; QualCost qpqual_cost; Cost cpu_per_tuple; QualCost tid_qual_cost; @@ -1287,7 +1286,6 @@ cost_tidscan(Path *path, PlannerInfo *root, else if (IsA(qual, CurrentOfExpr)) { /* CURRENT OF yields 1 tuple */ - isCurrentOf = true; ntuples++; } else @@ -1298,22 +1296,6 @@ cost_tidscan(Path *path, PlannerInfo *root, } /* - * We must force TID scan for WHERE CURRENT OF, because only nodeTidscan.c - * understands how to do it correctly. Therefore, honor enable_tidscan - * only when CURRENT OF isn't present. Also note that cost_qual_eval - * counts a CurrentOfExpr as having startup cost disable_cost, which we - * subtract off here; that's to prevent other plan types such as seqscan - * from winning. - */ - if (isCurrentOf) - { - Assert(baserel->baserestrictcost.startup >= disable_cost); - startup_cost -= disable_cost; - } - else if (!enable_tidscan) - startup_cost += disable_cost; - - /* * The TID qual expressions will be computed once, any other baserestrict * quals once per retrieved tuple. */ @@ -1399,9 +1381,6 @@ cost_tidrangescan(Path *path, PlannerInfo *root, ntuples = selectivity * baserel->tuples; nseqpages = pages - 1.0; - if (!enable_tidscan) - startup_cost += disable_cost; - /* * The TID qual expressions will be computed once, any other baserestrict * quals once per retrieved tuple. @@ -4884,11 +4863,6 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context) /* Treat all these as having cost 1 */ context->total.per_tuple += cpu_operator_cost; } - else if (IsA(node, CurrentOfExpr)) - { - /* Report high cost to prevent selection of anything but TID scan */ - context->total.startup += disable_cost; - } else if (IsA(node, SubLink)) { /* This routine should not be applied to un-planned expressions */ |