Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id AB63E63222E for ; Thu, 20 May 2010 17:19:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 08542-03 for ; Thu, 20 May 2010 20:19:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 2FDB3634C41 for ; Thu, 20 May 2010 17:19:00 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o4KKIwm8008133; Thu, 20 May 2010 16:18:58 -0400 (EDT) To: David Jarvis cc: Thom Brown , pgsql-performance@postgresql.org Subject: Re: Optimize date query for large child tables: GiST or GIN? In-reply-to: References: <7143.1274382139@sss.pgh.pa.us> <7767.1274385170@sss.pgh.pa.us> <7917.1274385834@sss.pgh.pa.us> Comments: In-reply-to David Jarvis message dated "Thu, 20 May 2010 13:09:05 -0700" Date: Thu, 20 May 2010 16:18:58 -0400 Message-ID: <8132.1274386738@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/125 X-Sequence-Number: 38709 David Jarvis writes: > I was hoping to eliminate this part of the query: > (cast(extract( YEAR FROM m.taken ) + greatest( -1 * > sign( > (extract( YEAR FROM m.taken )||'-12-31')::date - > (extract( YEAR FROM m.taken )||'-01-01')::date ), 0 > ) AS text)||'-12-31')::date > That uses functions to create the dates, which is definitely the problem. Well, it's not the functions per se that's the problem, it's the lack of a useful index on the expression. But as somebody remarked upthread, that expression doesn't look correct at all. Doesn't the whole greatest() subexpression reduce to a constant? regards, tom lane