Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 3BB68633DA9 for ; Mon, 19 Jul 2010 03:16:31 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 58108-02 for ; Mon, 19 Jul 2010 06:16:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id 751C563439F for ; Mon, 19 Jul 2010 03:08:55 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id DC5689F90; Mon, 19 Jul 2010 14:07:50 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 3BAF8AEAEA; Mon, 19 Jul 2010 14:06:17 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id KGPuwTrhB3KF; Mon, 19 Jul 2010 14:06:08 +0800 (WST) Received: from [10.1.1.6] (124-168-255-56.dyn.iinet.net.au [124.168.255.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id C2387AE628; Mon, 19 Jul 2010 14:06:08 +0800 (WST) Message-ID: <4C43EBEB.8070704@postnewspapers.com.au> Date: Mon, 19 Jul 2010 14:08:43 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: Srikanth CC: pgsql-performance@postgresql.org Subject: Re: What is the best way to optimize the query. References: <4C416ED2.4000008@inventum.net> In-Reply-To: <4C416ED2.4000008@inventum.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_20=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/279 X-Sequence-Number: 39668 On 17/07/10 16:50, Srikanth wrote: > I am sending u the query along with execution plan. Please help > > explain analyze select > s.*,a.actid,a.phone,d.domid,d.domname,d.domno,a.actno,a.actname,p.descr > as svcdescr > from vwsubsmin s > inner join packages p on s.svcno=p.pkgno > inner join account a on a.actno=s.actno > inner join ssgdom d on a.domno=d.domno > inner join (select subsno from getexpiringsubs(1,cast(2 as > integer),cast(3 as double precision), > '4') as (subsno int,expirydt timestamp without time zone,balcpt double > precision)) as e > on s.subsno=e.subsno > where s.status <=15 and d.domno=273 > order by d.domname,s.expirydt,a.actname Lots of those names in the join list are views, aren't they? I doubt anyone can help you unless you show the definition of your views and the schema of your tables. Also, consider attaching the EXPLAIN ANALYZE output as a text attachment, as your mail client is "helpfully" rewrapping it into unintelligible gibberish. -- Craig Ringer