Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5RtN-0069o1-Ez for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Oct 2024 15:42:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t5RtK-007kYI-EM for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Oct 2024 15:42:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5RtK-007kYA-6A for pgsql-bugs@lists.postgresql.org; Mon, 28 Oct 2024 15:42:50 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5RtI-003R9O-C3 for pgsql-bugs@lists.postgresql.org; Mon, 28 Oct 2024 15:42:49 +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 49SFgk503972735; Mon, 28 Oct 2024 11:42:46 -0400 From: Tom Lane To: poliv78@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18676: Execute function while selecting from table with partial index using this function. In-reply-to: <18676-383b0d2b6dc65bf6@postgresql.org> References: <18676-383b0d2b6dc65bf6@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 28 Oct 2024 14:58:34 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3972733.1730130166.1@sss.pgh.pa.us> Date: Mon, 28 Oct 2024 11:42:46 -0400 Message-ID: <3972734.1730130166@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Please run the script below. It creates sample table with partial index > using IMMUTABLE function. > I think when table is changing - index in changing and thus function used in > WHERE cluse can be run. > But it is not supposed to be run on just simple SELECT from table without > even condition to use this index. [ shrug... ] There is no bug here. The planner is entitled to investigate the properties of indexes attached to a table it's trying to plan for. Sure, this index is not relevant to this query --- but how's the planner going to know that without examining the index? And part of that examination involves reducing any partial-index predicate to standard form, which includes constant-folding. Since your function is marked IMMUTABLE, that means it should be evaluated and reduced to a constant. Part of the contract for marking a function IMMUTABLE is that it has no interesting side-effects. This example breaks that in two ways: the RAISE NOTICE is a side-effect, and the possibility of a permissions failure is another one. regards, tom lane