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

From: Ethan Tran <ethantran(at)quwin(dot)dev>
To: Keyerror Smart <smartkeyerror(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH]Fix planner's strictness check for JsonExpr
Date: 2026-11-04 23:05:00
Message-ID: E8366FAC-9216-4FE7-B436-B2F4A99441B7@quwin.dev
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Zhenglong,

I found one remaining correctness issue involving result-domain coercion:
> ExecInitJsonExpr() returns NULL as soon as the context item or the
> path specification evaluates to NULL
Result coercion still runs after that shortcut. A RETURNING domain with
NOT NULL can reject NULL and invoke EMPTY ARRAY ON ERROR, producing [].

With v2, the attached reproducer returns [] for a NULL argument to an
inlined STRICT wrapper; preventing inlining returns SQL NULL.
Outer-join pull-up has the same problem.

In local testing, a conservative domain guard fixes these cases, but also
disables some safe inlining. An unconstrained-domain JSON_QUERY wrapper went
from about 35 ms to 196 ms over 100,000 rows (5.6x), while direct-expression
timings remained comparable.

Should we preserve unconstrained-domain inlining, with cached plans rebuilt
if constraints are added to the domain or its parents?

Thanks,
Ethan

Attached: domain-reproducer.sql



In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Peter Smith 2026-11-04 23:00:03 Re: Proposal: Conflict log history table for Logical Replication