Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oelXJ-0002iN-F6 for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Oct 2022 23:04:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oelXI-0006sj-9D for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Oct 2022 23:04:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oelXI-0006sZ-0l for pgsql-bugs@lists.postgresql.org; Sat, 01 Oct 2022 23:04:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oelXF-0003ZO-M9 for pgsql-bugs@lists.postgresql.org; Sat, 01 Oct 2022 23:04:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 291N4eAu1028096; Sat, 1 Oct 2022 19:04:40 -0400 From: Tom Lane To: Shane Plesner cc: pgsql-bugs@lists.postgresql.org Subject: Re: Bug / Unintentional Feature: non-immutable functions can be used for generated columns. In-reply-to: References: Comments: In-reply-to Shane Plesner message dated "Sat, 01 Oct 2022 16:44:31 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1028094.1664665480.1@sss.pgh.pa.us> Date: Sat, 01 Oct 2022 19:04:40 -0400 Message-ID: <1028095.1664665480@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Shane Plesner 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