Re: Ignored join clause
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Andreas Karlsson <andreas@proxel.se>, pgsql-bugs@lists.postgresql.org
Date: 2018-04-19T15:11:32Z
Lists: pgsql-bugs
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
Commits
-
Tweak a couple of planner APIs to save recalculating join relids.
- ec38dcd363cd 11.0 landed
-
Change more places to be less trusting of RestrictInfo.is_pushed_down.
- 9680c120e5b2 9.3.23 landed
- 80e12a621876 9.5.13 landed
- 64ad85860ce6 9.6.9 landed
- 58fec95268dc 9.4.18 landed
- c792c7db4146 11.0 landed
- 8b6294c7a560 10.4 landed
-
Fix broken extract_actual_join_clauses call in 9.6 postgres_fdw.
- 306d6e59f751 9.6.9 cited
-
Fix incorrect handling of join clauses pushed into parameterized paths.
- e5d83995e9f8 11.0 landed
- e4e43a16b250 9.5.13 landed
- e1d4398c0a5b 9.3.23 landed
- a347d5210ef0 9.4.18 landed
- 68fab04f7c2a 10.4 landed
- 0c141fcaa7dd 9.6.9 landed
-
Handle restriction clause lists more uniformly in postgres_fdw.
- 28b047875554 10.0 cited