From 2ef58acb90b965689e7f82efef5daa0d4e02f8b1 Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Thu, 18 May 2023 15:32:22 +0800 Subject: [PATCH v1] Fix thinko in outer-join removal. We should consider min_xxxhand not syn_xxxhand when we compute the relid set for the join we are considering to remove, because the outer joins may not be performed in syntactic order. This should be a thinko in 9df8f903eb. Revert the related changes to what they looked like before. --- src/backend/optimizer/plan/analyzejoins.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c index 7463b3696a..a61e35f92d 100644 --- a/src/backend/optimizer/plan/analyzejoins.c +++ b/src/backend/optimizer/plan/analyzejoins.c @@ -88,11 +88,8 @@ restart: */ innerrelid = bms_singleton_member(sjinfo->min_righthand); - /* - * Compute the relid set for the join we are considering. We can - * assume things are done in syntactic order. - */ - joinrelids = bms_union(sjinfo->syn_lefthand, sjinfo->syn_righthand); + /* Compute the relid set for the join we are considering */ + joinrelids = bms_union(sjinfo->min_lefthand, sjinfo->min_righthand); if (sjinfo->ojrelid != 0) joinrelids = bms_add_member(joinrelids, sjinfo->ojrelid); @@ -204,8 +201,8 @@ join_is_removable(PlannerInfo *root, SpecialJoinInfo *sjinfo) if (!rel_supports_distinctness(root, innerrel)) return false; - /* Compute the syntactic relid set for the join we are considering */ - inputrelids = bms_union(sjinfo->syn_lefthand, sjinfo->syn_righthand); + /* Compute the relid set for the join we are considering */ + inputrelids = bms_union(sjinfo->min_lefthand, sjinfo->min_righthand); Assert(sjinfo->ojrelid != 0); joinrelids = bms_copy(inputrelids); joinrelids = bms_add_member(joinrelids, sjinfo->ojrelid); -- 2.31.0