Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fn7CV-0005tB-Qx for pgsql-general@arkaria.postgresql.org; Tue, 07 Aug 2018 18:59:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fn7CQ-0001el-Ha for pgsql-general@arkaria.postgresql.org; Tue, 07 Aug 2018 18:59:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fn7CQ-0001eX-6K for pgsql-general@lists.postgresql.org; Tue, 07 Aug 2018 18:59:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fn7CJ-0004M2-2z for pgsql-general@postgresql.org; Tue, 07 Aug 2018 18:59:16 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w77Ix7gf028960; Tue, 7 Aug 2018 14:59:07 -0400 From: Tom Lane To: Ken Tanzer cc: Adrian Klaver , PG-General Mailing List Subject: Re: Immutable function WAY slower than Stable function? In-reply-to: References: <03120a03-75d0-ad6c-691c-35ca7e7fccfa@aklaver.com> <27336.1533609731@sss.pgh.pa.us> <24954.1533658221@sss.pgh.pa.us> Comments: In-reply-to Ken Tanzer message dated "Tue, 07 Aug 2018 11:42:51 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28958.1533668347.1@sss.pgh.pa.us> Date: Tue, 07 Aug 2018 14:59:07 -0400 Message-ID: <28959.1533668347@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ken Tanzer writes: > I've wondered in the past about Immutable functions, and particularly the > scope & lifetime of "forever" in "guaranteed to return the same results > given the same arguments forever." I assume that's "for all users and all > sessions," but either in theory or in practice is there a limit to how long > a stale value might persist? The two issues I can think of offhand are (a) plans that depend on the assumption of immutability might persist for the life of active sessions; (b) if you created an index on the result of an immutable function, changing the function's behavior would likely render the index inconsistent. (REINDEX would be enough to fix that, though.) > And, if you were to drop and recreate a > function with the same name & parameters, would it start fresh at that > point? DROP (not CREATE OR REPLACE) would surely get rid of any dependent values. > Finally, I'm wondering if there's any legitimate reason for a immutable > function to call anything stable or volatile, and if not would it make any > sense to emit a warning when the function is created. We've been around on that before, and concluded that it's not worth it. People have in the past used phony-immutable functions to coerce the optimizer to do what they want --- in fact, that use case is one of the reasons why we have the inlining restriction. I'm not sure if such practices are still popular, but somebody who was doing that would not appreciate nannyism. regards, tom lane