Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1cOH-0001XP-Bi for pgsql-bugs@arkaria.postgresql.org; Mon, 30 Jun 2014 14:17:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X1cOG-0006A1-K5 for pgsql-bugs@arkaria.postgresql.org; Mon, 30 Jun 2014 14:17:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1cOF-00069D-G3 for pgsql-bugs@postgresql.org; Mon, 30 Jun 2014 14:17:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1cOB-00025N-QT for pgsql-bugs@postgresql.org; Mon, 30 Jun 2014 14:17:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s5UEGvda004201; Mon, 30 Jun 2014 10:16:57 -0400 From: Tom Lane To: bashtanov@imap.cc cc: pgsql-bugs@postgresql.org Subject: Re: BUG #10816: explain analyze reports different rows counts before and after sort In-reply-to: <20140630094343.15698.80138@wrigleys.postgresql.org> References: <20140630094343.15698.80138@wrigleys.postgresql.org> Comments: In-reply-to bashtanov@imap.cc message dated "Mon, 30 Jun 2014 09:43:43 -0000" Date: Mon, 30 Jun 2014 10:16:57 -0400 Message-ID: <4200.1404137817@sss.pgh.pa.us> X-Pg-Spam-Score: -0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org bashtanov@imap.cc writes: > Please have a look at the two bottom nodes of the plan. Function scan > produces 1000 rows, then they are sorted and turn into 3201 rows! How could > this happen? The discrepancy is easily explained because the sort is the righthand child of a merge join. Merge join will rewind and rescan its right child every time the left child produces duplicate keys, so that the appropriate right-child rows get joined to all the similarly-keyed rows from the left child. And you do have duplicate outputs coming from that left child ... IOW, it's just a measurement artifact arising from re-fetching the same rows repeatedly. I think there's a warning about this in the docs. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs