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 950069FA131; Sun, 21 May 2006 12:31:11 -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 84742-01; Sun, 21 May 2006 12:31:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E40D19FA159; Sun, 21 May 2006 12:31:02 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k4LFV2sY005288; Sun, 21 May 2006 11:31:02 -0400 (EDT) To: "Marc G. Fournier" cc: pgsql-sql@postgresql.org Subject: Re: timestamp query doesn't use an index ... In-reply-to: <20060520223704.T1114@ganymede.hub.org> References: <20060520223704.T1114@ganymede.hub.org> Comments: In-reply-to "Marc G. Fournier" message dated "Sat, 20 May 2006 22:42:00 -0300" Date: Sun, 21 May 2006 11:31:02 -0400 Message-ID: <5287.1148225462@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/163 X-Sequence-Number: 25194 "Marc G. Fournier" writes: > 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 > Is there some other way I can either write above query *or* do an index, > such that it will use the index? One-sided inequalities frequently *shouldn't* use an index, because they're retrieving too much of the table. Are you sure this is fetching only a small fraction of the table? Are you using PG 8.1 (8.1 would be likely to try to use a bitmap indexscan for this)? You could experiment with enable_seqscan = off to see if the planner is actually wrong about its choice. If so, reducing random_page_cost might be the best permanent solution. regards, tom lane