X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 145E39DC87D for ; Fri, 24 Mar 2006 08:59:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04240-01 for ; Fri, 24 Mar 2006 08:59:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id C27999DC842 for ; Fri, 24 Mar 2006 08:59:16 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 4ADE656408; Fri, 24 Mar 2006 06:59:20 -0600 (CST) Received: (hashcash-sendmail, from uid 1001); Fri, 24 Mar 2006 06:59:19 -0600 Date: Fri, 24 Mar 2006 06:59:19 -0600 From: "Jim C. Nasby" To: Svenne Krap Cc: pgsql-performance@postgresql.org Subject: Re: Performance problems with multiple layers of functions Message-ID: <20060324125919.GD90527@pervasive.com> References: <4423EACD.80706@krap.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4423EACD.80706@krap.dk> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060324:svenne@krap.dk::pkQQGUdrLi9ZZY5m:0005tpU X-Hashcash: 1:20:060324:pgsql-performance@postgresql.org::xD3P2ZgJk1+Pt3bg:00000 0000000000000000000000000o4d X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.108 required=5 tests=[AWL=0.108] X-Spam-Score: 0.108 X-Spam-Level: X-Archive-Number: 200603/490 X-Sequence-Number: 17927 On Fri, Mar 24, 2006 at 01:49:17PM +0100, Svenne Krap wrote: > explain select dataset_id, entity, sum(amount) from entrydata_current > where flow_direction in (select * from outflow_direction(dataset_id)) > and dataset_id in (select * from get_dataset_ids(122)) group by > dataset_id, entity; > which does not return within 10 minutes - which is unacceptable. The issue is that the planner has no way to know what's comming back from get_dataset_ids. I think your best bet will be to wrap that select into it's own function and have that function prepare the query statement, going back to hard-coded values. So you could do something like: SQL := 'SELECT ... AND dataset_id IN (''' || get_dataset_ids(122) || ''');' (yeah, I know that won't work as written, but you get the idea). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461