pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
index usage on timestamp without time zone
2+ messages / 2 participants
[nested] [flat]

* index usage on timestamp without time zone
@ 2011-04-28 14:38 Gerhard Hintermayer <gerhard.hintermayer@gmail.com>
  2011-04-28 15:07 ` Re: index usage on timestamp without time zone Kevin Grittner <Kevin.Grittner@wicourts.gov>
  0 siblings, 1 reply; 2+ messages in thread

From: Gerhard Hintermayer @ 2011-04-28 14:38 UTC (permalink / raw)
  To: pgsql-admin

I'm trying to make use of indices for following table
auftrag_l1

a_nr       | integer
ts         | timestamp without time zone
and 10-15 other columns

I do have indices
    "idx_auftrag_l1_anr" btree (a_nr)
    "idx_auftrag_l1_ts" btree (ts)

when I query the table by

explain analyze select * from auftrag_l1 where ts>'01-01-2009'::timestamp
without time zone and ts <' 31-12-2010'::timestamp without time zone;

I get the following query plan

 Seq Scan on auftrag_l1  (cost=0.00..334.04 rows=4885 width=89) (actual
time=0.097..4.172 rows=4893 loops=1)
   Filter: ((ts > 'Thu 01 Jan 00:00:00 2009'::timestamp without time zone)
AND (ts < 'Fri 31 Dec 00:00:00 2010'::timestamp without time zone))
 Total runtime: 4.933 ms
(3 rows)

Is there a way to make postgres use the index on the timestamp column ? The
timing is from a test table, production tables have a lot more rows.
Interesting, that the #rows decrease, when I shorten the timespan, so the
number of rows scanned is influenced by the selected timespan, but postgres
still does seq. scans.

Gerhard

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: index usage on timestamp without time zone
  2011-04-28 14:38 index usage on timestamp without time zone Gerhard Hintermayer <gerhard.hintermayer@gmail.com>
@ 2011-04-28 15:07 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
  0 siblings, 0 replies; 2+ messages in thread

From: Kevin Grittner @ 2011-04-28 15:07 UTC (permalink / raw)
  To: Gerhard Hintermayer <gerhard.hintermayer@gmail.com>; pgsql-admin

Gerhard Hintermayer <gerhard.hintermayer@gmail.com> wrote:
 
> Is there a way to make postgres use the index on the timestamp
> column ? The timing is from a test table, production tables have a
> lot more rows.
 
It's a mistake to assume that the plan you get on a small table will
resemble the plan you will get on a big table.  If you want to know
what the plan will be on the big table, at least run an EXPLAIN of
the query on that big table.
 
-Kevin



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-04-28 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-04-28 14:38 index usage on timestamp without time zone Gerhard Hintermayer <gerhard.hintermayer@gmail.com>
2011-04-28 15:07 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>

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