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

From: 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-10-29 01:19:00
Message-ID: F385991A-6880-4FF6-A32D-B4369BA04ADC@quwin.dev
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> Hi Zhenglong,
> This is another review of CF 7186 v1 [1].
>
> Contents & Purpose
> ==================
> The patch treats JsonExpr as non-strict so that outer-join pull-up and
> STRICT SQL-function inlining preserves NULL semantics. It includes a
> regression test for the outer-join case.
>
> Initial Run
> ==================
> The patch applies cleanly to HEAD. Baseline and patched
> builds each pass all 239 core tests, and the patched build passes all 582
> make installcheck-world tests. TAP was disabled; PL/Perl, PL/Python and
> SSL was not configured.
>
> Performance
> ==================
> The conservative check prevents the safe inlining of a context-only wrapper:
>
> CREATE FUNCTION value_ctx(text) RETURNS text
> LANGUAGE sql IMMUTABLE STRICT
> AS SELECTJSONVALUE($1::jsonb,'$');
>
> SELECT sum(length(value_ctx(doc))) FROM perf;
>
> With 100,000 rows, median tested execution time increased
> from 34.9 ms to 137.3 ms, about 3.93x on macOS with JIT and parallelism
> off.
>
> Nitpicking & Conclusion
> ==================
> Nit: could you add a STRICT-inlining regression test alongside the outer-join
> test? For example:
>
> CREATE TEMP TABLE args(x integer);
> INSERT INTO args VALUES (NULL), (1);
> CREATE FUNCTION pg_temp.f(integer) RETURNS text
> LANGUAGE sql IMMUTABLE STRICT
> AS SELECTJSONVALUE('1','$'PASSING$1ASp);
>
> SELECT x, pg_temp.f(x) FROM args;
>
> For the NULL row, unpatched master returns '1'; v1 correctly returns NULL.
>
> This approach looks appropriate for the correctness fix.
> Since this is a correctness fix, preserving safe context-only inlining could be a follow-up optimization.
> +1 from me on the approach and the patch.
>
> References
> ==================
> [1] CF 7186, 2026-08-24, [PATCH]Fix planner's strictness check for JsonExpr
> https://www.postgresql.org/message-id/CAD=-kXbK=GGAAK62N-r6tKuU2dVmtJ4GvHTr=CJJGHczuuUGCQ@mail.gmail.com
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2026-10-29 01:36:09 Re: [PG19] Wrong results from Memoize with a nondeterministic collation
Previous Message Keyerror Smart 2026-10-29 01:16:52 Re: [PATCH] Consider window functions when reordering GROUP BY items