pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedUse of to_timestamp causes full scan
2+ messages / 2 participants
[nested] [flat]
* Use of to_timestamp causes full scan
@ 2003-09-02 17:50 Zaremba, Don <dzaremba@ellacoya.com>
2003-09-02 18:06 ` Re: Use of to_timestamp causes full scan Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Zaremba, Don @ 2003-09-02 17:50 UTC (permalink / raw)
To: pgsql-performance
Has anyone seen any performace problems with the use to to_timestamp?
When I use it in a where clause I get a full file scan, when I don't it
uses the index
for the query. The begin_time column is of type timestamp.
This does a full sequential scan
select id from details where begin_time > to_timestamp('03/08/25
18:30');
This uses the index
select id from details where begin_time > '03/08/25 18:30';
Don
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Use of to_timestamp causes full scan
2003-09-02 17:50 Use of to_timestamp causes full scan Zaremba, Don <dzaremba@ellacoya.com>
@ 2003-09-02 18:06 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2003-09-02 18:06 UTC (permalink / raw)
To: Zaremba, Don <dzaremba@ellacoya.com>; +Cc: pgsql-performance
"Zaremba, Don" <dzaremba@ellacoya.com> writes:
> This does a full sequential scan
> select id from details where begin_time > to_timestamp('03/08/25
> 18:30');
to_timestamp('foo') is not a constant, so the planner doesn't know how
much of the table this is going to select. In the absence of that
knowledge, its default guess favors a seqscan.
> This uses the index
> select id from details where begin_time > '03/08/25 18:30';
Here the planner can consult pg_stats to get a pretty good idea how
much of the table will be scanned; if the percentage is small enough
it will pick an indexscan.
There are various ways to deal with this --- one thing you might
consider is making a wrapper function for to_timestamp that is
marked "immutable", so that it will be constant-folded on sight.
That has potential gotchas if you want to put the query in a function
though. Another tack is to make the query into a range query:
where begin_time > ... AND begin_time < 'infinity';
See the archives for more discussion.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-09-02 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-02 17:50 Use of to_timestamp causes full scan Zaremba, Don <dzaremba@ellacoya.com>
2003-09-02 18:06 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox