Re: BUG #17564: Planner bug in combination of generate_series(), unnest() and ORDER BY

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)gmail(dot)com>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17564: Planner bug in combination of generate_series(), unnest() and ORDER BY
Date: 2022-08-03 21:53:30
Message-ID: 3243867.1659563610@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Martijn van Oosterhout <kleptog(at)gmail(dot)com> writes:
> The part I haven't seen explained is why the generate_series() is
> important. My guess is that if you replace it with an expression it is no
> longer an SRF and it produces some completely different plan that prevents
> the problematic path being triggered.

I think the generate_series() forces a ProjectSet to be put atop the
join, where we'd probably not have done that without it, having made
the bogus assumption that we could evaluate the sort-key SRF at scan
level. Why that changes the costs enough to mask or not mask the bug
is still obscure.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Richard Guo 2022-08-04 01:05:13 Re: BUG #17564: Planner bug in combination of generate_series(), unnest() and ORDER BY
Previous Message Tom Lane 2022-08-03 21:44:17 Re: BUG #17564: Planner bug in combination of generate_series(), unnest() and ORDER BY