From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Bruce Momjian <bruce(at)momjian(dot)us>, "Naik, Sameer" <Sameer_Naik(at)bmc(dot)com>, "pgsql-performance(at)lists(dot)postgresql(dot)org" <pgsql-performance(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Generic Plans for Prepared Statement are 158155 times slower than Custom Plans |
Date: | 2019-04-29 16:23:38 |
Message-ID: | 20190429162338.bgpvgh6epwc2rmzu@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Hi,
On 2019-04-29 10:35:39 -0400, Tom Lane wrote:
> This isn't the first time we've seen a plan-choice failure of this sort.
> I've wondered if we should make the plancache simply disbelieve generic
> cost estimates that are actually cheaper than the custom plans, on the
> grounds that they must be estimation errors. In principle a generic
> plan could never really be better than a custom plan; so if it looks
> that way on a cost basis, what that probably means is that the actual
> parameter values are outliers of some sort (e.g. extremely common),
> and the custom plan "knows" that it's going to be taking a hit from
> that, but the generic plan doesn't. In this sort of situation, going
> with the generic plan could be really disastrous, which is exactly
> what the OP is seeing (and what we've seen reported before).
>
> However, I'm not sure how to tune this idea so that it doesn't end up
> rejecting perfectly good generic plans. It's likely that there will be
> some variation in the cost estimates between the generic and specific
> cases, even if the plan structure is exactly the same; and that
> variation could go in either direction.
Yea, I've both seen the "generic is cheaper due to averaged selectivity"
and the "insignificant cost variations lead to always prefer custom
plan" problems in production.
I've also - but less severely - seen that the "planning cost" we add to
the custom plan leads to the generic plan to always be preferred. In
particular for indexed queries, on system that set random_page_cost =
seq_page_cost = 1 (due to SSD or expectation that workload is entirely
cached), the added cost from cached_plan_cost() can be noticable in
comparison to the estimated cost of the total query.
Greetings,
Andres Freund
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2019-04-29 16:51:36 | Re: Generic Plans for Prepared Statement are 158155 times slower than Custom Plans |
Previous Message | Tom Lane | 2019-04-29 14:35:39 | Re: Generic Plans for Prepared Statement are 158155 times slower than Custom Plans |