Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 213256c

Browse files
committed
My recent fix for semijoin planning didn't actually work for a semijoin with a
RHS that can't be unique-ified --- join_is_legal has to check that before deciding to build a join, else we'll have an unimplementable joinrel. Per report from Greg Stark.
1 parent 5f77b1a commit 213256c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/backend/optimizer/path/joinrels.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.95 2008/11/22 22:47:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.96 2008/11/28 19:29:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -420,19 +420,23 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
420420
reversed = true;
421421
}
422422
else if (sjinfo->jointype == JOIN_SEMI &&
423-
bms_equal(sjinfo->syn_righthand, rel2->relids))
423+
bms_equal(sjinfo->syn_righthand, rel2->relids) &&
424+
create_unique_path(root, rel2, rel2->cheapest_total_path,
425+
sjinfo) != NULL)
424426
{
425427
/*
426428
* For a semijoin, we can join the RHS to anything else by
427-
* unique-ifying the RHS.
429+
* unique-ifying the RHS (if the RHS can be unique-ified).
428430
*/
429431
if (match_sjinfo)
430432
return false; /* invalid join path */
431433
match_sjinfo = sjinfo;
432434
reversed = false;
433435
}
434436
else if (sjinfo->jointype == JOIN_SEMI &&
435-
bms_equal(sjinfo->syn_righthand, rel1->relids))
437+
bms_equal(sjinfo->syn_righthand, rel1->relids) &&
438+
create_unique_path(root, rel1, rel1->cheapest_total_path,
439+
sjinfo) != NULL)
436440
{
437441
/* Reversed semijoin case */
438442
if (match_sjinfo)
@@ -664,7 +668,10 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
664668
/*
665669
* If we know how to unique-ify the RHS and one input rel is
666670
* exactly the RHS (not a superset) we can consider unique-ifying
667-
* it and then doing a regular join.
671+
* it and then doing a regular join. (The create_unique_path
672+
* check here is probably redundant with what join_is_legal did,
673+
* but if so the check is cheap because it's cached. So test
674+
* anyway to be sure.)
668675
*/
669676
if (bms_equal(sjinfo->syn_righthand, rel2->relids) &&
670677
create_unique_path(root, rel2, rel2->cheapest_total_path,

0 commit comments

Comments
 (0)