Re: [Bug][Ver 11]: Generic query plan selected is worse than custom query plan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Malay Keshav <malay(dot)keshav(at)databricks(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, "malay(dot)keshav(at)gmail(dot)com" <malay(dot)keshav(at)gmail(dot)com>
Subject: Re: [Bug][Ver 11]: Generic query plan selected is worse than custom query plan
Date: 2022-09-29 19:58:02
Message-ID: 347704.1664481482@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-sql

Malay Keshav <malay(dot)keshav(at)databricks(dot)com> writes:
> In our particular case, the Postgres engine decided to pick the generic
> query plan and cache it for all further calls with that query. My
> understanding was that the generic query plan would only be selected if it
> had a better execution time than the custom query plan. Which in our case
> is not true.

> We were able to reproduce this deterministically using the same query
> parameters to trigger the engine to pick the bad generic query plan on the
> 6th run (first 5 runs shows the engine used the efficient query plan). Why
> does the engine pick the generic query plan when its execution time is
> worse than the custom query plan? Is this a bug?

Since you've provided precisely zero detail, it's impossible to answer
in any detail, but this is unlikely to be anything we'd call a bug.
What's presumably happening is that the planner's estimate of the cost
of the generic plan comes out less than its estimate of the cost of
a custom plan, but that estimate is faulty. Sure, we'd love to improve
all such situations, but it's not an easy task --- and any changes in that
area would not be something we'd consider back-patching into long-stable
branches.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-09-29 20:16:31 Re: BUG #17625: In PG15 PQsslAttribute returns different values than PG14 when SSL is not in use for the connection
Previous Message Tom Lane 2022-09-29 19:49:58 Re: BUG #17625: In PG15 PQsslAttribute returns different values than PG14 when SSL is not in use for the connection

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2022-10-13 15:44:39 Can we generate a series of tables in a loop and then use another loop to union all?
Previous Message Malay Keshav 2022-09-29 18:33:54 [Bug][Ver 11]: Generic query plan selected is worse than custom query plan