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 9F193D1B281 for ; Thu, 15 Jul 2004 09:08:48 -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 34524-06 for ; Thu, 15 Jul 2004 12:08:56 +0000 (GMT) Received: from trofast.sesse.net (trofast.sesse.net [129.241.93.32]) by svr1.postgresql.org (Postfix) with ESMTP id 431BFD1B269 for ; Thu, 15 Jul 2004 09:08:46 -0300 (ADT) Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1Bl52k-000890-00 for ; Thu, 15 Jul 2004 14:08:54 +0200 Date: Thu, 15 Jul 2004 14:08:54 +0200 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: Odd sorting behaviour Message-ID: <20040715120854.GA31259@uio.no> References: <20040708101913.GA15871@uio.no> <200407141841.01863.josh@agliodbs.com> <16637.1089867158@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16637.1089867158@sss.pgh.pa.us> X-Operating-System: Linux 2.6.6 on a i686 User-Agent: Mutt/1.5.6+20040523i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/96 X-Sequence-Number: 7487 On Thu, Jul 15, 2004 at 12:52:38AM -0400, Tom Lane wrote: > No, it's not missing anything. The number being reported here is the > number of rows pulled from the plan node --- but this plan node is on > the inside of a merge join, and one of the properties of merge join is > that it will do partial rescans of its inner input in the presence of > equal keys in the outer input. If you have, say, 10 occurrences of > "42" in the outer input, then any "42" rows in the inner input have to > be rescanned 10 times. EXPLAIN ANALYZE will count each of them as 10 > rows returned by the input node. OK, that makes sense, although it seems to me as is loops= should have been something larger than 1 if the data was scanned multiple times. > The large multiple here (80-to-one overscan) says that you've got a lot > of duplicate values in the outer input. This is generally a good > situation to *not* use a mergejoin in ;-). We do have some logic in the > planner that attempts to estimate the extra cost involved in such > rescanning, but I'm not sure how accurate the cost model is. Hum, I'm not sure if I'm in the termiology here -- "outer input" in "A left join B" is A, right? But yes, I do have a lot of duplicates, that seems to match my data well. > Raising shared_buffers seems unlikely to help. I do agree with raising > sort_mem --- not so much to make the merge faster as to encourage the > thing to try a hash join instead. sort_mem is already 16384, which I thought would be plenty -- I tried increasing it to 65536 which made exactly zero difference. :-) /* Steinar */ -- Homepage: http://www.sesse.net/