pgsql: Refactor to avoid code duplication in transformPLAssignStmt.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Refactor to avoid code duplication in transformPLAssignStmt.
Date: 2025-09-27 21:18:07
Message-ID: E1v2cIw-000NsY-2u@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Refactor to avoid code duplication in transformPLAssignStmt.

transformPLAssignStmt contained many lines cribbed directly from
transformSelectStmt. I had supposed that we could manage to keep
the two copies in sync, but the bug just fixed in 7504d2be9 shows
that that hope was foolish. Let's refactor so there's just one copy.

The main stumbling block to doing this is that transformPLAssignStmt
has a chunk of custom code that has to run after transformTargetList
but before we potentially modify the tlist further during analysis
of ORDER BY and GROUP BY. Rather than make transformSelectStmt fully
aware of PLAssignStmt processing, I put that code into a callback
function. It still feels a little bit ugly, but it's not too awful,
and surely it's better than a hundred lines of duplicated code.
The steps involved in processing a PLAssignStmt remain exactly
the same as before, just in different places.

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/31027.1758919078@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b0fb2c6aa5a485e28210e13ae5536c1231b1261f

Modified Files
--------------
src/backend/parser/analyze.c | 207 ++++++++++++++++-----------------------
src/tools/pgindent/typedefs.list | 1 +
2 files changed, 84 insertions(+), 124 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-09-28 23:58:31 pgsql: Add support for tracking of entry count in pgstats
Previous Message Tom Lane 2025-09-27 18:29:56 pgsql: Fix missed copying of groupDistinct in transformPLAssignStmt.