return bms_add_member(relids, member->rti);
}
-/*
- * Update a pgpa_gathered_join to include RTIs scanned by the provided
- * plan node.
- */
-void
-pgpa_add_to_gathered_join(pgpa_gathered_join *gathered_join, Plan *plan)
-{
- Bitmapset *relids = pgpa_relids(plan);
- Index rti;
-
- /*
- * In cases where a single node replaces a join -- such as a Result node
- * that replaces a join between multiple provably-empty relations -- or
- * when partitionwise join is chosen, we find multiple RTIs for a single
- * Plan node and must add all of them to the pgpa_gathered_join.
- */
- if (relids != NULL)
- {
- gathered_join->relids = bms_add_members(gathered_join->relids,
- relids);
- return;
- }
-
- /*
- * Otherwise, maybe there's a single RTI that this Plan node is scanning.
- * If so, we should add its RTI to the pgpa_gathered_join; else, there's
- * nothing to do here.
- */
- rti = pgpa_scanrelid(plan);
- if (rti != 0)
- gathered_join->relids = bms_add_member(gathered_join->relids, rti);
-}
-
/*
* Is this a Result node that has a child?
*/
pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan,
int join_unroll_level,
pgpa_join_unroller *join_unroller,
- pgpa_gathered_join *gathered_join,
List *active_query_features)
{
pgpa_join_unroller *outer_join_unroller = NULL;
pgpa_qf_add_rtis(active_query_features, last_elided_node->relids);
}
- /*
- * If we're trying to accumulate the set of relids beneath a Gather or
- * Gather Merge node, add the relids from the last elided node to the
- * set. Earlier elided nodes don't need to be mentioned, because we
- * only want to accumulate RTIs that are part of the same join
- * problem.
- *
- * For instance, if a Gather node appears above a join between p and
- * q, we do not really care whether p is a plain table, a partitioned
- * table with children p1 and p2, or a non-inlined subquery containing
- * arbitrary logic. Knowing that p was joined to q and that the Gather
- * node appears above that join is enough for us to understand that
- * any substructure of p and/or q must also appear beneath the Gather
- * node.
- */
- if (gathered_join != NULL)
- {
- ElidedNode *last_elided_node;
-
- last_elided_node = list_nth(elided_nodes, num_elided_nodes - 1);
- gathered_join->relids = bms_add_members(gathered_join->relids,
- last_elided_node->relids);
- }
-
/*
* If there are multiple relids for the elided node, a clumped join
* should be built for it exactly once. When there's a join_unroller,
* flattening it into the parent. In either case, the join order and
* join methods beneath the elided node should be described separately
* from the join order and methods above the elided node.
- *
- * Likewise, we only expect a ppga_gathered_join to mention the RTIs
- * from the join problem considered immediately beneath the Gather or
- * Gather Merge node.
*/
join_unroller = NULL;
- gathered_join = NULL;
- }
-
- /*
- * If we've found a Gather or Gather Merge node, prepare to accumulate the
- * associated RTIs in a new ppga_gathered_join object.
- */
- if (IsA(plan, Gather) || IsA(plan, GatherMerge))
- {
- if (gathered_join != NULL)
- elog(ERROR, "nested Gather or Gather Merge nodes");
- gathered_join = palloc(sizeof(pgpa_gathered_join));
- gathered_join->is_merge = IsA(plan, GatherMerge);
- gathered_join->relids = NULL;
- context->gathered_joins =
- lappend(context->gathered_joins, gathered_join);
}
/* Check whether the Plan node is a join, and if so, which kind. */
pgpa_unroll_join(context, plan, join_unroller,
&outer_join_unroller, &inner_join_unroller);
- /*
- * If we are collecting RTIs below Gather (Merge), add any appropriate
- * RTIs for this node.
- */
- if (gathered_join != NULL)
- pgpa_add_to_gathered_join(gathered_join, plan);
-
/*
* If this is a Gather or Gather Merge node, directly add it to the list
* of currently-active query features.
/* Recurse into the outer and inner subtrees. */
if (plan->lefttree != NULL)
pgpa_plan_walker(context, plan->lefttree, join_unroll_level,
- outer_join_unroller, gathered_join,
- active_query_features);
+ outer_join_unroller, active_query_features);
if (plan->righttree != NULL)
pgpa_plan_walker(context, plan->righttree, join_unroll_level,
- inner_join_unroller, gathered_join,
- active_query_features);
+ inner_join_unroller, active_query_features);
/*
* If we created a join unroller up above, then it's also our join to use
* those are specific to a subquery level.
*/
pgpa_plan_walker(context, ((SubqueryScan *) plan)->subplan,
- 0, NULL, NULL, NIL);
+ 0, NULL, NIL);
break;
case T_CustomScan:
extraplans = ((CustomScan *) plan)->custom_plans;
{
Plan *subplan = lfirst(lc);
- pgpa_plan_walker(context, subplan, 0, NULL, NULL,
+ pgpa_plan_walker(context, subplan, 0, NULL,
pushdown_query_features ? active_query_features : NIL);
}