X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CC791476141 for ; Thu, 8 May 2003 18:35:15 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 1D307474E4F for ; Thu, 8 May 2003 18:35:14 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h48MZEU6017014; Thu, 8 May 2003 18:35:14 -0400 (EDT) To: Stephan Szabo Cc: David Olbersen , pgsql-performance@postgresql.org Subject: Re: Type casting and indexes In-reply-to: <20030508090101.K43697-100000@megazone23.bigpanda.com> References: <20030508090101.K43697-100000@megazone23.bigpanda.com> Comments: In-reply-to Stephan Szabo message dated "Thu, 08 May 2003 09:13:29 -0700" Date: Thu, 08 May 2003 18:35:14 -0400 Message-ID: <17013.1052433314@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/109 X-Sequence-Number: 1888 Stephan Szabo writes: > On Thu, 8 May 2003, David Olbersen wrote: >> So it seems that the type conversion is killing the use of the index, >> even though the type conversion has to happen for the condition to be >> tested. > IIRC, timestamp->timestamptz is not considered to give a constant value > (ie, is not stable) No: it is stable, but not immutable, because it depends on SET TIMEZONE. (Our policy on those is if you change one mid-query, it's unspecified whether the query will notice or not.) So the query is potentially indexable. The problem here is that instead of seeing a constant, the planner sees a nonconstant function invocation on the right side of '>', and so it has to fall back to a default selectivity estimate instead of being able to extract a reasonable estimate from pg_statistic. The default estimate is high enough to discourage an indexscan ... regards, tom lane