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

Started by ZizhuanLiu X-MAN8 days ago3 messageshackers
Jump to latest
#1ZizhuanLiu X-MAN
44973863@qq.com

Hi, Hackers
`
While reviewing commit cf6723 (Make transformAExprIn() return a flattened bool expression directly), 
I found several near-duplicate function implementations in makefuncs.c that can be refactored to 
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(), 
  aligning their implementation style with the existing makeAndExpr() / makeOrExpr() / makeNotExpr() logic in gram.y.
  This eliminates redundant duplicate code for boolean clause construction.
- makeSimpleA_Expr() --> makeA_Expr(): Remove the trivial wrapper function and use the core makeA_Expr() directly to
  simplify expression building logic.
- makeDefElemExtended() --> makeDefElem(): Remove the extended wrapper and adopt standard makeDefElem() uniformly for  
  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:
  - make_andclause() --> makeBoolExpr(): SELECT * FROM t1 WHERE id = 1 AND id = 3;
  - make_orclause() -->  makeBoolExpr(): SELECT * FROM t1 WHERE id = 1 OR id = 3;
  - make_notclause() --> 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@qq.com

Attachments:

v1-0001-Little-refactoring-of-makefuncs.c.patchapplication/octet-stream; charset=utf-8; name=v1-0001-Little-refactoring-of-makefuncs.c.patchDownload+7-31
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: ZizhuanLiu X-MAN (#1)
Re: [PATCH]Refactor and unify expression construction functions in makefuncs.c

"=?utf-8?B?Wml6aHVhbkxpdSBYLU1BTg==?=" <44973863@qq.com> writes:

This patch performs a set of minor, low-impact clean-up refactors to unify internal expression construction logic:

TBH, I don't think this is worth the trouble.

regards, tom lane

#3ZizhuanLiu X-MAN
44973863@qq.com
In reply to: Tom Lane (#2)
Re: [PATCH]Refactor and unify expression construction functions in makefuncs.c

&gt;From: Tom Lane <tgl@sss.pgh.pa.us&gt;
&gt;Date: 2026-06-01 11:56
&gt;To: ZizhuanLiu X-MAN <44973863@qq.com&gt;
&gt;Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org&gt;
&gt;Subject: Re: [PATCH]Refactor and unify expression construction functions in makefuncs.c
&gt;
&gt;
&gt; &nbsp; &nbsp; &nbsp;"=?utf-8?B?Wml6aHVhbkxpdSBYLU1BTg==?="?<44973863@qq.com&gt;?writes:
&gt;&gt;?This?patch?performs?a?set?of?minor,?low-impact?clean-up?refactors?to?unify?internal?expression?construction?logic:
&gt;
&gt;TBH, I don't think this is worth the trouble.
&gt;
&gt;                 regards, tom lane

Thanks,&nbsp; you're right.&nbsp; Let's drop this idea for now.
`
regards,
--
ZizhuanLiu&nbsp;(X-MAN)&nbsp;
44973863@qq.com