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 1o6QWh-0004fs-N6 for pgsql-general@arkaria.postgresql.org; Wed, 29 Jun 2022 05:46:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o6QWg-0005O9-Ep for pgsql-general@arkaria.postgresql.org; Wed, 29 Jun 2022 05:46:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6QWg-0005Ny-4T for pgsql-general@lists.postgresql.org; Wed, 29 Jun 2022 05:46:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6QWb-0006v9-Tj for pgsql-general@lists.postgresql.org; Wed, 29 Jun 2022 05:46:09 +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 25T5k2I52987096; Wed, 29 Jun 2022 01:46:02 -0400 From: Tom Lane To: Pavel Stehule cc: Bryn Llewellyn , "David G. Johnston" , Christophe Pettus , pgsql-general list Subject: Re: User's responsibility when using a chain of "immutable" functions? In-reply-to: References: <38FB5DA3-5940-43A9-8B09-5C856E2B18C4@yugabyte.com> <80C40450-6C0C-46E2-AE82-E7D46120F7FF@thebuild.com> Comments: In-reply-to Pavel Stehule message dated "Wed, 29 Jun 2022 06:34:31 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2987094.1656481562.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 29 Jun 2022 01:46:02 -0400 Message-ID: <2987095.1656481562@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Pavel Stehule writes: > st 29. 6. 2022 v 6:28 odesílatel Bryn Llewellyn napsal: >> Moreover, this "hermetic" property of a to-be-immutable function can be >> established only by human analysis of the function's source code. > Our immutable functions are more tolerant than they should be - for real > immutable functions we should disallow SQL inside functions (and everything > that is not immutable (plpgsql_check raises warning in this case)), but it > is allowed. It's generally believed that Turing's proof of the undecidability of the halting problem [1] implies that it's impossible to mechanically prove or refute function properties like immutability. Admittedly, Turing was concerned with the most general case --- that is, he showed that *there exist* cases for which no algorithm can give the right answer, not that any specific practical case can't be proven. Still, that result has discouraged most people from spending much time on mechanically checking such things. If you declare a function immutable, Postgres will believe you; the consequences if you lied are on your own head. regards, tom lane [1] https://en.wikipedia.org/wiki/Halting_problem