Re: Index on timestamp field, and now() - Mailing list pgsql-general

From Tom Lane
Subject Re: Index on timestamp field, and now()
Date
Msg-id 7553.1013446830@sss.pgh.pa.us
Whole thread Raw
In response to Re: Index on timestamp field, and now()  (Denis Perchine <dyp@perchine.com>)
Responses Re: Index on timestamp field, and now()
List pgsql-general
Denis Perchine <dyp@perchine.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

pgsql-general by date:

Previous
From: Jean-Michel POURE
Date:
Subject: Re: [HACKERS] Feature enhancement request : use of libgda in
Next
From: Bradley Brown
Date:
Subject: Re: initdb - segmentation fault