Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id CC5E09F98B3 for ; Wed, 15 Aug 2007 17:48:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 78751-04 for ; Wed, 15 Aug 2007 17:48:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from roadrunner.quickmin.net (roadrunner.quickmin.net [217.14.112.5]) by postgresql.org (Postfix) with SMTP id D5DEE9F9884 for ; Wed, 15 Aug 2007 17:48:41 -0300 (ADT) Received: (qmail 88015 invoked by uid 0); 15 Aug 2007 20:48:39 -0000 Received: from krlh-590f2f95.pool.einsundeins.de (HELO ?192.168.178.24?) (89.15.47.149) by roadrunner.quickmin.net with SMTP; 15 Aug 2007 20:48:39 -0000 In-Reply-To: <21918.1187038900@sss.pgh.pa.us> References: <2E281675-B282-41F6-B7A2-86853250850A@phlybye.de> <21918.1187038900@sss.pgh.pa.us> Mime-Version: 1.0 (Apple Message framework v752.3) X-Gpgmail-State: !signed Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <62CBC6C5-93D8-4667-8143-02F6AF2B9C09@phlybye.de> Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit From: Philipp Specht Subject: Re: Stable function optimisation Date: Wed, 15 Aug 2007 22:48:34 +0200 To: Tom Lane X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/156 X-Sequence-Number: 26286 Hi Tom, Thank you very much for your explanation. On 13.08.2007, at 23:01, Tom Lane wrote: > Philipp Specht writes: >> The biggest question here is: Why is the runtime of the query with >> the stable function not near the runtime of the immutable function? > > Stable functions don't get folded to constants. I tried to force this by using the following construct: SELECT t.id, t.a FROM public.t WHERE t.a=(VALUES(public.f())); Is this a bad practice and will destroy some other thing I can't think of at the moment? What it means for me at the moment is about half the query time of a high usage query directly linked to a gui. That's a big gain for a user interface and takes the query under the magical 500ms response time... >> It's definitely one query and the manual states that a stable >> function does not change in one statement and therefore can be >> optimised. > > That's not the type of optimization that gets done with it. What > "STABLE" is for is marking functions that are safe to use in index > conditions. If you'd been using an indexable condition you'd have > seen three different behaviors here. > > (I see that you do have an index on t.a, but apparently there are > too many matching rows for the planner to think the index is worth > using.) Yes, that's not the real problem here. It's only a test database and the real data behaves a bit differently. Have a nice day, Philipp