Re: unstable query plan on pg 16,17,18 - Mailing list pgsql-performance

From Attila Soki
Subject Re: unstable query plan on pg 16,17,18
Date
Msg-id 1695A676-062B-47C5-B302-91E2357DC874@gmx.net
Whole thread Raw
In response to Re: unstable query plan on pg 16,17,18  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: unstable query plan on pg 16,17,18
List pgsql-performance
> On 23 Feb 2026, at 10:41, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> On Mon, 2026-02-23 at 10:37 +0100, Attila Soki wrote:
>> When upgrading from PostgreSQL 14.4, I noticed that one of my somewhat complex
>> analytical queries sometimes gets an inefficient plan under PostgreSQL 16, 17, and 18.
>> Under 14.4, the query runs with a stable plan and completes in 19 to 22 seconds.
>> In newer versions, the plan seems to be unstable, sometimes the query completes
>> in 17 to 20 seconds, sometimes it runs for 5 to 18 minutes with the inefficient plan.
>> This also happens even if the data is not significantly changed.
>
> This is very likely owing to a bad estimate.
>
> Could you turn on "track_io_timing" and send us the EXPLAIN (ANALYZE, BUFFERS) output
> for both the good and the bad plan?

Hi Laurenz,

Thank you for your reply. Here are the two explains.
In order to be able to publish the plans here, I have obfuscated the table and field names, but this is reversible, so
Ican provide more info if needed. 

plan-ok:
https://explain.depesz.com/s/hQvM

plan-wrong:
https://explain.depesz.com/s/uLvl

Best regards,
Attila




pgsql-performance by date:

Previous
From: Lea Führer
Date:
Subject: MERGE INTO... WHEN NOT MATCHED BY SOURCE index usage
Next
From: Andrei Lepikhov
Date:
Subject: Re: unstable query plan on pg 16,17,18