Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id CC5399FA2BC for ; Mon, 9 Apr 2007 18:34:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 55505-03 for ; Mon, 9 Apr 2007 18:34:41 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.227]) by postgresql.org (Postfix) with ESMTP id 73C4E9FA1FD for ; Mon, 9 Apr 2007 18:34:41 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id 50so947222wri for ; Mon, 09 Apr 2007 14:34:40 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Z3SW0y4B+ngmfzOMYFiDnLVlcXKgsNqNqlMQnX4PQvy1B9zvU0Ab8offoouOn+I6mEsxr1pNm2NlMA7cALcdUMfYIve/E5rnhINtQVTLfY5nftf3qCutaRC4aMM15W1IbjxpcplYbr67/W+IbunQfK9cHfrCj7f2eKhENapVbdE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=n1rDKtDlGLo8sxQZag5vA2WGuzdSCQZmeJkMC8DUiowk3cAGDF2iuiAtkzy9zW7WAfeQwhEwFYfE52JxQV68QyZwoGlOYzncGgzDTvE3q6BI8U5d63ClRJFSk0c18JRq3PDdDoLfGWtudt3XTdFNeLuQbzebU4tnjxr93hzczi8= Received: by 10.78.204.20 with SMTP id b20mr937498hug.1176154479607; Mon, 09 Apr 2007 14:34:39 -0700 (PDT) Received: by 10.78.35.18 with HTTP; Mon, 9 Apr 2007 14:34:39 -0700 (PDT) Message-ID: Date: Mon, 9 Apr 2007 17:34:39 -0400 From: "Merlin Moncure" To: "Tom Lane" Subject: Re: join to view over custom aggregate seems like it should be faster Cc: "PostgreSQL Performance" In-Reply-To: <10651.1176152866@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <10651.1176152866@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/216 X-Sequence-Number: 24093 On 4/9/07, Tom Lane wrote: > "Merlin Moncure" writes: > > I have an odd performance issue on 8.2 that I'd thought I'd document > > here. I have a workaround, but I'm if there is something that I'm not > > seeing. > > It's hard to comment on this without seeing the full details of the view > and tables. I'm wondering where the SubPlans are coming from, for instance. ok, this is really odd. I was in the process of busting all that out for you when I noticed this: here is the source sql for the view create or replace view latest_download as select software_binary_id, host_id, (( select latest_software_download( (bds_status_id, mtime, dl_window_open, dl_window_close, download_start, download_stop, info, userupgradeable, overrideflag, percent_complete)::software_download_data) )::software_download_data).* from software_download group by host_id, software_binary_id; here is what psql \d shows: SELECT software_download.software_binary_id, software_download.host_id, ((SELECT latest_software_download(ROW(software_download.bds_status_id, software_download.mtime, software_download.dl_window_open, software_download.dl_window_close, software_download.download_start, software_download.download_stop, software_download.info, software_download.userupgradeable, software_download.overrideflag, software_download.percent_complete)::software_download_data) AS latest_software_download)).bds_status_id AS bds_status_id, ((SELECT l [snip] this is repeated several more times...I replace the view just to be safe. for posterity: create or replace function max_software_download(l software_download_data, r software_download_data) returns software_download_data as $$ begin if l.mtime > r.mtime then return l; end if; return r; end; $$ language plpgsql; CREATE TYPE software_download_data as ( bds_status_id integer, mtime timestamp with time zone, dl_window_open time without time zone, dl_window_close time without time zone, download_start timestamp with time zone, download_stop timestamp with time zone, info text, userupgradeable boolean, overrideflag boolean, percent_complete integer ); CREATE AGGREGATE latest_software_download ( BASETYPE=software_download_data, SFUNC=max_software_download, STYPE=software_download_data ); merlin