X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id AFEF39F946D for ; Sat, 20 May 2006 22:42:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 31788-10 for ; Sat, 20 May 2006 22:42:00 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from hub.org (hub.org [200.46.204.220]) by postgresql.org (Postfix) with ESMTP id 600119FA387 for ; Sat, 20 May 2006 22:42:00 -0300 (ADT) Received: from localhost (mx1.hub.org [200.46.208.251]) by hub.org (Postfix) with ESMTP id 2A14F290C35 for ; Sat, 20 May 2006 22:41:54 -0300 (ADT) Received: from hub.org ([200.46.204.220]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 35344-08 for ; Sat, 20 May 2006 22:41:56 -0300 (ADT) Received: from ganymede.hub.org (blk-7-151-244.eastlink.ca [71.7.151.244]) by hub.org (Postfix) with ESMTP id 3673D290C1F for ; Sat, 20 May 2006 22:41:50 -0300 (ADT) Received: by ganymede.hub.org (Postfix, from userid 1000) id 9130A61860; Sat, 20 May 2006 22:42:00 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ganymede.hub.org (Postfix) with ESMTP id 906E86185A for ; Sat, 20 May 2006 22:42:00 -0300 (ADT) Date: Sat, 20 May 2006 22:42:00 -0300 (ADT) From: "Marc G. Fournier" X-X-Sender: scrappy@ganymede.hub.org To: pgsql-sql@postgresql.org Subject: timestamp query doesn't use an index ... Message-ID: <20060520223704.T1114@ganymede.hub.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/158 X-Sequence-Number: 25189 I'm trying to figure out some way to speed up the following query: select ps2.page_id, ps2.template_component_id, max(ps2.start_time) from page_schedule ps2 where ps2.start_time at time zone 'MST7MDT' <= '2006-5-17 8:9:18' group by ps2.page_id, ps2.template_component_id When run through EXPLAIN ANALYZE, it shows: QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- HashAggregate (cost=2613.28..2614.17 rows=72 width=16) (actual time=976.629..976.938 rows=128 loops=1) -> Seq Scan on page_schedule ps2 (cost=0.00..2364.95 rows=33110 width=16) (actual time=0.021..623.363 rows=94798 loops=1) Filter: (timezone('MST7MDT'::text, start_time) <= '2006-05-17 08:09:18'::timestamp without time zone) Total runtime: 977.224 ms (4 rows) I've tried doing a function index, like: create index start_time_page_schedule on page_schedule using btree ( timezone('MST7MDT'::text, start_time ) ); But, same result ... whereas, if I change the <= to just =, the index is used, but that is expected ... Is there some other way I can either write above query *or* do an index, such that it will use the index? thanks ... ---- Marc G. Fournier Hub.Org Networking Services (http://www.hub.org) Email . scrappy@hub.org MSN . scrappy@hub.org Yahoo . yscrappy Skype: hub.org ICQ . 7615664