Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9BDp-000471-1j for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Apr 2018 15:11:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9BDn-0002S0-St for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Apr 2018 15:11:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9BDn-0002Rr-MO for pgsql-bugs@lists.postgresql.org; Thu, 19 Apr 2018 15:11:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9BDk-000326-FL for pgsql-bugs@lists.postgresql.org; Thu, 19 Apr 2018 15:11:39 +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 w3JFBWvT021076; Thu, 19 Apr 2018 11:11:33 -0400 From: Tom Lane To: Andrew Gierth cc: Andreas Karlsson , pgsql-bugs@lists.postgresql.org Subject: Re: Ignored join clause In-reply-to: <87efjbe8rz.fsf@news-spur.riddles.org.uk> References: <87muy0dk4a.fsf@news-spur.riddles.org.uk> <87efjbe8rz.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Thu, 19 Apr 2018 12:59:40 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21074.1524150692.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 19 Apr 2018 11:11:32 -0400 Message-ID: <21075.1524150692@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "Andrew" =3D=3D Andrew Gierth writes: > Andrew> My suspicion is that this is an interaction between lateral and > Andrew> join reordering. Looking into it further. > I think I was wrong, and that in fact this is a much more general > problem which amounts to a lack of communication between > get_joinrel_parampathinfo and extract_actual_join_clauses. I've not got to the bottom of it yet either, but I notice that if you replace the VALUES thingy with a plain table, the bug goes away: regression=3D# create table q1(x int, y int); CREATE TABLE regression=3D# insert into q1 values (1, 10), (2, 20); INSERT 0 2 regression=3D# SELECT * FROM t LEFT JOIN q1 ON q1.x =3D t.x LEFT JOIN unnest(ys) q2 (y) ON q2.y =3D q1.y; x | ys | x | y | y = ---+---------+---+----+---- 1 | {10,20} | 1 | 10 | 10 (1 row) The plan's much saner-looking, too: Nested Loop Left Join (cost=3D246.68..32758.05 rows=3D14351 width=3D48) Output: t.x, t.ys, q1.x, q1.y, q2.y Join Filter: (q2.y =3D q1.y) -> Merge Left Join (cost=3D246.68..468.29 rows=3D14351 width=3D44) Output: t.x, t.ys, q1.x, q1.y Merge Cond: (t.x =3D q1.x) -> Sort (cost=3D88.17..91.35 rows=3D1270 width=3D36) Output: t.x, t.ys Sort Key: t.x -> Seq Scan on public.t (cost=3D0.00..22.70 rows=3D1270 w= idth=3D36) Output: t.x, t.ys -> Sort (cost=3D158.51..164.16 rows=3D2260 width=3D8) Output: q1.x, q1.y Sort Key: q1.x -> Seq Scan on public.q1 (cost=3D0.00..32.60 rows=3D2260 = width=3D8) Output: q1.x, q1.y -> Function Scan on pg_catalog.unnest q2 (cost=3D0.00..1.00 rows=3D10= 0 width=3D4) Output: q2.y Function Call: unnest(t.ys) So I'm suspicious that the real issue here has to do with the weird subselect representation we use for VALUES; either that's broken in itself somehow, or more likely the planner gets confused while flattening it. regards, tom lane