Re: [PATCH]Fix planner's strictness check for JsonExpr

From: Keyerror Smart <smartkeyerror(at)gmail(dot)com>
To: Tomas Vondra <tomas(at)vondra(dot)me>
Cc: Amit Langote <amitlangote09(at)gmail(dot)com>, ethantran(at)quwin(dot)dev, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH]Fix planner's strictness check for JsonExpr
Date: 2026-11-20 01:55:43
Message-ID: CAD=-kXZRqnOFfumUNwJckaN592zV0xnSS2V7i5TWXKw8YM1=eA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Amit, Tomas,

Thanks, Amit, for the review and the patch.

On Thu, Nov 19, 2026 at 13:40, Amit Langote wrote:
> So we should remove the reference to use_json_coercion from this
> patch, [...] and keep only the get_typtype() test.

Agreed. I hadn't considered that use_json_coercion for JSON_VALUE()
already depends on DomainHasConstraints() at parse time, so the v5
check could go stale in the same way the executor does. Checking only
the type is simpler and doesn't interact with your patch removing the
flag, in master or in the back branches.

> Tomas's 0004 on the other thread does the precise thing [...]
> Attached is a variant of it that applies on top of v5

Attached v6 takes your variant as-is: a JsonExpr is non-strict if it
returns any domain, or if a Var, PlaceHolderVar or Param appears in
its PASSING values or ON EMPTY / ON ERROR expressions (the latter as a
JsonBehavior case in the walker). Changes relative to your diff are
limited to comments, which I've tightened a bit, and the commit
message, which now describes the precise rule.

Tests:

- all of v5's tests are kept unchanged and pass;
- as you suggested, a wrapper RETURNING a domain without constraints
is shown not to be inlined;
- new EXPLAIN tests show that wrappers with a constant PASSING value
and constant DEFAULT ON EMPTY / ON ERROR, with EMPTY ARRAY ON EMPTY,
and a plain JSON_EXISTS() with its implicit FALSE ON ERROR are
inlined again (v5 didn't inline these), together with a check that
they still return NULL for a NULL argument.

The patch is rebased over 72b480e55d7 and applies to REL_18_STABLE and
REL_17_STABLE as well. I've added Amit as a co-author.

On Thu, Nov 19, 2026 at 14:56, Tomas Vondra wrote:
> But if you agree it's correct, we can backpatch, that's fine.

Since the precise check only inspects the node itself, I think it's as
back-patchable as the v5 rule, and it avoids the loss of inlining you
listed earlier, so I went that way.

On Thu, Nov 19, 2026 at 14:46, Tomas Vondra wrote:
> That adds a new walker mimicking
> contain_nonstrict_functions_walker-like, so once we figure out the
> solution here, we should apply the fix to both places.

Right. Once we agree on v6, I can add the same JsonExpr / JsonBehavior
handling to full_join_expr_nonstrict_walker(), with a FULL JOIN test,
either as a 0002 here or folded into 0001 -- whichever you prefer.

Regards,
Zhenglong

Attachment Content-Type Size
v6-0001-Fix-planner-s-strictness-check-for-JsonExpr.patch application/octet-stream 20.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-11-20 01:55:59 Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain
Previous Message Tomas Vondra 2026-11-20 01:54:50 Re: A bug in recovery prefetcher, triggering asserts / FATAL: checkpoint request failed