Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id BE2CD9FB89F for ; Thu, 12 Jul 2007 19:15:01 -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 35721-07 for ; Thu, 12 Jul 2007 19:14:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (unknown [87.127.95.194]) by postgresql.org (Postfix) with ESMTP id EFB409FB85F for ; Thu, 12 Jul 2007 19:14:58 -0300 (ADT) Received: from localhost.enta.net ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1I96vv-0001Wd-OL; Thu, 12 Jul 2007 23:14:47 +0100 From: Gregory Stark To: Cc: Subject: Re: Query Plan In-Reply-To: <63759.63.118.86.10.1184274660.squirrel@www.88thstreet.com> (Radhika Sambamurti's message of "Thu, 12 Jul 2007 17:11:00 -0400 (EDT)") Organization: EnterpriseDB References: <63759.63.118.86.10.1184274660.squirrel@www.88thstreet.com> X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.sql" 575) Date: Thu, 12 Jul 2007 23:14:47 +0100 Message-ID: <874pk96zhk.fsf@oxford.xeocode.com> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/75 X-Sequence-Number: 28810 "Radhika Sambamurti" writes: > When I run the query with combination of FirmClearingID & status the run > times are approx 3700ms. > But when I add tradedate ie date_trunc('day', tradedate) = '20070703' the > run time becomes a horrendous 19631.958 ms. I'm not really able to make heads or tails of your plans without the query. But any where clause of the form date_trunc('...',col)='...' will always generate crappy plans. And it looks like you already have expressions of that form in the view even in the one which you label "without date_trunc". Instead try to write a where clause that the database can understand the end points of. Something like (col >= '20070703' and col < '20070704'). That's something the database can apply a normal index to and also something it can have a chance at guessing how many rows will fit. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com