Skip to content

Commit b52f3db

Browse files
committed
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
1 parent 1db7119 commit b52f3db

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/backend/optimizer/util/clauses.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,26 +445,26 @@ contain_mutable_functions_walker(Node *node, void *context)
445445
return true;
446446
}
447447

448-
/* Check all subnodes */
448+
/* Fall through to check subnodes */
449449
}
450450

451451
if (IsA(node, JsonExpr))
452452
{
453-
JsonExpr *jexpr = castNode(JsonExpr, node);
453+
JsonExpr *jexpr = (JsonExpr *) node;
454454
Const *cnst;
455455

456+
/* If non-constant path_spec, must treat as mutable */
456457
if (!IsA(jexpr->path_spec, Const))
457458
return true;
458459

459-
cnst = castNode(Const, jexpr->path_spec);
460-
460+
cnst = (Const *) jexpr->path_spec;
461461
Assert(cnst->consttype == JSONPATHOID);
462-
if (cnst->constisnull)
463-
return false;
464-
465-
if (jspIsMutable(DatumGetJsonPathP(cnst->constvalue),
462+
if (!cnst->constisnull &&
463+
jspIsMutable(DatumGetJsonPathP(cnst->constvalue),
466464
jexpr->passing_names, jexpr->passing_values))
467465
return true;
466+
467+
/* Fall through to check subnodes */
468468
}
469469

470470
if (IsA(node, SQLValueFunction))

0 commit comments

Comments
 (0)