Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY

From: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: zengman <zengman(at)halodbtech(dot)com>, syzhong16 <syzhong16(at)gmail(dot)com>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>, Amit Langote <amitlangote09(at)gmail(dot)com>
Subject: Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY
Date: 2026-09-28 04:03:36
Message-ID: CAB8bMiua3O8ZA1YHzQQYNLeDg+Pyom-XoiDx4_Z_QoA8WCu7Rw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

сб, 26 сент. 2026 г. в 21:29, jian he <jian(dot)universality(at)gmail(dot)com>:

> On Fri, Sep 4, 2026 at 6:38 PM Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
> wrote:
> >
> > Attached is v2 of the patch.
> >
> > --
> > Regards,
> > Rachitskiy Andrey
>
>
> + EEO_CASE(EEOP_JSONEXPR_RESET)
> + {
> + ExecEvalJsonExprReset(state, op);
> +
> + EEO_NEXT();
> + }
> +
>
> --- a/src/include/executor/execExpr.h
> +++ b/src/include/executor/execExpr.h
> @@ -265,6 +265,7 @@ typedef enum ExprEvalOp
> EEOP_XMLEXPR,
> EEOP_JSON_CONSTRUCTOR,
> EEOP_IS_JSON,
> + EEOP_JSONEXPR_RESET,
> EEOP_JSONEXPR_PATH,
> EEOP_JSONEXPR_COERCION,
> EEOP_JSONEXPR_COERCION_FINISH,
>
> This seems unnecessary.
> In EEOP_JSONEXPR_PATH, we can
> if document or jsonpath is NULL, we can just go to jump_end (return
> NULL) or jump_eval_coercion (NULL need coerce to constrainted domain),
> no need to worry about ON ERROR, ON EMPTY.
>
> What do you think of the attachment?
>
>
>
> --
> jian
> https://www.enterprisedb.com/

Hi, Jian!

Thanks for posting this alternative.

I considered the same shape earlier: keep the empty/error reset in
EEOP_JSONEXPR_PATH and stop skipping that step on SQL NULL. Your version is
simpler than adding EEOP_JSONEXPR_RESET. No new opcode, and no JIT or
back-branch ABI churn.

The commit message still described a RESET opcode that the diff does not
add. I adjusted the subject and body to match what the patch actually does
(retarget JUMP_IF_NULL at PATH, drop the CONST NULL pad, handle NULL inside
ExecEvalJsonExprPath).

Either approach fixes the reported cases. I am fine with whichever version
a committer prefers.

Attachment Content-Type Size
v3-0001-Handle-SQL-NULL-inside-EEOP-JSONEXPR-PATH.patch text/x-patch 8.8 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Geoghegan 2026-09-28 04:13:14 Re: BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption
Previous Message Michael Paquier 2026-09-27 20:35:01 Re: BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption