Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B27F31337BE8 for ; Mon, 14 Mar 2011 14:17:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 31738-08 for ; Mon, 14 Mar 2011 17:17:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 106ED1337BE6 for ; Mon, 14 Mar 2011 14:17:40 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p2EHHXOZ012873; Mon, 14 Mar 2011 13:17:34 -0400 (EDT) To: Julius Tuskenis cc: Merlin Moncure , pgsql-performance@postgresql.org Subject: Re: unexpected stable function behavior In-reply-to: <4D7DD5CF.4080502@nsoft.lt> References: <4D78FB98.7090609@nsoft.lt> <4D7DD5CF.4080502@nsoft.lt> Comments: In-reply-to Julius Tuskenis message dated "Mon, 14 Mar 2011 10:46:07 +0200" Date: Mon, 14 Mar 2011 13:17:33 -0400 Message-ID: <12872.1300123053@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/141 X-Sequence-Number: 42820 Julius Tuskenis writes: > From the postgresql documentation about STABLE functions: "This > category allows the optimizer to optimize multiple calls of the function > to a single call." I thought that this means that optimizer executes the > function only for now parameter sets and stores results in some "cache" > and use it if the parameters are already known. No, it does not. That function property *allows* the optimizer to invoke the function fewer times than would happen in an un-optimized query. It does not *require* it to do so. There is no such cache mechanism in Postgres, and it's unlikely that there ever will be, because it probably would be a net performance loss on average. regards, tom lane