Re: 回复:[Internet]Re: [PATCH] Prevent replacement of a function if it's used in an index expression and is not IMMUTABLE - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: 回复:[Internet]Re: [PATCH] Prevent replacement of a function if it's used in an index expression and is not IMMUTABLE
Date
Msg-id CAKFQuwZD+V-9Tm8OD2Zx6hgvU=f8aQ+xjaD7EhP7OLvc=ZF8BQ@mail.gmail.com
Whole thread Raw
In response to Re: 回复:[Internet]Re: [PATCH] Prevent replacement of a function if it's used in an index expression and is not IMMUTABLE  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: 回复:[Internet]Re: [PATCH] Prevent replacement of a function if it's used in an index expression and is not IMMUTABLE
List pgsql-hackers
On Wed, Jul 9, 2025 at 9:15 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
"sundayjiang(蒋浩天)" <sundayjiang@tencent.com> writes:
> > The purpose of this patch is to prevent replacing a function via `CREATE OR REPLACE FUNCTION` with a new definition that is not marked as `IMMUTABLE`, if the existing function is referenced by an index expression.
> >
> > Replacing such functions may lead to index corruption or runtime semantic inconsistencies, especially when the function’s output is not stable for the same input.


TBH, I find this proposal to be useless nannyism.  Replacing a
function that is used in an index is problematic if you change its
behavior (that is, its actual output for given inputs) in any way.
Whether it's marked IMMUTABLE is a very minor side point.

Isn't preventing a dump-restore hazard sufficient reason to do this?  The now-volatile function will be dumped as such and the create index during the restore will fail because of that.

David J.

pgsql-hackers by date:

Previous
From: Mahendra Singh Thalor
Date:
Subject: Re: Non-text mode for pg_dumpall
Next
From: Tom Lane
Date:
Subject: Re: [PoC] Federated Authn/z with OAUTHBEARER