Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W88c3-0006Ih-7q for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jan 2014 13:21:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W88c2-00054p-NN for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jan 2014 13:21:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W84Ti-0001Q5-8Y for pgsql-bugs@postgresql.org; Tue, 28 Jan 2014 08:57:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W84Tf-0008CH-Do for pgsql-bugs@postgresql.org; Tue, 28 Jan 2014 08:57:05 +0000 MIME-Version: 1.0 Subject: BUG #9007: List comparison To: pgsql-bugs@postgresql.org From: stefan.kirchev@gmail.com Date: Tue, 28 Jan 2014 08:56:34 +0000 Message-ID: <20140128085634.26701.33428@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) 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: 9007 Logged by: Stefan Kirchev Email address: stefan.kirchev@gmail.com PostgreSQL version: 9.1.0 Operating system: Linux Ubuntu Server Description: Using two tables to extract differences fails to show any result. Table `table1` has two column of type integer, table `table2` has the same structure. Using the following query fails to show the expected result: select * from table1 where (c1, c2) not in (select c1, c2 from table2); Adding a dummy condition in the internal query helps in getting results: select * from table1 where (c1, c2) not in (select c1, c2 from table2 where c1 <> 0); Consider c1 does not nave values equal to 0: pnp=# select c1, c2 from table2 where c1 = 0; c1 | c2 ----+---- (0 rows) Tested on versions 8.4 and 9.1. Here are the query plans on v8.4: pnp=# explain select * from table1 where (c1, c2) not in (select c1, c2 from table2 where c1 <> 0); QUERY PLAN -------------------------------------------------------------------- Seq Scan on table1 (cost=290.31..681.84 rows=9951 width=8) Filter: (NOT (hashed subplan)) SubPlan -> Seq Scan on table2 (cost=0.00..253.58 rows=14692 width=8) Filter: (c1 <> 0) (5 rows) pnp=# explain select * from table1 where (c1, c2) not in (select c1, c2 from table2); QUERY PLAN -------------------------------------------------------------------- Seq Scan on table1 (cost=253.57..645.11 rows=9951 width=8) Filter: (NOT (hashed subplan)) SubPlan -> Seq Scan on table2 (cost=0.00..216.66 rows=14766 width=8) (4 rows) pnp=# In the query plan the rows shown are half of the real table records: pnp=# select count(*) from table1; count ------- 20880 (1 row) pnp=# select count(*) from table2; count ------- 15557 (1 row) pnp=# Is that a buffers size issue? The server is pretty powerful and handles a much bigger tables of about 100GB without loosing breath. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs