Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 875FA633E41 for ; Thu, 25 Mar 2010 11:35:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16107-04 for ; Thu, 25 Mar 2010 14:35:30 +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 0759F632EA0 for ; Thu, 25 Mar 2010 11:35:30 -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 o2PEZRCB016801; Thu, 25 Mar 2010 10:35:27 -0400 (EDT) To: Louis-David Mitterrand cc: pgsql-sql@postgresql.org Subject: Re: Does IMMUTABLE property propagate? In-reply-to: <20100325075405.GA17176@apartia.fr> References: <4B91C184.4090906@venaver.info> <407d949e1003060645i408e0648te67dfd722172f76a@mail.gmail.com> <4B927FED.60209@venaver.info> <4150.1267911115@sss.pgh.pa.us> <20100325061616.GA4629@apartia.fr> <162867791003250027q3cfc5ba9g59d56768aa4c4e5e@mail.gmail.com> <20100325075405.GA17176@apartia.fr> Comments: In-reply-to Louis-David Mitterrand message dated "Thu, 25 Mar 2010 08:54:05 +0100" Date: Thu, 25 Mar 2010 10:35:26 -0400 Message-ID: <16800.1269527726@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/185 X-Sequence-Number: 33892 Louis-David Mitterrand writes: > Hmm, that's interesting. So for simple functions (like my example) it is > better to write them in plain sql? And in that case no 'immutable' flag > is necessary? If it's just a simple SQL expression, then yes write it as a SQL function. The planner can "inline" those, eliminating the call overhead that you'll pay with a plpgsql function. When you're intending to have a SQL function be inlined, it's probably best not to mark it as either IMMUTABLE or STRICT --- that doesn't buy anything and it can complicate matters as to whether inlining is legal. regards, tom lane