Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8234EB5DBB6 for ; Sun, 22 May 2011 20:11:49 -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 21276-04 for ; Sun, 22 May 2011 23:11:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gransy.com (mail.gransy.com [82.208.29.194]) by mail.postgresql.org (Postfix) with ESMTP id ACFBCB5D8B2 for ; Sun, 22 May 2011 20:11:42 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.gransy.com (Postfix) with ESMTP id 48DFE4A21D7 for ; Mon, 23 May 2011 01:11:40 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at nathalia.gransy.com Received: from mail.gransy.com ([127.0.0.1]) by localhost (Nathalka.gransy.com.gransy.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KwKpMZAEF2Po for ; Mon, 23 May 2011 01:11:39 +0200 (CEST) Received: from [192.168.1.221] (ip-94-112-0-189.net.upcbroadband.cz [94.112.0.189]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id CC34B4A21D3 for ; Mon, 23 May 2011 01:11:39 +0200 (CEST) Message-ID: <4DD9982C.6000807@fuzzy.cz> Date: Mon, 23 May 2011 01:11:40 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101219 Lightning/1.0b3pre Thunderbird/3.1.7 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: SORT performance - slow? References: In-Reply-To: X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/293 X-Sequence-Number: 43802 Dne 19.5.2011 23:13, Strange, John W napsal(a): > Am I reading this right in that the sort is taking almost 8 seconds? You're probably reading it wrong. The sort itself takes about 1 ms (just subtract the numbers in "actual="). If you include all the overhead it takes about 2.3 seconds (the hash join ends at 12 sec, the sort at 14.3). Anyway, your real problem is probably stale stats. Run ANALYZE on the tables referenced in the query, the estimates are very off. All the rows expect 1 row but are getting 315k of them. regards Tomas