Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeNRl-00039O-EX for pgsql-general@arkaria.postgresql.org; Thu, 28 May 2020 18:40:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jeNRj-0002iV-WF for pgsql-general@arkaria.postgresql.org; Thu, 28 May 2020 18:40:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeNRj-0002iN-OR for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 18:40:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeNRg-0007JP-OK for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 18:40:02 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 04SIdusN018622; Thu, 28 May 2020 14:39:56 -0400 From: Tom Lane To: Ying Lu cc: Adrian Klaver , "pgsql-general@lists.postgresql.org" Subject: Re: psql12.3 + jdbc_fdw - return wrong query results by using OR In-reply-to: <1590686553201.26345@concordia.ca> References: <20200528113956.767qptz1cg44cw0g@webmail.encs.concordia.ca> <625d4581-6b92-6368-f1a2-eedf4f6c890a@aklaver.com> <1590685166535.433@concordia.ca>, <1590686553201.26345@concordia.ca> Comments: In-reply-to Ying Lu message dated "Thu, 28 May 2020 17:22:32 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7463.1590691196.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 28 May 2020 14:39:56 -0400 Message-ID: <7464.1590691196@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ying Lu writes: > For Q1: = > QUERY PLAN > ------------------------------------------------------------------------= ------------------------------------------------------- > Aggregate (cost=3D5.40..5.41 rows=3D1 width=3D8) (actual time=3D1267.0= 01..1267.001 rows=3D1 loops=3D1) > -> Hash Join (cost=3D2.10..4.78 rows=3D245 width=3D0) (actual time=3D= 0.134..1265.840 rows=3D2650 loops=3D1) > Hash Cond: (a.c1 =3D b.c1) > -> Foreign Scan on oracle_t1 a (cost=3D0.00..0.00 rows=3D1000= width=3D32) (actual time=3D0.026..1257.823 rows=3D14625 loops=3D1) > -> Hash (cost=3D1.49..1.49 rows=3D49 width=3D5) (actual time=3D= 0.030..0.030 rows=3D49 loops=3D1) > Buckets: 1024 Batches: 1 Memory Usage: 10kB > -> Seq Scan on local_t1 b (cost=3D0.00..1.49 rows=3D49 = width=3D5) (actual time=3D0.014..0.021 rows=3D49 loops=3D1) > Planning Time: 0.178 ms > Execution Time: 1363.482 ms > For Q2: = > QUERY PLAN > ------------------------------------------------------------------------= ---------------------------------------------------- > Aggregate (cost=3D737.71..737.72 rows=3D1 width=3D8) (actual time=3D11= 97.366..1197.366 rows=3D1 loops=3D1) > -> Nested Loop (cost=3D0.00..736.49 rows=3D489 width=3D0) (actual t= ime=3D16.649..1197.292 rows=3D70 loops=3D1) > Join Filter: ((a.c1 =3D b.c1) OR (a.c2 =3D b.c1)) > Rows Removed by Join Filter: 14555 > -> Seq Scan on local_t1 b (cost=3D0.00..1.49 rows=3D49 width=3D= 5) (actual time=3D0.016..0.023 rows=3D49 loops=3D1) > -> Foreign Scan on oracle_t1 a (cost=3D0.00..0.00 rows=3D1000= width=3D64) (actual time=3D0.002..24.284 rows=3D298 loops=3D49) > Planning Time: 0.972 ms > Execution Time: 1299.896 ms The numbers here are consistent with the theory that there are 14625 rows in the foreign table, but when oracle_t1 is scanned on the inside of a nest loop, the FDW returns all of them on the first scan and then forgets to return any when rescanned. This'd be a bug in jdbc_fdw, and a pretty bad one :-(. But you'd have to report it to the jdbc_fdw author(s) --- the core Postgres project doesn't maintain that. regards, tom lane