Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 2FC8337C762 for ; Thu, 9 Oct 2008 16:31:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 60737-07 for ; Thu, 9 Oct 2008 16:31:01 -0300 (ADT) 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 postgresql.org (Postfix) with ESMTP id F1E2037C77C for ; Thu, 9 Oct 2008 16:31:01 -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 m99JUpHU003694; Thu, 9 Oct 2008 15:30:51 -0400 (EDT) To: "Sabin Coanda" cc: pgsql-performance@postgresql.org Subject: Re: low performance on functions returning setof record In-reply-to: References: Comments: In-reply-to "Sabin Coanda" message dated "Thu, 09 Oct 2008 17:47:30 +0300" Date: Thu, 09 Oct 2008 15:30:51 -0400 Message-ID: <3693.1223580651@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200810/45 X-Sequence-Number: 31626 "Sabin Coanda" writes: > I use different functions returning setof record, and they are working well. > The problem is the performance when I use those functions in joins, for > instance: > SELECT * > FROM "Table1" t1 > JOIN "Function1"( a1, a2, ... aN ) AS f1( ColA int4, ColB > varchar, ... ) > ON t1.ColX = f1.ColA > The problem is I'm not able to make indexes on the function, even inside I > have just another select statement from different permanent tables, with > some where clauses depending on the function arguments. There's not a lot you can do about that at the moment. 8.4 will have the ability to inline functions returning sets, if they're SQL-language and consist of just a single SELECT, but existing releases won't do it. You might consider trying to refactor your stuff to use views ... regards, tom lane