Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 3936D9F9AC3 for ; Sun, 9 Sep 2007 23:15:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 64762-10 for ; Sun, 9 Sep 2007 23:15:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1FF4C9F9A68 for ; Sun, 9 Sep 2007 23:15:33 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l8A2FOMq015491; Sun, 9 Sep 2007 22:15:24 -0400 (EDT) To: "Fernando Hevia" cc: "'SQL Postgresql List'" Subject: Re: Function Volatility In-reply-to: <017901c7f340$f497e400$8f01010a@iptel.com.ar> References: <017901c7f340$f497e400$8f01010a@iptel.com.ar> Comments: In-reply-to "Fernando Hevia" message dated "Sun, 09 Sep 2007 21:24:30 -0300" Date: Sun, 09 Sep 2007 22:15:24 -0400 Message-ID: <15490.1189390524@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/74 X-Sequence-Number: 29287 "Fernando Hevia" writes: > I am not sure if I am understanding volatility. You're not. > What bother me are the 3 "been here" messages. As the function is immutable > and the parameter remains unchanged needs the planner actually execute the > function 3 times? The IMMUTABLE marker is a promise from you to the system that it is safe to optimize away multiple calls to the function. It is not a promise from the system to you that the system will expend unlimited amounts of energy to detect duplicate calls. The majority of the immutable functions in Postgres are things like int4pl(), where it would obviously be silly to expend any cycles at all on looking for duplicate calls such as you show here. In practice what will happen is that each textual call will be folded to a constant separately. The advantage comes from not having to repeat the call for each row processed by a query, not from saving work within a row. regards, tom lane