To fix this problem, I'm thinking we can leverage 'root->all_baserels' to tell if we are at the topmost scan/join rel, something like:
--- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -3041,7 +3041,7 @@ standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels) * partial paths. We'll do the same for the topmost scan/join rel * once we know the final targetlist (see grouping_planner). */ - if (lev < levels_needed) + if (!bms_equal(rel->relids, root->all_baserels)) generate_useful_gather_paths(root, rel, false);
Any thoughts?
Attach a patch to include the fix described upthread. Would appreciate any comments on this topic.