Re: Index on timestamp field, and now()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Denis Perchine <dyp(at)perchine(dot)com>
Cc: lockhart(at)fourpalms(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: Index on timestamp field, and now()
Date: 2002-02-11 17:00:30
Message-ID: 7553.1013446830@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Denis Perchine <dyp(at)perchine(dot)com> writes:
> webmailstation=> explain select * from queue where send_date > timestamp
> 'now';
> NOTICE: QUERY PLAN:

> Seq Scan on queue (cost=0.00..10114.06 rows=80834 width=190)

> EXPLAIN

> Although exact search uses index scan:

> webmailstation=> explain select * from queue where send_date = timestamp
> 'now';
> NOTICE: QUERY PLAN:

> Index Scan using queue_senddate_key on queue (cost=0.00..5.95 rows=1
> width=190)

> EXPLAIN

The second case proves that it's not a datatype or not-a-constant
problem. I'd guess that the failure of the first case indicates you've
never ANALYZEd the table, and so you're getting a default selectivity
estimate for the inequality operator (which is way too high to allow an
indexscan). If that's not so, what do you get from

select * from pg_stats where tablename = 'queue';

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Page 2002-02-11 17:16:38 Re: [HACKERS] Feature enhancement request : use of libg
Previous Message Jean-Michel POURE 2002-02-11 16:56:22 Re: [HACKERS] Feature enhancement request : use of libgda in