X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 642B3476141 for ; Thu, 8 May 2003 12:25:02 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id B3CC747592C for ; Thu, 8 May 2003 12:25:01 -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 h48GP7U6020979; Thu, 8 May 2003 12:25:07 -0400 (EDT) To: "David Olbersen" Cc: pgsql-performance@postgresql.org Subject: Re: Type casting and indexes In-reply-to: References: Comments: In-reply-to "David Olbersen" message dated "Thu, 08 May 2003 08:36:27 -0700" Date: Thu, 08 May 2003 12:25:07 -0400 Message-ID: <20978.1052411107@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-29.3 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,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/107 X-Sequence-Number: 1886 "David Olbersen" writes: > 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. Seems like I just answered this yesterday ;-) Note the difference in the number of estimated rows in the two explains. The reason is that the timestamptz conversion is not a constant and so the planner can't get a good estimate of the number of rows that will satisfy it. (And the reason it's not a constant is that it depends on SET TIMEZONE.) Bottom line: declare the constant correctly. Or at least don't gratuitously cast it to the wrong thing. regards, tom lane