X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6308654B0C for ; Tue, 26 Apr 2005 17:49:04 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13394-08 for ; Tue, 26 Apr 2005 20:49:01 +0000 (GMT) Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by svr1.postgresql.org (Postfix) with ESMTP id 0B7B0540C2 for ; Tue, 26 Apr 2005 17:48:58 -0300 (ADT) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.34) id 1DQWzJ-0008GM-BM for pgsql-performance@postgresql.org; Tue, 26 Apr 2005 22:48:58 +0200 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1DQWzF-0007lA-00 for ; Tue, 26 Apr 2005 22:48:53 +0200 Date: Tue, 26 Apr 2005 22:48:53 +0200 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: speed up query with max() and odd estimates Message-ID: <20050426204853.GA29424@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Operating-System: Linux 2.6.11-rc3 on a i686 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.017 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/706 X-Sequence-Number: 12103 On Tue, Apr 26, 2005 at 03:16:57PM -0500, Matthew Nuzum wrote: > Seq Scan on usage_access (cost=0.00..1183396.40 rows=12713851 > width=116) (actual time=481796.22..481839.43 rows=3343 loops=1) That's a gross misestimation -- four orders of magnitude off! Have you considering doing this in two steps, first getting out whatever comes from the subquery and then doing the query? Have you ANALYZEd recently? Do you have an index on atime? /* Steinar */ -- Homepage: http://www.sesse.net/