Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 6CEDA2E0038 for ; Wed, 9 Apr 2008 08:16:43 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 57787-10 for ; Wed, 9 Apr 2008 08:16:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by developer.postgresql.org (Postfix) with ESMTP id 2AE352E0035 for ; Wed, 9 Apr 2008 08:16:31 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id BBB772E59; Wed, 9 Apr 2008 19:16:21 +0800 (WST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 478581E0434; Wed, 9 Apr 2008 19:16:24 +0800 (WST) Message-ID: <47FCA58D.5070904@postnewspapers.com.au> Date: Wed, 09 Apr 2008 19:16:29 +0800 From: Craig Ringer User-Agent: Icedove 1.5.0.12 (X11/20070607) MIME-Version: 1.0 To: "Luigi N. Puleio" Cc: pgsql-performance@postgresql.org Subject: Re: EXPLAIN detail References: <931174.41521.qm@web33505.mail.mud.yahoo.com> In-Reply-To: <931174.41521.qm@web33505.mail.mud.yahoo.com> X-Enigmail-Version: 0.94.2.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/104 X-Sequence-Number: 29597 Luigi N. Puleio wrote: > SELECT > (a.column1)::date, MIN(b.column2) - a.column2 > FROM > table a > inner join table b > on ((a.column1)::date = (b.column1)::date amd > b.column3 = 'b' and (b.column1)::time without time > zone >= (a.column1)::time without time zone) > WHERE > (a.column1)::date = '2008-04-09' > a.column3 = 'a' > GROUP BY a.column1 > > and with this I have to obtain like 3-4 records from > all those whole 500000 records and with the explain > analyze I get almost 6 seconds: > > Nested Loop (cost=0.00...52140.83 rows=1 width=34) > (actual time=4311.756...5951.271 rows=1 loops=1) With all that casting, is it possible that appropriate indexes aren't being used because your WHERE / ON clauses aren't an exact type match for the index? Can you post the full EXPLAIN ANALYZE from the query? This snippet doesn't even show how records are being looked up. What about a \d of the table from psql, or at least a summary of the involved column data types and associated indexes? -- Craig Ringer