private QueryTablePlanner CreateTablePlanner(IRequest context, QueryExpressionFrom queryFrom)
{
// Set up plans for each table in the from clause of the command. For
// sub-queries, we recurse.
var tablePlanner = new QueryTablePlanner();
for (int i = 0; i < queryFrom.SourceCount; i++) {
var tableSource = queryFrom.GetTableSource(i);
IQueryPlanNode plan;
if (tableSource is FromTableSubQuerySource) {
var subQuerySource = (FromTableSubQuerySource) tableSource;
var subQueryExpr = subQuerySource.QueryExpression;
var subQueryFrom = subQuerySource.QueryFrom;
plan = PlanQuery(context, subQueryExpr, subQueryFrom, null, null);
if (!(plan is SubsetNode))
throw new InvalidOperationException("The root node of a sub-query plan must be a subset.");
var subsetNode = (SubsetNode) plan;
subsetNode.SetAliasParentName(subQuerySource.AliasName);
} else if (tableSource is FromTableDirectSource) {
var directSource = (FromTableDirectSource) tableSource;
plan = directSource.QueryPlan;
} else {
throw new InvalidOperationException(String.Format("The type of FROM source '{0}' is not supported.", tableSource.GetType()));
}
tablePlanner.AddPlan(plan, tableSource);
}
return tablePlanner;
}