pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Treat JsonConstructorExpr as non-strict
Date: Tue, 16 Sep 2025 09:42:52 +0000
Message-ID: <E1uySD5-000z2i-25@gemulon.postgresql.org> (raw)

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 <runyuan@berkeley.edu>
Author: Tender Wang <tndrwang@gmail.com>
Co-authored-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/19046-765b6602b0a8cfdf@postgresql.org
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b63a822452152a7bd613fd4b28e0967e626e274e

Modified Files
--------------
src/backend/optimizer/util/clauses.c    |  2 ++
src/test/regress/expected/subselect.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 47 insertions(+)



view thread (4+ messages)  latest in thread

Message-ID: <E1uySD5-000z2i-25@gemulon.postgresql.org>
Permalink:  ../E1uySD5-000z2i-25@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uySD5-000z2i-25@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: rguo@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Treat JsonConstructorExpr as non-strict
  In-Reply-To: <E1uySD5-000z2i-25@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox