X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E03D853583 for ; Mon, 25 Apr 2005 19:06:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54288-06 for ; Mon, 25 Apr 2005 22:06:31 +0000 (GMT) Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by svr1.postgresql.org (Postfix) with ESMTP id 7D67C535A6 for ; Mon, 25 Apr 2005 19:06:29 -0300 (ADT) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO temoku.sf.agliodbs.com) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 7283943; Mon, 25 Apr 2005 15:08:28 -0700 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Ron Mayer Subject: Re: half the query time in an unnecessary(?) sort? Date: Mon, 25 Apr 2005 15:11:41 -0700 User-Agent: KMail/1.7.1 Cc: pgsql-performance@postgresql.org References: <426D4FA1.1050000@cheapcomplexdevices.com> In-Reply-To: <426D4FA1.1050000@cheapcomplexdevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200504251511.41949.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.047 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/685 X-Sequence-Number: 12082 Ron, > If I have a freshly CLUSTERed table and queries that want to do a > merge join, it seems to me that quite a bit of time is spent > unnecessarily sorting the already-sorted table. An example such > query I found in my log files is shown below. If I read the > EXPLAIN ANALYZE output correctly, it's saying that roughly half > the time (570-269 = 300 out of 670 ms) was spent sorting the > already sorted data. It still has to sort because the clustering isn't guarenteed to be 100%. However, such sorts should be very quick as they have little work to do. Looking at your analyze, though, I think it's not the sort that's taking the time as it is that the full sorted entity_id column won't fit in work_mem. Try increasing it? -- --Josh Josh Berkus Aglio Database Solutions San Francisco