Re: Unfortunate pushing down of expressions below sort

From: Chengpeng Yan <chengpeng_yan(at)Outlook(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, David Rowley <dgrowleyml(at)gmail(dot)com>
Subject: Re: Unfortunate pushing down of expressions below sort
Date: 2026-02-11 14:17:01
Message-ID: 13636E54-C27A-4A49-926D-B9E3EBAA8A10@Outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I've attached v2 of the patch.

Changes since v1:
- No planner logic changes.
- Fixed one regression-test fallout in contrib/postgres_fdw by updating
expected EXPLAIN output. With the planner change, the deparsed remote
SQL can omit a redundant constant there, so GROUP BY positional
references shift accordingly; query results are unchanged.

Behavior is unchanged from v1:
- Postpone additional non-sort target expressions only when doing so
does not require carrying any extra Vars/PlaceHolderVars through Sort.
- Existing volatile/SRF/expensive-expression behavior is unchanged.

Validation:
- make check-world passes.

Would especially appreciate feedback on whether the “no extra Vars/PHVs
through sort” rule is the right safety boundary.

Thanks!

--
Best regards,
Chengpeng Yan

Attachment Content-Type Size
v2-0001-planner-postpone-some-non-sort-output-expressions.patch application/octet-stream 21.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-02-11 14:18:39 Re: Add CREATE SCHEMA ... LIKE support
Previous Message Thomas Munro 2026-02-11 14:06:29 Re: Do we still need MULE_INTERNAL?