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 C323F5E3F15 for ; Sun, 29 Aug 2004 15:57:53 -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 22332-03 for ; Sun, 29 Aug 2004 18:57:51 +0000 (GMT) Received: from trofast.sesse.net (trofast.sesse.net [129.241.93.32]) by svr1.postgresql.org (Postfix) with ESMTP id 58A5C5E3631 for ; Sun, 29 Aug 2004 15:57:50 -0300 (ADT) Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1C1UsA-0007s4-00 for ; Sun, 29 Aug 2004 20:57:50 +0200 Date: Sun, 29 Aug 2004 20:57:50 +0200 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: Why does a simple query not use an obvious index? Message-ID: <20040829185750.GA30018@uio.no> References: <20040829180448.41247.qmail@web41108.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040829180448.41247.qmail@web41108.mail.yahoo.com> X-Operating-System: Linux 2.6.6 on a i686 User-Agent: Mutt/1.5.6+20040818i 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/426 X-Sequence-Number: 8062 On Sun, Aug 29, 2004 at 11:04:48AM -0700, Mr Pink wrote: > Another is that if the condition data types don't match then an indes won't be used you could try: > > select count(*) from billing where timestamp > (now()-60)::timestamp In fact, I've had success with code like select count(*) from billing where timestamp > ( select now() - interval '1 minute' ) At least in my case (PostgreSQL 7.2, though), it made PostgreSQL magically do an index scan. :-) /* Steinar */ -- Homepage: http://www.sesse.net/