This is an automated email from the ASF dual-hosted git repository. maxyang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/main by this push: new a7582be845c Fix: initialize FuncExpr.is_tablefunc to false a7582be845c is described below commit a7582be845cf1efd03285034ff4c270449298149 Author: Jianghua Yang <yjhj...@gmail.com> AuthorDate: Wed Aug 20 20:30:51 2025 +0000 Fix: initialize FuncExpr.is_tablefunc to false In simplify_function(), switched to using makeFuncExpr() to construct a FuncExpr node instead of manually allocating it on the stack. This avoids passing an invalid pointer to prosupport routines. Also explicitly initialize the new is_tablefunc field in makeFuncExpr to false. Without initialization, the field contained random values, which could lead to unpredictable behavior during expression simplification. --- src/backend/nodes/copyfuncs.c | 2 +- src/backend/nodes/makefuncs.c | 1 + src/backend/nodes/outfuncs.c | 2 +- src/backend/nodes/readfuncs.c | 3 +-- src/backend/optimizer/util/clauses.c | 22 ++++++++-------------- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 7dcead7c499..3a9fd32741d 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -2203,8 +2203,8 @@ _copyFuncExpr(const FuncExpr *from) COPY_SCALAR_FIELD(funccollid); COPY_SCALAR_FIELD(inputcollid); COPY_NODE_FIELD(args); - COPY_SCALAR_FIELD(is_tablefunc); COPY_LOCATION_FIELD(location); + COPY_SCALAR_FIELD(is_tablefunc); return newnode; } diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index 946cdfa6717..fcb37bfd8da 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -534,6 +534,7 @@ makeFuncExpr(Oid funcid, Oid rettype, List *args, funcexpr->inputcollid = inputcollid; funcexpr->args = args; funcexpr->location = -1; + funcexpr->is_tablefunc = false; return funcexpr; } diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 6b21ff93654..b27ca507c65 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -1469,8 +1469,8 @@ _outFuncExpr(StringInfo str, const FuncExpr *node) WRITE_OID_FIELD(funccollid); WRITE_OID_FIELD(inputcollid); WRITE_NODE_FIELD(args); - WRITE_BOOL_FIELD(is_tablefunc); /* GPDB */ WRITE_LOCATION_FIELD(location); + WRITE_BOOL_FIELD(is_tablefunc); /* GPDB */ } static void diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index cfe4c8d1d01..5f1bbacfa91 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -749,9 +749,8 @@ _readFuncExpr(void) READ_OID_FIELD(funccollid); READ_OID_FIELD(inputcollid); READ_NODE_FIELD(args); - READ_BOOL_FIELD(is_tablefunc); /* GPDB */ READ_LOCATION_FIELD(location); - + READ_BOOL_FIELD(is_tablefunc); /* GPDB */ READ_DONE(); } diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 1fd03a05e87..2669f2c3017 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -4153,29 +4153,23 @@ simplify_function(Oid funcid, Oid result_type, int32 result_typmod, * function is actually being invoked. */ SupportRequestSimplify req; - FuncExpr fexpr; - - fexpr.xpr.type = T_FuncExpr; - fexpr.funcid = funcid; - fexpr.funcresulttype = result_type; - fexpr.funcretset = func_form->proretset; - fexpr.funcvariadic = funcvariadic; - fexpr.funcformat = COERCE_EXPLICIT_CALL; - fexpr.funccollid = result_collid; - fexpr.inputcollid = input_collid; - fexpr.args = args; - fexpr.location = -1; + FuncExpr *fexpr = makeFuncExpr(funcid, result_type, args, + result_collid, input_collid, + COERCE_EXPLICIT_CALL); + + fexpr->funcvariadic = funcvariadic; + fexpr->funcretset = func_form->proretset; req.type = T_SupportRequestSimplify; req.root = context->root; - req.fcall = &fexpr; + req.fcall = fexpr; newexpr = (Expr *) DatumGetPointer(OidFunctionCall1(func_form->prosupport, PointerGetDatum(&req))); /* catch a possible API misunderstanding */ - Assert(newexpr != (Expr *) &fexpr); + Assert(newexpr != (Expr *) fexpr); } if (!newexpr && allow_non_const) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org For additional commands, e-mail: commits-h...@cloudberry.apache.org