Re: Bug / Unintentional Feature: non-immutable functions can be used for generated columns.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Shane Plesner <gebnar(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Bug / Unintentional Feature: non-immutable functions can be used for generated columns.
Date: 2022-10-01 23:04:40
Message-ID: 1028095.1664665480@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Shane Plesner <gebnar(at)gmail(dot)com> writes:
> It seems to me that any time a function is replaced, there could be a check
> to see if it was changed from immutable to mutable. If it was, check the
> schema for any references to that function that require immutable function
> calls, and raise an exception.
> Is there something I'm missing that makes this unfeasible?

Cost, added maintenance burden, race conditions.

Also, just complaining about dropping the immutability flag seems
rather pointless. If you redefine the function in a way that changes its
results, but continue to mark it immutable, you've still broken a lot
of situations (e.g., expression indexes that depend on the function's
results). If memory serves, we've actually discussed refusing any
alterations at all of an "immutable" function once it's defined.
But that's still not much help, because we can't usefully verify that
an "immutable" function's behavior actually is immutable. In the end
it's on the user to preserve its behavior, or do appropriate cleanup
(such as reindexing) after a change.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2022-10-03 08:41:03 Re: v15rc1 shadowbuild fails when using src from symlink
Previous Message Jeff Janes 2022-10-01 21:44:36 Re: pg ignores wal files in pg_wal, and instead tries to load them from archive/primary