Re: BUG #18854: PostgreSQL chooses a suboptimal execution plan when using a specific WHERE filter

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: Yoni Sade <yonisade83(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18854: PostgreSQL chooses a suboptimal execution plan when using a specific WHERE filter
Date: 2025-03-20 19:50:51
Message-ID: 31635fee-f260-49a4-81d3-8f684efdabd3@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 19/3/2025 14:34, Yoni Sade wrote:
> I would like to add that commenting out that WHERE clause doesn't work
> for all of this query variations so I've found another workaround for
> now ("LIMIT 1000000" in *bold*)
>
> to make the optimizer better estimate the cardinality of the subquery
> and change the plan to a better one:*
I wouldn't say it is the ultimate root of the problem, but using
generate_series, especially with non-constant parameters, seems harmful
for the query planning: we can't predict the number of tuples and don't
have any statistics on that set. So, your LIMIT works like a hint that
helps decide how massive a set of tuples it will generate and seems to
be the only option possible.

--
regards, Andrei Lepikhov

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-03-21 04:46:51 BUG #18860: Test src/test/recovery/t/039_end_of_wal.pl is unstable
Previous Message Ben Caspi 2025-03-20 15:14:13 PostgreSQL v15.12 fails to perform PG_UPGRADE from v13 and v9 on Windows