Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1Y88-0005Em-Jr for pgsql-bugs@arkaria.postgresql.org; Mon, 30 Jun 2014 09:44:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X1Y88-0000mT-4M for pgsql-bugs@arkaria.postgresql.org; Mon, 30 Jun 2014 09:44:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1Y87-0000mN-FK for pgsql-bugs@postgresql.org; Mon, 30 Jun 2014 09:44:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1Y83-00058S-QH for pgsql-bugs@postgresql.org; Mon, 30 Jun 2014 09:44:06 +0000 MIME-Version: 1.0 Subject: BUG #10816: explain analyze reports different rows counts before and after sort To: pgsql-bugs@postgresql.org From: bashtanov@imap.cc Date: Mon, 30 Jun 2014 09:43:43 +0000 Message-ID: <20140630094343.15698.80138@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.1 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 10816 Logged by: Alexey Bashtanov Email address: bashtanov@imap.cc PostgreSQL version: 9.3.4 Operating system: Ubuntu Linux 12.04 Description: Hello! 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? localhost/stat 13:31:19 > select version(); version ----------------------------------------------------------------------------------------------------- PostgreSQL 9.3.4 on i686-pc-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 32-bit (1 row) localhost/stat 13:31:21 > set enable_hashjoin to off; SET localhost/stat 13:31:22 > explain analyze select * from (select k % 5 b from generate_series(1,4000) k) l natural join generate_series(1,1000) b; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=119.66..227.16 rows=5000 width=4) (actual time=5.977..11.848 rows=3200 loops=1) Merge Cond: (((k.k % 5)) = b.b) -> Sort (cost=59.83..62.33 rows=1000 width=4) (actual time=4.571..5.825 rows=4000 loops=1) Sort Key: ((k.k % 5)) Sort Method: quicksort Memory: 221kB -> Function Scan on generate_series k (cost=0.00..10.00 rows=1000 width=4) (actual time=0.732..2.737 rows=4000 loops=1) -> Sort (cost=59.83..62.33 rows=1000 width=4) (actual time=0.878..1.942 rows=3201 loops=1) Sort Key: b.b Sort Method: quicksort Memory: 40kB -> Function Scan on generate_series b (cost=0.00..10.00 rows=1000 width=4) (actual time=0.193..0.528 rows=1000 loops=1) Total runtime: 12.814 ms (11 rows) Regards, Alexey Bashtanov -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs