From: Ilya Gladyshev <ilya.gladyshev@linux.dev>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Subject: [PATCH] Remove redundant path_nulls checks in setPathObject/Array
Date: Wed, 26 Aug 2026 12:03:02 +0000
Message-ID: <bb4175151e040c4b98045d5b01b8128fd923eb1e@linux.dev> (raw)
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.cindex 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: ilya.gladyshev@linux.dev
Subject: Re: [PATCH] Remove redundant path_nulls checks in setPathObject/Array
In-Reply-To: <bb4175151e040c4b98045d5b01b8128fd923eb1e@linux.dev>
References: <bb4175151e040c4b98045d5b01b8128fd923eb1e@linux.dev>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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