Skip site navigation (1) Skip section navigation (2)

Re: Why does a simple query not use an obvious index?

From: "Steinar H(dot) Gunderson" <sgunderson(at)bigfoot(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Why does a simple query not use an obvious index?
Date: 2004-08-29 18:57:50
Message-ID: 20040829185750.GA30018@uio.no (view raw or flat)
Thread:
Lists: pgsql-performance
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/

In response to

pgsql-performance by date

Next:From: Josh BerkusDate: 2004-08-29 18:59:01
Subject: Re: Equivalent praxis to CLUSTERED INDEX?
Previous:From: Scott MarloweDate: 2004-08-29 18:28:48
Subject: Re: Why does a simple query not use an obvious index?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group