protected override void OnExecute()
 {
     using (var scope = new DatabaseScope(context.Database.Name))
     {
         var existingIndices = indicesRepository.GetAll();
         foreach (var i in existingIndices)
         {
             var relation           = relationsRepository.Get(i.RelationID);
             var relationData       = new RelationData(relation);
             var attributes         = new List <AttributeData>();
             var includedAttributes = new List <AttributeData>();
             foreach (var atrributeName in i.AttributesNames)
             {
                 var attribute = attributesRepository.Get(relation.ID, atrributeName);
                 var toAdd     = new AttributeData(relationData, attribute);
                 if (IsIncludedAttribute(i.CreateDefinition, attribute.Name))
                 {
                     includedAttributes.Add(toAdd);
                 }
                 else
                 {
                     attributes.Add(toAdd);
                 }
             }
             var existingIndexToAdd = new IndexDefinition(Convert(i.AccessMethod), relationData, attributes, includedAttributes);
             if (context.StatementsData.AllQueriesByRelation.TryGetValue(relation.ID, out var possibleQueriesForIndex))
             {
                 foreach (var statementQueryPair in possibleQueriesForIndex)
                 {
                     var normalizedStatementID = statementQueryPair.NormalizedStatementID;
                     var normalizedStatement   = context.StatementsData.All[normalizedStatementID].NormalizedStatement;
                     var query         = statementQueryPair.Query;
                     var extractedData = context.StatementsExtractedData.DataPerQuery[statementQueryPair];
                     if (IndexApplicability.IsIndexApplicableForQuery(extractedData, existingIndexToAdd))
                     {
                         context.IndicesDesignData.ExistingIndices.TryAddPossibleIndices(new[] { existingIndexToAdd }, normalizedStatement, query);
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        protected override void OnExecute()
        {
            context.IndicesDesignData.Environments.Clear();
            foreach (var index in context.IndicesDesignData.PossibleIndices.All)
            {
                foreach (var kv in context.StatementsData.AllQueriesByRelation[index.Relation.ID])
                {
                    var query = kv.Query;
                    var normalizedStatement           = context.StatementsData.All[kv.NormalizedStatementID].NormalizedStatement;
                    var queryExtractedDataForCovering = context.StatementsExtractedData.DataPerQuery[kv];
                    if (IndexApplicability.IsIndexApplicableForQuery(queryExtractedDataForCovering, index))
                    {
                        context.IndicesDesignData.PossibleIndices.TryAddPossibleIndices(new[] { index }, normalizedStatement, query);
                    }
                }
            }
            var possibleIndices = context.IndicesDesignData.PossibleIndices.Clone();

            context.IndicesDesignData.Environments.Add(new VirtualIndicesEnvironment(possibleIndices));
        }
        protected override void OnExecute()
        {
            context.IndicesDesignData.Environments.Clear();
            foreach (var index in context.IndicesDesignData.PossibleIndices.All)
            {
                foreach (var kv in context.StatementsData.AllQueriesByRelation[index.Relation.ID])
                {
                    var query = kv.Query;
                    var normalizedStatement           = context.StatementsData.All[kv.NormalizedStatementID].NormalizedStatement;
                    var queryExtractedDataForCovering = context.StatementsExtractedData.DataPerQuery[kv];
                    if (IndexApplicability.IsIndexApplicableForQuery(queryExtractedDataForCovering, index))
                    {
                        context.IndicesDesignData.PossibleIndices.TryAddPossibleIndices(new[] { index }, normalizedStatement, query);
                    }
                }
            }
            foreach (var kv in context.IndicesDesignData.PossibleIndices.AllPerStatement)
            {
                var indices = kv.Value;
                for (int combinationLength = 1; combinationLength <= indices.Count; combinationLength++)
                {
                    var combinations = new Combinations <IndexDefinition>(indices, combinationLength);
                    foreach (var c in combinations)
                    {
                        context.IndicesDesignData.Environments.Add(new VirtualIndicesEnvironment(context.IndicesDesignData.PossibleIndices.ToSubSetOf(c)));
                    }
                }
            }

            /*
             * var allIndices = new ElementSet<IndexDefinition>(context.IndicesDesignData.PossibleIndices.All);
             * for (int combinationLength = 1; combinationLength <= allIndices.Count; combinationLength++)
             * {
             *  var combinations = new Combinations<IndexDefinition>(allIndices, combinationLength);
             *  foreach (var c in combinations)
             *  {
             *      context.IndicesDesignData.Environments.Add(new VirtualIndicesEnvironment(context.IndicesDesignData.PossibleIndices.ToSubSetOf(c)));
             *  }
             * }
             */
        }