From: | Alex <cdalxndr(at)yahoo(dot)com> |
---|---|
To: | David Rowley <dgrowleyml(at)gmail(dot)com> |
Cc: | Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-performance <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: 15x slower PreparedStatement vs raw query |
Date: | 2021-05-05 15:21:30 |
Message-ID: | 416718045.765440.1620228090971@mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
This is exactly my issue.
Using raw query, planning takes 22ms (custom plan), but using PreparedStatement planning takes 11ms (generic plan).It choose the faster generic plan 11ms, wining 11ms faster than custom plan, but loosing 14seconds!!! to execution...
The auto choose algorithm should be changed to include execution time in the decision.
On Wednesday, May 5, 2021, 9:57:20 AM GMT+3, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
On Tue, 4 May 2021 at 22:05, Alex <cdalxndr(at)yahoo(dot)com> wrote:
> Shouldn't this process be automatic based on some heuristics?
When plan_cache_mode is set to "auto", then the decision to use a
generic or custom plan is cost-based. See [1]. There's a fairly crude
method there for estimating the effort required to replan the query.
The remainder is based on the average cost of the previous custom
plans + estimated planning effort vs cost of the generic plan. The
cheaper one wins.
Certainly, what's there is far from perfect. There are various
problems with it. The estimated planning cost is pretty crude and
could do with an overhaul. There are also issues with the plan costs
not being true to the cost of the query. One problem there is that
run-time partition pruning is not costed into the plan. This might
cause choose_custom_plan() to pick a custom plan when a generic one
with run-time pruning might have been better.
In order to get a better idea of where things are going wrong for you,
we'd need to see the EXPLAIN ANALYZE output for both the custom and
the generic plan.
David
[1] https://github.com/postgres/postgres/blob/master/src/backend/utils/cache/plancache.c#L1019
From | Date | Subject | |
---|---|---|---|
Next Message | Semen Yefimenko | 2021-05-06 14:38:39 | Very slow Query compared to Oracle / SQL - Server |
Previous Message | Justin Pryzby | 2021-05-05 06:59:19 | Re: 15x slower PreparedStatement vs raw query |