Re: Unfortunate pushing down of expressions below sort

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgresql.org, David Rowley <dgrowleyml@gmail.com>
Date: 2026-02-06T01:02:31Z
Lists: pgsql-hackers
I wrote:
> Yeah.  That's a hangover from an ancient decision that sort/limit
> would always be applied at the top of the plan tree.  I'm too
> lazy to check the details right now, but I think we already relaxed
> that in some cases (or maybe it was about evaluating stuff
> before/after GROUP BY?).

Ah, right: see make_sort_input_target() and its very extensive
comment in planner.c.  I wonder why that didn't trigger in
your example.

			regards, tom lane