Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id ED6F79FBA49 for ; Tue, 24 Jul 2007 16:25:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 64354-08 for ; Tue, 24 Jul 2007 16:24:57 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 2ECFB9FBA17 for ; Tue, 24 Jul 2007 16:24:59 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l6OJOt5R014908; Tue, 24 Jul 2007 15:24:56 -0400 (EDT) To: arnaulist@andromeiberica.com cc: PostgreSQL Performance Subject: Re: index over timestamp not being used In-reply-to: <46A64475.3040201@andromeiberica.com> References: <46A64475.3040201@andromeiberica.com> Comments: In-reply-to Arnau message dated "Tue, 24 Jul 2007 20:27:01 +0200" Date: Tue, 24 Jul 2007 15:24:55 -0400 Message-ID: <14907.1185305095@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/322 X-Sequence-Number: 26006 Arnau writes: > timestamp_in | timestamp without time zone | default now() > SELECT ... > FROM > transactions t > LEFT OUTER JOIN statistics s ON t.transaction_id = s.transaction_id > WHERE > t.timestamp_in >= to_timestamp('20070101', 'YYYYMMDD') > GROUP BY date, t.type_id; to_timestamp() produces timestamp *with* timezone, so your WHERE query is effectively t.timestamp_in::timestamptz >= to_timestamp('20070101', 'YYYYMMDD') which doesn't match the index. The first question you should ask yourself is whether you picked the right datatype for the column. IMHO timestamp with tz is the more appropriate choice in the majority of cases. If you do want to stick with timestamp without tz, you'll need to cast the result of to_timestamp to that. Alternatively, do you really need to_timestamp at all? The standard timestamp input routine won't have any problem with that format: t.timestamp_in >= '20070101' regards, tom lane