Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T162b-0005di-J3 for pgsql-performance@postgresql.org; Tue, 14 Aug 2012 01:35:29 +0000 Received: from elizabeth.gransy.com ([89.187.132.199]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T162X-0007bH-6R for pgsql-performance@postgresql.org; Tue, 14 Aug 2012 01:35:28 +0000 Received: from sq.gransy.com (localhost [127.0.0.1]) by elizabeth.gransy.com (Postfix) with ESMTP id 9722C15E426A; Tue, 14 Aug 2012 03:35:21 +0200 (CEST) Received: from 78.45.133.255 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Tue, 14 Aug 2012 03:35:21 +0200 Message-ID: In-Reply-To: References: Date: Tue, 14 Aug 2012 03:35:21 +0200 Subject: Re: 7k records into Sort node, 4.5m out? From: "Tomas Vondra" To: "Christophe Pettus" Cc: pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.22 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 X-Priority: 3 (Normal) Importance: Normal Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: 0.0 (/) X-Archive-Number: 201208/77 X-Sequence-Number: 47615 On 14 Srpen 2012, 3:15, Christophe Pettus wrote: > Consider this EXPLAIN ANALYZE output: > > http://explain.depesz.com/s/TCi > > Note the Bitmap Heap Scan at the bottom claims to be producing 7094 row= s, > and the Sort above it expects to be processing 7330 rows (the same numb= er > the Bitmap Heap Scan expected to produce)... but the sort is actually > producing 4512231 rows, which the sort time would indicate is what real= ly > happened. How can this be? Hi, notice there's a merge join right above the sort. If there are duplicate values in the first table (charlie in the explain plans), the matching rows from the sort will be read repeatedly (re-scanned) and thus counted multiple times. Tomas