From d7e4fd99e53db2a225d17738b64c6ec66e6f17f2 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 22 Sep 2005 23:25:07 +0000
Subject: [PATCH] Fix bug introduced into indexable_outerrelids() by an
 ill-considered "optimization".  When we find a potentially useful joinclause,
 we have to add all its other required_relids to the result, not only the
 other clause_relids.  They are different in the case of a joinclause whose
 applicability has to be postponed due to outer join.  We have to include the
 extra rels because otherwise, after best_inner_indexscan masks the join rels
 with index_outer_relids, it will always fail to find the joinclause as
 applicable.  Per report from Husam Tomeh.

---
 src/backend/optimizer/path/indxpath.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c689d1461e9..1d744978289 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.188 2005/08/28 22:47:20 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.189 2005/09/22 23:25:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -955,15 +955,13 @@ indexable_outerrelids(RelOptInfo *rel)
 	/*
 	 * Examine each joinclause in the joininfo list to see if it matches any
 	 * key of any index.  If so, add the clause's other rels to the result.
-	 * (Note: we consider only actual participants, not extraneous rels
-	 * possibly mentioned in required_relids.)
 	 */
 	foreach(l, rel->joininfo)
 	{
 		RestrictInfo *joininfo = (RestrictInfo *) lfirst(l);
 		Relids	other_rels;
 
-		other_rels = bms_difference(joininfo->clause_relids, rel->relids);
+		other_rels = bms_difference(joininfo->required_relids, rel->relids);
 		if (matches_any_index(joininfo, rel, other_rels))
 			outer_relids = bms_join(outer_relids, other_rels);
 		else
-- 
GitLab