X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5224ED1B4E6 for ; Thu, 23 Oct 2003 15:30:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 76530-04 for ; Thu, 23 Oct 2003 12:29:50 -0300 (ADT) Received: from web13805.mail.yahoo.com (web13805.mail.yahoo.com [216.136.175.15]) by svr1.postgresql.org (Postfix) with SMTP id EF794D1B517 for ; Thu, 23 Oct 2003 12:29:49 -0300 (ADT) Message-ID: <20031023152944.56378.qmail@web13805.mail.yahoo.com> Received: from [216.173.173.66] by web13805.mail.yahoo.com via HTTP; Thu, 23 Oct 2003 08:29:44 PDT Date: Thu, 23 Oct 2003 08:29:44 -0700 (PDT) From: Chris Gamache Reply-To: cgg007@yahoo.com Subject: Re: Query planner: current_* vs. explicit date To: Tom Lane , pgsql-sql@postgresql.org In-Reply-To: <24641.1066862720@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/307 X-Sequence-Number: 15707 Thanks Tom (and others!) Right-on-the-money, as always... By giving it a definitive range I was able to coax query planner to use the index: SELECT id FROM trans_table WHERE trans_date >= (SELECT current_date::timestamptz) AND trans_date < (SELECT current_timestamp); gave me from midnight to the present... Aside from a slight amount of ugliness, the solution is quite adequate. The subselects shouldn't cause too much overhead, yes? BTW, This didn't work: SELECT id FROM trans_table WHERE trans_date >= current_date::timestamptz AND trans_date < current_timestamp; Which was a "nonconstant" version of the above. I think it still suffers from the timestamp >= unknown_value problem. CG --- Tom Lane wrote: > being careful that both comparison values are nonconstant (don't use > 'infinity'::timestamp, for instance, even though that might seem like > a reasonable thing to do). The planner still has no idea how many rows > will be fetched exactly, but it does realize that this is a range > condition, and its default assumption about the number of matching rows > is small enough to encourage indexscan use. > > Of course this workaround assumes that you can pick an upper bound that > you are sure is past the end of the available values, but that's usually > not hard in the sort of context where you would have thought that the > one-sided inequality test is a sane thing to do anyway. __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com