From b63a822452152a7bd613fd4b28e0967e626e274e Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Tue, 16 Sep 2025 18:42:20 +0900 Subject: Treat JsonConstructorExpr as non-strict JsonConstructorExpr can produce non-NULL output with a NULL input, so it should be treated as a non-strict construct. Failing to do so can lead to incorrect query behavior. For example, in the reported case, when pulling up a subquery that is under an outer join, if the subquery's target list contains a JsonConstructorExpr that uses subquery variables and it is mistakenly treated as strict, it will be pulled up without being wrapped in a PlaceHolderVar. As a result, the expression will be evaluated at the wrong place and will not be forced to null when the outer join should do so. Back-patch to v16 where JsonConstructorExpr was introduced. Bug: #19046 Reported-by: Runyuan He Author: Tender Wang Co-authored-by: Richard Guo Discussion: https://postgr.es/m/19046-765b6602b0a8cfdf@postgresql.org Backpatch-through: 16 --- src/backend/optimizer/util/clauses.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/backend/optimizer/util') diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index ae0bd073ca9..f49bde7595b 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -1115,6 +1115,8 @@ contain_nonstrict_functions_walker(Node *node, void *context) return true; if (IsA(node, BooleanTest)) return true; + if (IsA(node, JsonConstructorExpr)) + return true; /* Check other function-containing nodes */ if (check_functions_in_node(node, contain_nonstrict_functions_checker, -- cgit v1.2.3