Skip to content

Commit c8b881d

Browse files
committed
Undo faulty attempt at not relying on RINFO_IS_PUSHED_DOWN.
I've had a bee in my bonnet for some time about getting rid of RestrictInfo.is_pushed_down, because it's squishily defined and requires not-inexpensive extra tests to use (cf RINFO_IS_PUSHED_DOWN). In commit 2489d76, I tried to make remove_rel_from_query() not depend on that macro; but the replacement test is buggy, as exposed by a report from Rushabh Lathia and Robert Haas. That change was pretty incidental to the main goal of 2489d76, so let's just revert it for now. (Getting rid of is_pushed_down is still far away, anyway.) Discussion: https://postgr.es/m/CA+TgmoYco=hmg+iX1CW9Y1_CzNoSL81J03wUG-d2_3=rue+L2A@mail.gmail.com
1 parent 375407f commit c8b881d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/backend/optimizer/plan/analyzejoins.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,7 @@ remove_rel_from_query(PlannerInfo *root, int relid, int ojrelid,
466466

467467
remove_join_clause_from_rels(root, rinfo, rinfo->required_relids);
468468

469-
/*
470-
* If the qual lists ojrelid in its required_relids, it must have come
471-
* from above the outer join we're removing (so we need to keep it);
472-
* if it does not, then it didn't and we can discard it.
473-
*/
474-
if (bms_is_member(ojrelid, rinfo->required_relids))
469+
if (RINFO_IS_PUSHED_DOWN(rinfo, joinrelids))
475470
{
476471
/*
477472
* There might be references to relid or ojrelid in the

src/test/regress/expected/join.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,6 +5320,22 @@ select 1 from (select a.id FROM a left join b on a.b_id = b.id) q,
53205320
Filter: (a.id = i)
53215321
(4 rows)
53225322

5323+
-- check join removal within RHS of an outer join
5324+
explain (costs off)
5325+
select c.id, ss.a from c
5326+
left join (select d.a from onerow, d left join b on d.a = b.id) ss
5327+
on c.id = ss.a;
5328+
QUERY PLAN
5329+
--------------------------------
5330+
Hash Right Join
5331+
Hash Cond: (d.a = c.id)
5332+
-> Nested Loop
5333+
-> Seq Scan on onerow
5334+
-> Seq Scan on d
5335+
-> Hash
5336+
-> Seq Scan on c
5337+
(7 rows)
5338+
53235339
CREATE TEMP TABLE parted_b (id int PRIMARY KEY) partition by range(id);
53245340
CREATE TEMP TABLE parted_b1 partition of parted_b for values from (0) to (10);
53255341
-- test join removals on a partitioned table

src/test/regress/sql/join.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,12 @@ explain (costs off)
19271927
select 1 from (select a.id FROM a left join b on a.b_id = b.id) q,
19281928
lateral generate_series(1, q.id) gs(i) where q.id = gs.i;
19291929

1930+
-- check join removal within RHS of an outer join
1931+
explain (costs off)
1932+
select c.id, ss.a from c
1933+
left join (select d.a from onerow, d left join b on d.a = b.id) ss
1934+
on c.id = ss.a;
1935+
19301936
CREATE TEMP TABLE parted_b (id int PRIMARY KEY) partition by range(id);
19311937
CREATE TEMP TABLE parted_b1 partition of parted_b for values from (0) to (10);
19321938

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy