Skip to content

Commit 4de2f24

Browse files
committed
Fix for queries with 3 or more relations participating in
one clause.
1 parent 6eb0525 commit 4de2f24

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/backend/optimizer/path/joinrels.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.1.1.1 1996/07/09 06:21:36 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.2 1997/02/20 02:54:09 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -297,10 +297,18 @@ new_joininfo_list(List *joininfo_list, List *join_relids)
297297
List *xjoininfo = NIL;
298298

299299
foreach (xjoininfo, joininfo_list) {
300+
List *or;
300301
JInfo *joininfo = (JInfo*)lfirst(xjoininfo);
301302

302303
new_otherrels = joininfo->otherrels;
303-
if (nonoverlap_sets(new_otherrels,join_relids)) {
304+
foreach (or, new_otherrels)
305+
{
306+
if ( intMember (lfirsti(or), join_relids) )
307+
new_otherrels = lremove ((void*)lfirst(or), new_otherrels);
308+
}
309+
joininfo->otherrels = new_otherrels;
310+
if ( new_otherrels != NIL )
311+
{
304312
other_joininfo = joininfo_member(new_otherrels,
305313
current_joininfo_list);
306314
if(other_joininfo) {

src/backend/optimizer/plan/initsplan.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.2 1996/10/31 10:59:13 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.3 1997/02/20 02:53:26 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -250,10 +250,19 @@ add_join_clause_info_to_rels(Query *root, CInfo *clauseinfo, List *join_relids)
250250
List *join_relid;
251251

252252
foreach (join_relid, join_relids) {
253-
JInfo *joininfo =
253+
JInfo *joininfo;
254+
List *other_rels = NIL;
255+
List *rel;
256+
257+
foreach (rel, join_relids)
258+
{
259+
if ( (int)lfirst(rel) != (int)lfirst(join_relid) )
260+
other_rels = lappendi (other_rels, lfirst(rel));
261+
}
262+
263+
joininfo =
254264
find_joininfo_node(get_base_rel(root, lfirsti(join_relid)),
255-
intLispRemove((int)lfirst(join_relid),
256-
join_relids));
265+
other_rels);
257266
joininfo->jinfoclauseinfo =
258267
lcons(clauseinfo, joininfo->jinfoclauseinfo);
259268

0 commit comments

Comments
 (0)