Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6777368538E for ; Thu, 10 Jun 2010 23:11:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 28736-08 for ; Fri, 11 Jun 2010 02:11:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (vcs5.camavision.com [63.228.164.252]) by mail.postgresql.org (Postfix) with ESMTP id 3CF01684B23 for ; Thu, 10 Jun 2010 23:11:15 -0300 (ADT) Received: from [192.168.1.103] (173-20-246-8.client.mchsi.com [173.20.246.8]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id 44D325B8C6; Thu, 10 Jun 2010 21:11:12 -0500 (CDT) Message-ID: <4C119B3E.3090608@squeakycode.net> Date: Thu, 10 Jun 2010 21:11:10 -0500 From: Andy Colson User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: David Jarvis , pgsql-performance@postgresql.org Subject: Re: Analysis Function References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201006/195 X-Sequence-Number: 39051 On 06/10/2010 07:41 PM, David Jarvis wrote: > Hi, > > I found a slow part of the query: > > SELECT > * date(extract(YEAR FROM m.taken)||'-1-1') d1,* > * date(extract(YEAR FROM m.taken)||'-1-31') d2* > FROM > climate.city c, > climate.station s, > climate.station_category sc, > climate.measurement m > WHERE > c.id = 5148 AND ... > > Date extraction is 3.2 seconds, but without is 1.5 seconds. The PL/pgSQL > code that actually runs (where p_month1, p_day1, and p_month2, p_day2 > are integers): > > * date(extract(YEAR FROM > m.taken)||''-'||p_month1||'-'||p_day1||''') d1, > date(extract(YEAR FROM > m.taken)||''-'||p_month2||'-'||p_day2||''') d2 > * > What is a better way to create those dates (without string > concatenation, I presume)? > > Dave > I assume you are doing this in a loop? Many Many Many times? cuz: andy=# select date(extract(year from current_date) || '-1-1'); date ------------ 2010-01-01 (1 row) Time: 0.528 ms Its pretty quick. You say "without" its 1.5 seconds? Thats all you change? Can we see the sql and 'explain analyze' for both? -Andy