X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2E3C0DB2B6 for ; Fri, 28 Oct 2005 21:12:09 -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 14117-02 for ; Sat, 29 Oct 2005 00:12:05 +0000 (GMT) Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by svr1.postgresql.org (Postfix) with ESMTP id 41DB4DB257 for ; Fri, 28 Oct 2005 21:12:06 -0300 (ADT) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EVeKM-0005Ce-Tj for pgsql-performance@postgresql.org; Sat, 29 Oct 2005 02:12:08 +0200 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1EVeKe-0001oE-00 for ; Sat, 29 Oct 2005 02:12:24 +0200 Date: Sat, 29 Oct 2005 02:12:24 +0200 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: Simple query: how to optimize Message-ID: <20051029001224.GA6611@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.14-rc5 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.009 required=5 tests=[AWL=0.009] X-Spam-Score: 0.009 X-Spam-Level: X-Archive-Number: 200510/448 X-Sequence-Number: 15216 On Fri, Oct 28, 2005 at 03:40:40PM -0700, Roger Hand wrote: > You're first joining against the entire user table, then filtering out the users > you don't need. That's just wrong, sorry -- the planner is perfectly able to push the WHERE down before the join. I'd guess the problem is the age() query; age() doesn't really return what you'd expect, and I don't think it can use an index easily (I might be wrong here, though). Instead, try something like WHERE u.joined_date >= current_date - interval '30 days' except that if you're running pre-8.0, you might want to precalculate the right-hand side on the client. I couldn't see EXPLAIN ANALYZE of your query, BTW -- having it would be useful. /* Steinar */ -- Homepage: http://www.sesse.net/