postgres.git / summary / log / commit / refs

commit    51ae11c51699ba6bc69c793485cffdd693e2b735
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Wed Nov 11 22:44:53 2026 +0000
First released in: 19.0

    Fix incorrect early exit from contain_mutable_functions_walker.
    
    Given a JsonExpr.path_spec that is a null constant,
    contain_mutable_functions_walker immediately returned false, failing
    to check for other sources of mutability elsewhere in the JsonExpr.
    It must only skip the jspIsMutable() test in this case.
    
    While here, remove a couple of redundant castNode calls (I'm not
    a fan of using that directly after an explicit IsA check).
    
    Bug: #19840
    Reported-by: chunling qin <303677365@qq.com>
    Author: Tom Lane <tgl@sss.pgh.pa.us>
    Discussion: https://postgr.es/m/19840-7d5243be84d7ecd3@postgresql.org
    Backpatch-through: 17


src/backend/optimizer/util/clauses.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index e94ec54549e..7b1b5f86a9c 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -429,26 +429,26 @@ contain_mutable_functions_walker(Node *node, void *context) return true; } - /* Check all subnodes */ + /* Fall through to check subnodes */ } if (IsA(node, JsonExpr)) { - JsonExpr *jexpr = castNode(JsonExpr, node); + JsonExpr *jexpr = (JsonExpr *) node; Const *cnst; + /* If non-constant path_spec, must treat as mutable */ if (!IsA(jexpr->path_spec, Const)) return true; - cnst = castNode(Const, jexpr->path_spec); - + cnst = (Const *) jexpr->path_spec; Assert(cnst->consttype == JSONPATHOID); - if (cnst->constisnull) - return false; - - if (jspIsMutable(DatumGetJsonPathP(cnst->constvalue), + if (!cnst->constisnull && + jspIsMutable(DatumGetJsonPathP(cnst->constvalue), jexpr->passing_names, jexpr->passing_values)) return true; + + /* Fall through to check subnodes */ } if (IsA(node, SQLValueFunction)) [parent: 52cb12240cd0]