예제 #1
0
        public QueryPlan GetQueryPlan(IDmObject parsedQuery, IQuery query, IQueryStore queryStore, MetadataIndex rowsEnumerator)
        {
            //Todo: Plan's cache's key decision (query-string based plan cache/optimizable-section based cache).
            OrderedList <double, IProxyPredicate> sortedPlans = new OrderedList <double, IProxyPredicate>();
            var optimizableQuery = parsedQuery as IFilterObject;

            var criteria  = AddQueryCriteria(parsedQuery, query.Parameters, queryStore);
            var queryPlan = new QueryPlan {
                Criteria = criteria
            };

            if (optimizableQuery != null && optimizableQuery.WherePredicate != null)
            {
                ITreePredicate whereExpression = optimizableQuery.WherePredicate;

                ITreePredicate contractedExpression = whereExpression.Contract();

                if (contractedExpression == null)
                {
                    contractedExpression = whereExpression;
                }

                List <ITreePredicate> distribCombinations = new List <ITreePredicate>();
                distribCombinations.Add(contractedExpression);

                //Todo: Restrict this call if there doesn't exist a compound index.
                while (contractedExpression.Expand() != null)
                {
                    distribCombinations.Add(contractedExpression.Expand());
                    contractedExpression = contractedExpression.Expand();
                }

                foreach (var treePredicate in distribCombinations)
                {
                    if (treePredicate is OrTreePredicate || treePredicate is AndTreePredicate)
                    {
                        break;
                    }
                    if (treePredicate is ComparisonPredicate)
                    {
                        DocumentKey documentKey = null;
                        if (((ComparisonPredicate)treePredicate).TryGetProxyKeyPredicate(rowsEnumerator, out documentKey))
                        {
                            IProxyPredicate optimizablePredicate = new ProxyPredicate(new KeyPredicate(documentKey, rowsEnumerator), treePredicate);
                            sortedPlans.Add(optimizablePredicate.Statistics[Statistic.ExpectedIO], optimizablePredicate);
                            queryPlan.Predicate = sortedPlans.FirstValues[0].GetExecutionPredicate(queryStore);
                            return(queryPlan);
                        }
                    }
                }

                foreach (var expressionState in distribCombinations)
                {
                    IProxyPredicate optimizablePredicate = expressionState.GetProxyExecutionPredicate(_indexManager, queryStore, rowsEnumerator);
                    sortedPlans.Add(optimizablePredicate.Statistics[Statistic.ExpectedIO], optimizablePredicate);
                    //Todo: Add optimizedPredicate to the SortedList by the cost.
                }

                queryPlan.Predicate = sortedPlans.FirstValues[0].GetExecutionPredicate(queryStore);
            }
            else
            {
                if (criteria.GroupFields != null && criteria.GroupFields.Count == 1 && criteria.GroupFields[0] is AllField && criteria.ContainsAggregations)
                {
                    if (criteria.Aggregations.Count == 1 && criteria.Aggregations[0].Aggregation is COUNT &&
                        criteria.Aggregations[0].Evaluation is AllEvaluable)
                    {
                        queryPlan.Criteria.GroupByField = null;
                        queryPlan.Predicate             = new SpecialCountPredicate(rowsEnumerator.KeyCount);
                        queryPlan.IsSpecialExecution    = true;
                        return(queryPlan);
                    }
                }

                //Todo:1 Projection variable-based index assigning (Functions' arguments + attributes).
                queryPlan.Predicate = GetSelectAllPredicate(criteria, rowsEnumerator);
            }

            return(queryPlan);
        }
예제 #2
0
 public ICollection <QueryPlan> GetAllPlans(IDmObject parsedQuery, IQuery query, IQueryStore queryStore)
 {
     throw new System.NotImplementedException();
 }
예제 #3
0
 public ICollection <QueryPlan> GetAllPlans(IDmObject parsedQuery, IQuery query, IQueryStore queryStore)
 {
     //NO!
     return(null);
 }
예제 #4
0
 public QueryPlan GetQueryPlan(IDmObject parsedQuery, IQuery query, IQueryStore queryStore, MetadataIndex rowEnumerator)
 {
     throw new System.NotImplementedException();
 }