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 DA9A15E46FA for ; Sun, 29 Aug 2004 18:12:15 -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 51315-07 for ; Sun, 29 Aug 2004 21:12:13 +0000 (GMT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by svr1.postgresql.org (Postfix) with ESMTP id 778AA5E46F2 for ; Sun, 29 Aug 2004 18:12:13 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1C1Wy5-0007qc-00; Sun, 29 Aug 2004 17:12:05 -0400 To: "Scott Marlowe" Cc: "Jack Kerkhof" , pgsql-performance@postgresql.org Subject: Re: Why does a simple query not use an obvious index? References: <1093804128.5493.22.camel@localhost.localdomain> In-Reply-To: <1093804128.5493.22.camel@localhost.localdomain> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 29 Aug 2004 17:12:05 -0400 Message-ID: <87fz65k5sq.fsf@stark.xeocode.com> Lines: 20 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/429 X-Sequence-Number: 8065 "Scott Marlowe" writes: > Also, count(*) is likely to always generate a seq scan due to the way > aggregates are implemented currently in pgsql. you might want to try: Huh? I'm curious to know what you're talking about here. > select somefield from sometable where timestampfield > now()-'60 > seconds'::interval > > and count the number of returned rows. If there's a lot, it won't be > any faster, if there's a few, it should be a win. Why would this ever be faster? And how could postgres ever calculate that without doing a sequential scan when count(*) would force it to do a sequential scan? -- greg