diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 85ee860a136..3302efc5b4b 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -1094,6 +1094,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, diff --git a/src/test/regress/expected/subselect.out b/src/test/regress/expected/subselect.out index e469cee2bab..cc91f0f144b 100644 --- a/src/test/regress/expected/subselect.out +++ b/src/test/regress/expected/subselect.out @@ -1671,6 +1671,34 @@ fetch backward all in c1; commit; -- +-- Check that JsonConstructorExpr is treated as non-strict, and thus can be +-- wrapped in a PlaceHolderVar +-- +begin; +create temp table json_tab (a int); +insert into json_tab values (1); +explain (verbose, costs off) +select * from json_tab t1 left join (select json_array(1, a) from json_tab t2) s on false; + QUERY PLAN +--------------------------------------------------- + Nested Loop Left Join + Output: t1.a, (JSON_ARRAY(1, a RETURNING json)) + Join Filter: false + -> Seq Scan on pg_temp.json_tab t1 + Output: t1.a + -> Result + Output: JSON_ARRAY(1, a RETURNING json) + One-Time Filter: false +(8 rows) + +select * from json_tab t1 left join (select json_array(1, a) from json_tab t2) s on false; + a | json_array +---+------------ + 1 | +(1 row) + +rollback; +-- -- Verify that we correctly flatten cases involving a subquery output -- expression that doesn't need to be wrapped in a PlaceHolderVar -- diff --git a/src/test/regress/sql/subselect.sql b/src/test/regress/sql/subselect.sql index c7385aa0c0e..b674f3870e3 100644 --- a/src/test/regress/sql/subselect.sql +++ b/src/test/regress/sql/subselect.sql @@ -876,6 +876,23 @@ fetch backward all in c1; commit; +-- +-- Check that JsonConstructorExpr is treated as non-strict, and thus can be +-- wrapped in a PlaceHolderVar +-- + +begin; + +create temp table json_tab (a int); +insert into json_tab values (1); + +explain (verbose, costs off) +select * from json_tab t1 left join (select json_array(1, a) from json_tab t2) s on false; + +select * from json_tab t1 left join (select json_array(1, a) from json_tab t2) s on false; + +rollback; + -- -- Verify that we correctly flatten cases involving a subquery output -- expression that doesn't need to be wrapped in a PlaceHolderVar