static char *
pg_plan_advice_generate(PlannedStmt *pstmt)
{
- pgpa_plan_walker_context context;
+ pgpa_plan_walker_context walker;
StringInfoData buf;
ListCell *lc;
const char **rt_identifiers;
rt_identifiers = pgpa_create_identifiers_for_planned_stmt(pstmt);
/* Initialization. */
- memset(&context, 0, sizeof(pgpa_plan_walker_context));
- context.pstmt = pstmt;
+ memset(&walker, 0, sizeof(pgpa_plan_walker_context));
+ walker.pstmt = pstmt;
/* Walk the main plan tree. */
- pgpa_plan_walker(&context, pstmt->planTree, 0, NULL, NIL);
+ pgpa_plan_walker(&walker, pstmt->planTree, 0, NULL, NIL);
/* Main plan tree walk won't reach subplans, so walk those. */
foreach(lc, pstmt->subplans)
Plan *plan = lfirst(lc);
if (plan != NULL)
- pgpa_plan_walker(&context, plan, 0, NULL, NIL);
+ pgpa_plan_walker(&walker, plan, 0, NULL, NIL);
}
/* Put advice into string form. */
initStringInfo(&buf);
- pgpa_output_advice(&buf, &context, rt_identifiers);
+ pgpa_output_advice(&buf, &walker, rt_identifiers);
return buf.data;
}
pgpa_join_unroller **inner_unrollers;
};
-static pgpa_join_strategy pgpa_decompose_join(pgpa_plan_walker_context *context,
+static pgpa_join_strategy pgpa_decompose_join(pgpa_plan_walker_context *walker,
Plan *plan,
Plan **realouter,
Plan **realinner,
* XXX. More comments.
*/
void
-pgpa_unroll_join(pgpa_plan_walker_context *context, Plan *plan,
+pgpa_unroll_join(pgpa_plan_walker_context *walker, Plan *plan,
pgpa_join_unroller *join_unroller,
pgpa_join_unroller **outer_join_unroller,
pgpa_join_unroller **inner_join_unroller)
* this should be an unrollable join.
*/
Assert(pgpa_get_join_class(plan) == PGPA_UNROLLED_JOIN);
- strategy = pgpa_decompose_join(context, plan,
+ strategy = pgpa_decompose_join(walker, plan,
&realouter, &realinner,
&elidedouter, &elidedinner);
* *elidedrealinner to the last of any correspoding elided nodes.
*/
static pgpa_join_strategy
-pgpa_decompose_join(pgpa_plan_walker_context *context, Plan *plan,
+pgpa_decompose_join(pgpa_plan_walker_context *walker, Plan *plan,
Plan **realouter, Plan **realinner,
ElidedNode **elidedrealouter, ElidedNode **elidedrealinner)
{
- PlannedStmt *pstmt = context->pstmt;
+ PlannedStmt *pstmt = walker->pstmt;
JoinType jointype = ((Join *) plan)->jointype;
Plan *outerplan = plan->lefttree;
Plan *innerplan = plan->righttree;
* to the main tree walk, but I don't currently have a better idea.
*/
if (uniqueouter)
- pgpa_add_future_feature(context, PGPAQF_SEMIJOIN_UNIQUE, outerplan);
+ pgpa_add_future_feature(walker, PGPAQF_SEMIJOIN_UNIQUE, outerplan);
else if (jointype == JOIN_RIGHT_SEMI)
- pgpa_add_future_feature(context, PGPAQF_SEMIJOIN_NON_UNIQUE, outerplan);
+ pgpa_add_future_feature(walker, PGPAQF_SEMIJOIN_NON_UNIQUE, outerplan);
if (uniqueinner)
- pgpa_add_future_feature(context, PGPAQF_SEMIJOIN_UNIQUE, innerplan);
+ pgpa_add_future_feature(walker, PGPAQF_SEMIJOIN_UNIQUE, innerplan);
else if (jointype == JOIN_SEMI)
- pgpa_add_future_feature(context, PGPAQF_SEMIJOIN_NON_UNIQUE, innerplan);
+ pgpa_add_future_feature(walker, PGPAQF_SEMIJOIN_NON_UNIQUE, innerplan);
/* Set output parameters. */
*realouter = outerplan;
#include "nodes/plannodes.h"
-static pgpa_query_feature *pgpa_add_feature(pgpa_plan_walker_context *context,
+static pgpa_query_feature *pgpa_add_feature(pgpa_plan_walker_context *walker,
pgpa_qf_type type,
Plan *plan);
* XXX. More comments.
*/
void
-pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan,
+pgpa_plan_walker(pgpa_plan_walker_context *walker, Plan *plan,
int join_unroll_level,
pgpa_join_unroller *join_unroller,
List *active_query_features)
{
active_query_features =
lappend(active_query_features,
- pgpa_add_feature(context, PGPAQF_GATHER, plan));
+ pgpa_add_feature(walker, PGPAQF_GATHER, plan));
is_query_feature = true;
}
else if (IsA(plan, GatherMerge))
{
active_query_features =
lappend(active_query_features,
- pgpa_add_feature(context, PGPAQF_GATHER_MERGE, plan));
+ pgpa_add_feature(walker, PGPAQF_GATHER_MERGE, plan));
is_query_feature = true;
}
else
{
- foreach_ptr(pgpa_query_feature, qf, context->future_query_features)
+ foreach_ptr(pgpa_query_feature, qf, walker->future_query_features)
{
if (qf->plan == plan)
{
is_query_feature = true;
active_query_features = lappend(active_query_features, qf);
- context->future_query_features =
- list_delete_ptr(context->future_query_features, plan);
+ walker->future_query_features =
+ list_delete_ptr(walker->future_query_features, plan);
break;
}
}
/*
* Find all elided nodes for this Plan node.
*/
- foreach_node(ElidedNode, n, context->pstmt->elidedNodes)
+ foreach_node(ElidedNode, n, walker->pstmt->elidedNodes)
{
if (n->plan_node_id == plan->plan_node_id)
elided_nodes = lappend(elided_nodes, n);
/*
* Every element of elided_nodes is an ElidedNode for which any
* necessary pgpa_clumped_join has not yet been created. Do that here,
- * and attach the resulting objects directly to the context object,
+ * and attach the resulting objects directly to the walker object,
* since we have nowhere else to put a reference to it.
*/
foreach_node(ElidedNode, n, elided_nodes)
{
pgpa_clumped_join *cjoin;
- cjoin = pgpa_build_clumped_join(context->pstmt, plan, n);
- context->clumped_joins =
- lappend(context->clumped_joins, cjoin);
+ cjoin = pgpa_build_clumped_join(walker->pstmt, plan, n);
+ walker->clumped_joins = lappend(walker->clumped_joins, cjoin);
}
}
{
pgpa_clumped_join *cjoin;
- cjoin = pgpa_build_clumped_join(context->pstmt, plan, NULL);
- context->clumped_joins = lappend(context->clumped_joins, cjoin);
+ cjoin = pgpa_build_clumped_join(walker->pstmt, plan, NULL);
+ walker->clumped_joins = lappend(walker->clumped_joins, cjoin);
}
/*
* outer and inner sides of the plan.
*/
if (join_unroller != NULL)
- pgpa_unroll_join(context, plan, join_unroller,
+ pgpa_unroll_join(walker, plan, join_unroller,
&outer_join_unroller, &inner_join_unroller);
/* Add RTIs from the plan node to all active query features. */
/* Recurse into the outer and inner subtrees. */
if (plan->lefttree != NULL)
- pgpa_plan_walker(context, plan->lefttree, join_unroll_level,
+ pgpa_plan_walker(walker, plan->lefttree, join_unroll_level,
outer_join_unroller, active_query_features);
if (plan->righttree != NULL)
- pgpa_plan_walker(context, plan->righttree, join_unroll_level,
+ pgpa_plan_walker(walker, plan->righttree, join_unroll_level,
inner_join_unroller, active_query_features);
/*
{
pgpa_unrolled_join *ujoin;
- ujoin = pgpa_build_unrolled_join(context->pstmt, join_unroller);
- context->unrolled_joins = lappend(context->unrolled_joins, ujoin);
+ ujoin = pgpa_build_unrolled_join(walker->pstmt, join_unroller);
+ walker->unrolled_joins = lappend(walker->unrolled_joins, ujoin);
pgpa_destroy_join_unroller(join_unroller);
}
* We don't pass down active_query_features across here, because
* those are specific to a subquery level.
*/
- pgpa_plan_walker(context, ((SubqueryScan *) plan)->subplan,
+ pgpa_plan_walker(walker, ((SubqueryScan *) plan)->subplan,
0, NULL, NIL);
break;
case T_CustomScan:
{
Plan *subplan = lfirst(lc);
- pgpa_plan_walker(context, subplan, 0, NULL,
+ pgpa_plan_walker(walker, subplan, 0, NULL,
pushdown_query_features ? active_query_features : NIL);
}
* yet!
*/
void
-pgpa_add_future_feature(pgpa_plan_walker_context *context,
+pgpa_add_future_feature(pgpa_plan_walker_context *walker,
pgpa_qf_type type, Plan *plan)
{
- pgpa_query_feature *qf = pgpa_add_feature(context, type, plan);
+ pgpa_query_feature *qf = pgpa_add_feature(walker, type, plan);
- context->future_query_features =
- lappend(context->future_query_features, qf);
+ walker->future_query_features =
+ lappend(walker->future_query_features, qf);
}
/*
* for this plan.
*/
static pgpa_query_feature *
-pgpa_add_feature(pgpa_plan_walker_context *context,
+pgpa_add_feature(pgpa_plan_walker_context *walker,
pgpa_qf_type type, Plan *plan)
{
pgpa_query_feature *qf = palloc0_object(pgpa_query_feature);
qf->type = type;
qf->plan = plan;
- context->query_features = lappend(context->query_features, qf);
+ walker->query_features = lappend(walker->query_features, qf);
return qf;
}