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.