[PATCH]Refactor and unify expression construction functions in makefuncs.c

From: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: 我自己的邮箱 <44973863(at)qq(dot)com>
Subject: [PATCH]Refactor and unify expression construction functions in makefuncs.c
Date: 2026-06-01 02:45:29
Message-ID: tencent_99476336BC701B21ADDC44E2B7BE25147506@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Hackers
`
While reviewing commit cf6723 (Make transformAExprIn() return a flattened bool expression directly),&nbsp;
I found several near-duplicate function implementations in makefuncs.c that can be refactored to&nbsp;
simplify and clean up the codebase.
`
This patch performs a set of minor, low-impact clean-up refactors to unify internal expression construction logic:
- make_andclause() / make_orclause() / make_notclause(): Rework these functions to directly call makeBoolExpr(),&nbsp;
&nbsp; aligning their implementation style with the existing makeAndExpr() / makeOrExpr() / makeNotExpr() logic in gram.y.
&nbsp; This eliminates redundant duplicate code for boolean clause construction.
- makeSimpleA_Expr() --&gt; makeA_Expr(): Remove the trivial wrapper function and use the core makeA_Expr() directly to
&nbsp; simplify expression building logic.
- makeDefElemExtended() --&gt; makeDefElem(): Remove the extended wrapper and adopt standard makeDefElem() uniformly for &nbsp;
&nbsp; definition element construction.
`
All changes are pure code cleanup with zero functional change.
The patch has minimal code intrusion, only optimizing internal function call chains without altering runtime behavior.
`
Test cases are added for every refactored function to guarantee correctness and prevent regression:
&nbsp; - make_andclause() --&gt; makeBoolExpr(): SELECT * FROM t1 WHERE id = 1 AND id = 3;
&nbsp; - make_orclause() --&gt; &nbsp;makeBoolExpr(): SELECT * FROM t1 WHERE id = 1 OR id = 3;
&nbsp; - make_notclause() --&gt; makeBoolExpr(): SELECT * FROM t1 WHERE id NOT IN (1);
&nbsp; - makeSimpleA_Expr() --&gt; makeA_Expr(): SELECT oid::integer+1 FROM pg_class WHERE oid::integer+1 < 100;
&nbsp; - makeDefElemExtended() --&gt; makeDefElem():&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432');
&nbsp; &nbsp; &nbsp; ALTER SERVER myserver OPTIONS (DROP port);
`
All newly added tests pass successfully, verifying that the refactoring is safe, consistent and introduces no behavioral changes.

Thanks,
--
ZizhuanLiu&nbsp;(X-MAN)&nbsp;
44973863(at)qq(dot)com

Attachment Content-Type Size
v1-0001-Little-refactoring-of-makefuncs.c.patch application/octet-stream 2.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-06-01 02:47:03 Re: Row pattern recognition
Previous Message Henson Choi 2026-06-01 02:29:21 Re: Row pattern recognition