X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 049C3DA05B for ; Tue, 4 Oct 2005 11:55:08 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45022-04 for ; Tue, 4 Oct 2005 14:55:03 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id DDC9DDA024 for ; Tue, 4 Oct 2005 11:55:05 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j94Eo7Vt008196; Tue, 4 Oct 2005 10:50:07 -0400 (EDT) To: "jan aerts (RI)" Cc: "Jaime Casanova" , pgsql-sql@postgresql.org Subject: Re: combination of function to simple query makes query slow In-reply-to: <84DA9D8AC9B05F4B889E7C70238CB45101FD6557@rie2ksrv1.ri.bbsrc.ac.uk> References: <84DA9D8AC9B05F4B889E7C70238CB45101FD6557@rie2ksrv1.ri.bbsrc.ac.uk> Comments: In-reply-to "jan aerts (RI)" message dated "Tue, 04 Oct 2005 09:27:56 +0100" Date: Tue, 04 Oct 2005 10:50:07 -0400 Message-ID: <8195.1128437407@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/4 X-Sequence-Number: 22857 "jan aerts (RI)" writes: > My Postgres version is 7.3.4 (on a central server, so I can't upgrade if > that would be one of the suggestions...) 7.3.4 has multiple known data-loss bugs and security issues. If you're dealing with someone who won't upgrade it, find someone else to deal with. At the very least they need to move to 7.3.10 (or as of today, 7.3.11). See http://developer.postgresql.org/docs/postgres/release-7-3-11.html and following pages for reasons why. > I thought that making a function stable or immutable would make it > available for an index search. Your problem isn't the function, it's the IN (SELECT ...) construct. 7.3 is not bright enough to optimize that. (Given that it's a correlated sub-SELECT, I'm afraid later releases aren't either :-(.) You need to find a way of expressing the query without that. My guess is that trying to use a function for this is counterproductive in itself; the table access that's going on inside the function needs to be exposed for optimization in order to get reasonable overall performance. regards, tom lane