/// <summary>
/// Update FROM clause, adds DOWNSIZE predicates in the corresponding join conditions,
/// and add corresponding predicates on the spilt nodes in the WHERE clause using
/// optimal component of each connected sub-graph.
/// </summary>
/// <param name="node">The SELECT statement</param>
/// <param name="components">The optimal components of each fully-connected graph</param>
private void UpdateQuery(WSelectQueryBlock node, List<MatchComponent> components)
{
// Removes schema name in SELECT clause and all column references.
var removeSchemaVisitor = new RemoveSchemanameInIdentifersVisitor();
removeSchemaVisitor.Visit(node);
foreach (var component in components)
{
//// Cross apply the unmaterilized edges which point to the optimized tail nodes
//Dictionary<MatchNode, MatchEdge> UnMatEdgeJoinDict = new Dictionary<MatchNode, MatchEdge>();
//foreach (var unMatEdge in component.EdgeMaterilizedDict.Where(e => !e.Value).Select(e => e.Key))
//{
// component.TableRef = component.SpanTableRef(component.TableRef,
// unMatEdge, component.GetNodeRefName(unMatEdge.SourceNode), _graphMetaData);
// MatchEdge joinEdge;
// if (UnMatEdgeJoinDict.TryGetValue(unMatEdge.SinkNode, out joinEdge))
// {
// if (!string.IsNullOrEmpty(newWhereString))
// newWhereString += " AND ";
// newWhereString += string.Format("{0}.Sink = {1}.Sink", joinEdge.EdgeAlias, unMatEdge.EdgeAlias);
// }
// else
// {
// UnMatEdgeJoinDict[unMatEdge.SinkNode] = unMatEdge;
// }
//}
// Updates from clause
node.FromClause.TableReferences.Add(component.TableRef);
}
WBooleanExpression attachWhereCondition = null;
foreach (var component in components)
{
attachWhereCondition = WBooleanBinaryExpression.Conjunction(attachWhereCondition,
component.WhereCondition);
}
if (attachWhereCondition != null)
{
if (node.WhereClause != null && node.WhereClause.SearchCondition != null)
node.WhereClause.SearchCondition = new WBooleanParenthesisExpression
{
Expression = node.WhereClause.SearchCondition
};
else
{
node.WhereClause = new WWhereClause();
}
node.WhereClause.SearchCondition = WBooleanBinaryExpression.Conjunction(attachWhereCondition,
node.WhereClause.SearchCondition);
}
}