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 1sBEqI-00FI64-4L for pgsql-general@arkaria.postgresql.org; Sun, 26 May 2024 14:27:23 +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 1sBEqG-00492G-80 for pgsql-general@arkaria.postgresql.org; Sun, 26 May 2024 14:27:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sBEqF-004928-Ob for pgsql-general@lists.postgresql.org; Sun, 26 May 2024 14:27:19 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sBEqC-0025FA-S7 for pgsql-general@lists.postgresql.org; Sun, 26 May 2024 14:27:18 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 44QEREkl1020667; Sun, 26 May 2024 10:27:14 -0400 From: Tom Lane To: Victor Dobrovolsky cc: pgsql-general@lists.postgresql.org Subject: Re: scalar plpgsql functions and their stability flags In-reply-to: References: Comments: In-reply-to Victor Dobrovolsky message dated "Sun, 26 May 2024 16:20:10 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2720.1716733634.1@sss.pgh.pa.us> Date: Sun, 26 May 2024 10:27:14 -0400 Message-ID: <2721.1716733634@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Victor Dobrovolsky writes: > It is clear that for immutable/stable functions with constant parameters, > query planner could/should calculate value in a parse time and use it > directly in query, or at least once per query. Immutable, yes, stable, no. Awhile back there was a draft patch to cache outputs of stable functions after running them once in a query, but I don't think anyone's still working on that. IIRC we were having a hard time convincing ourselves that the extra bookkeeping would pay for itself. > But it is unclear for me what exactly should/can happens when parameters > are bounded not to constant values but to query fields. > In such a case there could be some caching mechanics involved for > parameters combinations and result values. > Like building a hash table for that or something similar. No such mechanism exists. Again, there would be a lot of tradeoffs involved and it's difficult to say if it'd be a win. regards, tom lane