Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vim5H-00F8KW-23 for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jan 2026 04:14:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vim5E-00AveB-1I for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jan 2026 04:14:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vim5D-00Ave3-32 for pgsql-hackers@lists.postgresql.org; Thu, 22 Jan 2026 04:14:12 +0000 Received: from mail-vk1-xa2b.google.com ([2607:f8b0:4864:20::a2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vim5A-001hmn-2w for pgsql-hackers@postgresql.org; Thu, 22 Jan 2026 04:14:10 +0000 Received: by mail-vk1-xa2b.google.com with SMTP id 71dfb90a1353d-5636784884eso164172e0c.2 for ; Wed, 21 Jan 2026 20:14:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769055248; cv=none; d=google.com; s=arc-20240605; b=dWdRSw2vvmdNr/5CQz8MMOmxof1vTJpBeWEpXqenXCWLeKS7jD7hqmXpkujp9l61Iv 0hs6x6qK8mxHiTamtAZp85s5fU1hgZUVaJA+Z6b1yz00Ijy6Vt1SWutXvjVRk0q+7W7T y2CPQkW84dqbxiTN9YpWttNOoir/26Gn6fVNR5uBhXWF2sx1xk8nyTN86sm2n/rRor0r 0yF7cJUKXBpQufCcOUyvu2Yj1W/mkPPzPwV/NtZuLSP6/8zJpJdIPFj8s9416OAgr6sR SZQQgCxzvG8PNTVX3nrN2wrULroP+rDPpXbCb5XXwgRlpCHQuaHVbnyk7EAaL684uu0N BRYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=o8Uh6UAq9L8AnfQFg5G9CHS2esswex5gb3XANSxwitE=; fh=cRXR5SJOr2vhbsNQTy/iAJfslJSydmZtNBwdE94KqR0=; b=YDpy8g2edGe3qCh0qop2HFVVayHoMHuS/Wv7UwyTnuTxfNVQ2G/JUGq9sYnypWIjzD AohusuWYp7u3MNyi70OWJTzbXppFCkLwGrbW90WGFY+lN4EOgA9zhViev325Q0VCvHyR aPFZmD9+9DSIBzCdBxj/r30ERN0Hfk1PMU3MRkhgARcsVlsI0uU1mfr7iQw74QSPLMwO GFXNgBa49Nn+8oWWFRtwFXwk5GaxgxxfROyMkK/iFSwDmqdmv1WRyobCwDv549jbhPF6 EcO2qKtz3yZigA4rP66NUgR+4QiTEeSvSeeOzmF78jUKecBN2dUhmMFoQxyiBPOZsP4B Rbmg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1769055248; x=1769660048; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=o8Uh6UAq9L8AnfQFg5G9CHS2esswex5gb3XANSxwitE=; b=JlEvAHv/yS8cxW/XyfPmuwFwC4iHjBLV2BXuMgzKT8IO4z9e6oxVjXzG6ktXWjoAq4 Xk/fRT2F1IlIlrfWOmOpFrQtSjyvOgW0cW44jDPNyIyLb2RRnMarBYrEiGM7yQU/RsXC H07LDi3bf2+tYPX9KhSgYqYKHfwvi/uY6B0dEsXwnGTDgFRssx22KFmbsz/JehvApbsi UPD6WRJ35SZHAkW4R4oSoFvbBoPPx7tsRrmwQk1d54xeDibYMkarU5BVISMay6FuiQe6 FdX9z+aC3g/T+EuxIp/y7qsfP9xtVGQVl+p0n2Y+c/OM0BLmdJMmREV73RdS11Noua2R eiMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769055248; x=1769660048; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=o8Uh6UAq9L8AnfQFg5G9CHS2esswex5gb3XANSxwitE=; b=FIf9Y/YYgMob4sLmUjLxfseBgAC6jeFqGqPvhVmUenPENHqaFbiPc1AGH59Rt/PVY0 kljzWBxh+kqy3OQI0U3e2P8UyKHSXSC7rfXZ0msLjFROCi3Ou12c8q7DCJbZUtBRh5jo olKPrI4E6+LDVBFF/0jzOTlhuWapWnfF7mF0xLxVM3lHxkvu/2uhQsNO2e43bsiWY0Pf PqaSzyvuLIFPw41ATp3HBkOKO31JnB28+kc01kXB48IUrjHHLSEzzxi4QQHYMAfH0vv9 46iXJg3d8Aj9zg8XS5hdn72G//EUKK6SW9lcUp9xZpnBybq/Z0L9XAVYsl3x8Ap+B66X OcDw== X-Forwarded-Encrypted: i=1; AJvYcCV1jC9xdDKq4t0upDVmSigJFINp5X5KpT8G4GGHQAyPYWpZQw5oksYl4P3dBHrJJqdup2xq9Bcy05ZSA7Yo@postgresql.org X-Gm-Message-State: AOJu0Yyq3898Ctn9blHyzDnFopHl8L979KXCF/C56YecU/pWEAXX7HuU k9QfsuVHYVFICcgKD7px/T+Bzbde2Y1ghe6SfHx1NiaKKOc1C++M1DE5C05deHBabP8rToA27oN 1mVkuaprLVe7NsC4lUBTO/Px4h4dkol8W0I4fN6AM X-Gm-Gg: AZuq6aLKY3Z+npksvhT9Wikxe6M2ZyWTDC76Aq4HovszbRJtvSOStNwNI1Ce8JhcBnH i7eSUPvTAt12afmgDos1jpx/G0nbJ04cM5bp0GqNc5d+D4L/iDp/BETfJVzoK8AbKpmyOgoWc7g tvMr4Tz3KpXI5VAh904gZtVeQ4zyBC7GD50U0TUCut2TRTJJpaCoGv7l7ycL5tWmfPvRiPIvSYI UEzlaJn1AS2/a4JkEar1UYBpEjFDfPTUKoIszTq+rtge06f1RvIxJKyqMvaLlmB9m6+BtPTkXN9 1FpG1Ja/ X-Received: by 2002:a05:6102:374b:b0:5f5:3d46:e602 with SMTP id ada2fe7eead31-5f53d46f14emr84319137.18.1769055248140; Wed, 21 Jan 2026 20:14:08 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Vaibhav Dalvi Date: Thu, 22 Jan 2026 09:43:32 +0530 X-Gm-Features: AZwV_QiIpSHmyVwaxDV5ABfRkashIv19PCDlDYquCD3Zr5rfaikT40y9zxtEu8I Message-ID: Subject: Re: finish TODOs in to_json_is_immutable, to_jsonb_is_immutable also add tests on it To: jian he Cc: hackers@postgresql.org, pgsql-hackers@postgresql.org Content-Type: multipart/alternative; boundary="000000000000a75dc30648f24536" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a75dc30648f24536 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jian, Thanks for your detailed explanation. This makes sense to me as well. Regards, Vaibhav On Wed, Jan 21, 2026 at 2:09=E2=80=AFPM jian he wrote: > On Tue, Jan 13, 2026 at 7:12=E2=80=AFPM Vaibhav Dalvi > wrote: > > > > Hi Jian, > > > > Thanks for working on this. The patch looks good, but I have a few > observations: > > > > 1. Index creation fails for range types regardless of the base data typ= e: > > > > postgres=3D# create type range_int as range(subtype=3Dint); > > CREATE TYPE > > postgres=3D# create table range_table(r1 range_int); > > CREATE TABLE > > postgres=3D# create index on range_table(json_array(r1 returning jsonb)= ); > > ERROR: functions in index expression must be marked IMMUTABLE > > > > I believe this is because range_out is a stable function. Consequently, > the following > > code snippet in to_jsonb_is_immutable may be redundant, or should simpl= y > return > > false without recursing for the sub-type: > > > > + else if (att_typtype =3D=3D TYPTYPE_RANGE) > > + { > > + to_jsonb_is_immutable(get_range_subtype(typoid), contain_mutable); > > + } > > > > yech, your observation is right. > > create index on range_table((r1::text)); > > will fail, because pg_proc.provolatile is 's' for function range_out. > > but imagine the function range_out marked as immutable, then we would > need to recurse to the range's subtype. > also, it makes the logic more complite: if the type is container type, > recurse to check its elemental/subtype. > > Therefore, I am inclined to leave it unchanged. > > > 2. Regarding the function names to_jsonb_is_immutable and > to_json_is_immutable: > > since these do not return a boolean value, "is" may no longer be > appropriate. Perhaps > > something like to_jsonb_check_mutable would be more accurate? > > > > to_jsonb_is_immutable and to_json_is_immutable are marked as extern, so > they may > be used by other extensions. Renaming them would require extension author= s > to > discover and update to the new symbol names. Adding an additional argumen= t > makes > the change immediately visible through a signature mismatch. > > so I think we should stick to the current name. > > -- > jian > https://www.enterprisedb.com > --000000000000a75dc30648f24536 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jian,

Thanks for your det= ailed explanation. This makes sense to me as well.

Regards,
Vaibhav

On Wed, Jan 21, 2026= at 2:09=E2=80=AFPM jian he <jian.universality@gmail.com> wrote:
On Tue, Jan 13, 2026 at 7:12=E2=80=AFPM Va= ibhav Dalvi
<vai= bhav.dalvi@enterprisedb.com> wrote:
>
> Hi Jian,
>
> Thanks for working on this. The patch looks good, but I have a few obs= ervations:
>
> 1. Index creation fails for range types regardless of the base data ty= pe:
>
> postgres=3D# create type range_int as range(subtype=3Dint);
> CREATE TYPE
> postgres=3D# create table range_table(r1 range_int);
> CREATE TABLE
> postgres=3D# create index on range_table(json_array(r1 returning jsonb= ));
> ERROR: functions in index expression must be marked IMMUTABLE
>
> I believe this is because range_out is a stable function. Consequently= , the following
> code snippet in to_jsonb_is_immutable may be redundant, or should simp= ly return
> false without recursing for the sub-type:
>
> + else if (att_typtype =3D=3D TYPTYPE_RANGE)
> + {
> + to_jsonb_is_immutable(get_range_subtype(typoid), contain_mutable); > + }
>

yech, your observation is right.

create index on range_table((r1::text));

will fail, because pg_proc.provolatile is 's' for function range_ou= t.

but imagine the function range_out marked as immutable, then we would
need to recurse to the range's subtype.
also, it makes the logic more complite: if the type is container type,
recurse to check its elemental/subtype.

Therefore, I am inclined to leave it unchanged.

> 2. Regarding the function names to_jsonb_is_immutable and to_json_is_i= mmutable:
> since these do not return a boolean value, "is" may no longe= r be appropriate. Perhaps
> something like to_jsonb_check_mutable would be more accurate?
>

to_jsonb_is_immutable and to_json_is_immutable are marked as extern, so the= y may
be used by other extensions. Renaming them would require extension authors = to
discover and update to the new symbol names. Adding an additional argument = makes
the change immediately visible through a signature mismatch.

so I think we should stick to the current name.

--
jian
https://www.enterprisedb.com
--000000000000a75dc30648f24536--