Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7df4cf7

Browse files
committed
Fix oversight in join removal patch: we have to delete the removed relation
from SpecialJoinInfo relid sets as well. Per example from Vaclav Novotny.
1 parentc851884 commit7df4cf7

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

‎src/backend/optimizer/plan/analyzejoins.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/analyzejoins.c,v 1.1 2010/03/28 22:59:32 tgl Exp $
19+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/analyzejoins.c,v 1.2 2010/05/23 16:34:38 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -343,6 +343,24 @@ remove_rel_from_query(PlannerInfo *root, int relid)
343343
}
344344
}
345345

346+
/*
347+
* Likewise remove references from SpecialJoinInfo data structures.
348+
*
349+
* This is relevant in case the outer join we're deleting is nested
350+
* inside other outer joins: the upper joins' relid sets have to be
351+
* adjusted. The RHS of the target outer join will be made empty here,
352+
* but that's OK since caller will delete that SpecialJoinInfo entirely.
353+
*/
354+
foreach(l,root->join_info_list)
355+
{
356+
SpecialJoinInfo*sjinfo= (SpecialJoinInfo*)lfirst(l);
357+
358+
sjinfo->min_lefthand=bms_del_member(sjinfo->min_lefthand,relid);
359+
sjinfo->min_righthand=bms_del_member(sjinfo->min_righthand,relid);
360+
sjinfo->syn_lefthand=bms_del_member(sjinfo->syn_lefthand,relid);
361+
sjinfo->syn_righthand=bms_del_member(sjinfo->syn_righthand,relid);
362+
}
363+
346364
/*
347365
* Likewise remove references from PlaceHolderVar data structures.
348366
*

‎src/test/regress/expected/join.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,20 @@ explain (costs off)
25252525
Seq Scan on a
25262526
(1 row)
25272527

2528+
-- check optimization of outer join within another special join
2529+
explain (costs off)
2530+
select id from a where id in (
2531+
select b.id from b left join c on b.id = c.id
2532+
);
2533+
QUERY PLAN
2534+
----------------------------
2535+
Hash Semi Join
2536+
Hash Cond: (a.id = b.id)
2537+
-> Seq Scan on a
2538+
-> Hash
2539+
-> Seq Scan on b
2540+
(5 rows)
2541+
25282542
rollback;
25292543
create temp table parent (k int primary key, pd int);
25302544
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "parent_pkey" for table "parent"

‎src/test/regress/sql/join.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ explain (costs off)
588588
SELECT a.*FROM aLEFT JOIN (bleft join conb.c_id=c.id)
589589
ON (a.b_id=b.id);
590590

591+
-- check optimization of outer join within another special join
592+
explain (costs off)
593+
select idfrom awhere idin (
594+
selectb.idfrom bleft join conb.id=c.id
595+
);
596+
591597
rollback;
592598

593599
create temp table parent (kintprimary key, pdint);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp