pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Andreas Karlsson <andreas@proxel.se>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Ignored join clause
Date: Thu, 19 Apr 2018 11:11:32 -0400
Message-ID: <21075.1524150692@sss.pgh.pa.us> (raw)
In-Reply-To: <87efjbe8rz.fsf@news-spur.riddles.org.uk>
References: <f8128b11-c5bf-3539-48cd-234178b2314d@proxel.se>
	<87muy0dk4a.fsf@news-spur.riddles.org.uk>
	<87efjbe8rz.fsf@news-spur.riddles.org.uk>

Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> "Andrew" == Andrew Gierth <andrew@tao11.riddles.org.uk> 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=# create table q1(x int, y int);
CREATE TABLE
regression=# insert into q1 values (1, 10), (2, 20);
INSERT 0 2
regression=# SELECT *
FROM t
LEFT JOIN q1 ON q1.x = t.x
LEFT JOIN unnest(ys) q2 (y) ON q2.y = 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=246.68..32758.05 rows=14351 width=48)
   Output: t.x, t.ys, q1.x, q1.y, q2.y
   Join Filter: (q2.y = q1.y)
   ->  Merge Left Join  (cost=246.68..468.29 rows=14351 width=44)
         Output: t.x, t.ys, q1.x, q1.y
         Merge Cond: (t.x = q1.x)
         ->  Sort  (cost=88.17..91.35 rows=1270 width=36)
               Output: t.x, t.ys
               Sort Key: t.x
               ->  Seq Scan on public.t  (cost=0.00..22.70 rows=1270 width=36)
                     Output: t.x, t.ys
         ->  Sort  (cost=158.51..164.16 rows=2260 width=8)
               Output: q1.x, q1.y
               Sort Key: q1.x
               ->  Seq Scan on public.q1  (cost=0.00..32.60 rows=2260 width=8)
                     Output: q1.x, q1.y
   ->  Function Scan on pg_catalog.unnest q2  (cost=0.00..1.00 rows=100 width=4)
         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




view thread (7+ messages)  latest in thread

Message-ID: <21075.1524150692@sss.pgh.pa.us>
Permalink:  ../21075.1524150692@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21075.1524150692@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andrew@tao11.riddles.org.uk, andreas@proxel.se
  Subject: Re: Ignored join clause
  In-Reply-To: <21075.1524150692@sss.pgh.pa.us>
  References: <f8128b11-c5bf-3539-48cd-234178b2314d@proxel.se> <87muy0dk4a.fsf@news-spur.riddles.org.uk> <87efjbe8rz.fsf@news-spur.riddles.org.uk> <21075.1524150692@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox