public static QueryPlanTree BuildTreeSummary(IQueryElement queryTree, QueryParameters queryParameters) { QueryStack queryStack = new QueryStack(); int childId = 1; queryStack.AddElement(queryTree); QueryPlanTree queryPlanTree = new QueryPlanTree(childId, 0, queryTree, queryTree.ElementType, null, queryTree is AbstractLeaf ? ((AbstractLeaf)queryTree).GetValue() : "", queryTree.Cost(queryParameters), queryTree.Cardinality(queryParameters), queryTree.AccessType, queryTree.AccessObject); if (queryTree.GetComposite() != null) { queryPlanTree.Childrens = new List <QueryPlanTree>(); foreach (var elements in queryTree.GetComposite().GetElements()) { foreach (var element in elements.Value) { queryStack.AddElement(element); if (element.Optimize(queryParameters, queryStack)) { return(null); } if (element.GetComposite()?.GetElements()?.Count > 0) { QueryPlanTree queryPlanTreeChild = new QueryPlanTree(++childId, 1, element, elements.Key, queryPlanTree, "", element.Cost(queryParameters), element.Cardinality(queryParameters), element.AccessType, element.AccessObject); queryPlanTree.Childrens.Add(queryPlanTreeChild); if (BuildTreeChilds(element, childId, queryPlanTreeChild, queryParameters, queryStack) < 0) { return(null); } } else { QueryPlanTree queryPlanTreeChild = new QueryPlanTree(++childId, 1, element, elements.Key, queryPlanTree, element is AbstractLeaf ? ((AbstractLeaf)element).Value : "", element.Cost(queryParameters), element.Cardinality(queryParameters), element.AccessType, element.AccessObject); queryPlanTree.Childrens.Add(queryPlanTreeChild); } } } } return(queryPlanTree); }
private static int BuildTreeChilds(IQueryElement queryTree, int parentId, QueryPlanTree parent, QueryParameters queryParameters, QueryStack queryStack) { int childID = parentId + 1; parent.Childrens = new List <QueryPlanTree>(); if (queryTree.GetComposite()?.GetElements() != null) { foreach (var elements in queryTree.GetComposite().GetElements()) { foreach (var element in elements.Value) { queryStack.AddElement(element); if (element.Optimize(queryParameters, queryStack)) { return(-1); } if (element.GetComposite()?.GetElements()?.Count > 0) { QueryPlanTree queryPlanTreeChild = new QueryPlanTree(childID, parentId, element, elements.Key, parent, "", element.Cost(queryParameters), element.Cardinality(queryParameters), element.AccessType, element.AccessObject); parent.Childrens.Add(queryPlanTreeChild); childID = BuildTreeChilds(element, childID, queryPlanTreeChild, queryParameters, queryStack); if (childID < 0) { return(childID); } } else { parent.Childrens.Add(new QueryPlanTree(childID++, parentId, element, elements.Key, parent, element is AbstractLeaf ? ((AbstractLeaf)element).Value : "", element.Cost(queryParameters), element.Cardinality(queryParameters), element.AccessType, element.AccessObject)); } } } } return(childID); }