pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed[PATCH] Remove redundant path_nulls checks in setPathObject/Array
4+ messages / 4 participants
[nested] [flat]
* [PATCH] Remove redundant path_nulls checks in setPathObject/Array
@ 2026-08-26 12:03 Ilya Gladyshev <ilya.gladyshev@linux.dev>
0 siblings, 3 replies; 4+ messages in thread
From: Ilya Gladyshev @ 2026-08-26 12:03 UTC (permalink / raw)
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Hi all,
I noticed redundant path_nulls checks in setPathObject and setPathArray,
so here's a small refactoring patch to remove them.
- Both checks were introduced in c694701 (12 May 2015, "Additional
functions and operators for jsonb") with the functions' initial code.
- Both functions always had a single call site, `setPath`, as they are
internal implementations for the two cases (array/object) in a generic
function.
- Later, in 1edd4ec (4 Oct 2015, "Disallow invalid path elements in
jsonb_set"), the path_nulls check was propagated into setPath itself.
If desired, those conditions can be transformed into Assert()s with a
comment about setPath() validation.
---
Ilya Gladyshev // foxido.dev
Attachments:
0001-Remove-redundant-NULL-checks-in-setPathObject-Array.patch (text/x-diff, 1.5K) download
From ad1ad228c4bee6d672958860e0dbd7819223a5c7 Mon Sep 17 00:00:00 2001
From: Ilya Gladyshev <ilya.gladyshev@linux.dev>
Date: Wed, 26 Aug 2026 14:23:21 +0300
Subject: [PATCH] Remove redundant path_null checks in setPathObject/Array
- Both checks were introduced in c694701 (12 May 2015, "Additional
functions and operators for jsonb") with the functions' initial code.
- Both functions always had a single call site, `setPath`, as they are
internal implementations for the two cases (array/object) in a generic
function.
- Later, in 1edd4ec (4 Oct 2015, "Disallow invalid path elements in
jsonb_set"), path_nulls check was propagated into setPath itself.
Therefore, remove redundant checks in setPathObject/Array.
---
src/backend/utils/adt/jsonfuncs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index bc7b556e22e..8e5d5faf046 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -5260,7 +5260,7 @@ setPathObject(JsonbIterator **it, const Datum *path_elems, const bool *path_null
v;
bool done = false;
- if (level >= path_len || path_nulls[level])
+ if (level >= path_len)
done = true;
else
{
@@ -5398,7 +5398,7 @@ setPathArray(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls
bool done = false;
/* pick correct index */
- if (level < path_len && !path_nulls[level])
+ if (level < path_len)
{
char *c = TextDatumGetCString(path_elems[level]);
char *badp;
--
2.55.0
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [PATCH] Remove redundant path_nulls checks in setPathObject/Array
@ 2026-09-05 08:03 Pierre Forstmann <pierre.forstmann@gmail.com>
parent: Ilya Gladyshev <ilya.gladyshev@linux.dev>
2 siblings, 0 replies; 4+ messages in thread
From: Pierre Forstmann @ 2026-09-05 08:03 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org; +Cc: Ilya Gladyshev <ilya.gladyshev@linux.dev>
The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: not tested
Documentation: not tested
Hello,
This patch looks good to me.
There is no SQL change: no need to check SQL compliance.
IMO no documentation change is needed.
Regards,
PF.
The new status of this patch is: Ready for Committer
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [PATCH] Remove redundant path_nulls checks in setPathObject/Array
@ 2026-09-07 06:24 solai v <solai.cdac@gmail.com>
parent: Ilya Gladyshev <ilya.gladyshev@linux.dev>
2 siblings, 0 replies; 4+ messages in thread
From: solai v @ 2026-09-07 06:24 UTC (permalink / raw)
To: Ilya Gladyshev <ilya.gladyshev@linux.dev>; +Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Hi all,
On Mon, Sep 7, 2026 at 11:12 AM Ilya Gladyshev <ilya.gladyshev@linux.dev> wrote:
>
> Hi all,
>
> I noticed redundant path_nulls checks in setPathObject and setPathArray,
> so here's a small refactoring patch to remove them.
>
> - Both checks were introduced in c694701 (12 May 2015, "Additional
> functions and operators for jsonb") with the functions' initial code.
>
> - Both functions always had a single call site, `setPath`, as they are
> internal implementations for the two cases (array/object) in a generic
> function.
>
> - Later, in 1edd4ec (4 Oct 2015, "Disallow invalid path elements in
> jsonb_set"), the path_nulls check was propagated into setPath itself.
>
> If desired, those conditions can be transformed into Assert()s with a
> comment about setPath() validation.
>
Thank you for the patch.
I reviewed and tested this patch. The path_nulls[level] check is
already done in setPath() before calling setPathObject() or
setPathArray(). I also checked the call sites and confirmed that both
functions are only called from setPath(), so the checks removed by the
patch are indeed redundant.
I didn't find any issues with the patch. It looks good to me.
Regards.
Solai
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [PATCH] Remove redundant path_nulls checks in setPathObject/Array
@ 2026-09-07 07:22 Chao Li <li.evan.chao@gmail.com>
parent: Ilya Gladyshev <ilya.gladyshev@linux.dev>
2 siblings, 0 replies; 4+ messages in thread
From: Chao Li @ 2026-09-07 07:22 UTC (permalink / raw)
To: Ilya Gladyshev <ilya.gladyshev@linux.dev>; +Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
> On Aug 26, 2026, at 20:03, Ilya Gladyshev <ilya.gladyshev@linux.dev> wrote:
>
> Hi all,
>
> I noticed redundant path_nulls checks in setPathObject and setPathArray,
> so here's a small refactoring patch to remove them.
>
> - Both checks were introduced in c694701 (12 May 2015, "Additional
> functions and operators for jsonb") with the functions' initial code.
>
> - Both functions always had a single call site, `setPath`, as they are
> internal implementations for the two cases (array/object) in a generic
> function.
>
> - Later, in 1edd4ec (4 Oct 2015, "Disallow invalid path elements in
> jsonb_set"), the path_nulls check was propagated into setPath itself.
>
> If desired, those conditions can be transformed into Assert()s with a
> comment about setPath() validation.
>
> ---
> Ilya Gladyshev // foxido.dev<0001-Remove-redundant-NULL-checks-in-setPathObject-Array.patch>
Looks reasonable to me, since setPath() already checks path_nulls[level] and raises an error for a NULL path element.
I think this patch does more than just remove a redundant check, it also eliminates a potential source of confusion. setPath() treats path_nulls[level] being true as an error, while setPathObject() currently treats the same condition as an indication of done.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-09-07 07:22 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-26 12:03 [PATCH] Remove redundant path_nulls checks in setPathObject/Array Ilya Gladyshev <ilya.gladyshev@linux.dev>
2026-09-05 08:03 ` Pierre Forstmann <pierre.forstmann@gmail.com>
2026-09-07 06:24 ` solai v <solai.cdac@gmail.com>
2026-09-07 07:22 ` Chao Li <li.evan.chao@gmail.com>
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