public override Boolean Optimize(QueryParameters queryParameters, QueryStack queryElementsStack) { Boolean treeChanged = false; if (queryElementsStack.HasElementOnPeek(ElementType.WHERE) && queryElementsStack.FindLastAncestorOnPeekByType(ElementType.WHERE_OPERATION) is OperationComperision && ((AbstractComposite)queryElementsStack.FindLastAncestorOnPeekByType(ElementType.WHERE_OPERATION)).HasDescendant(ElementType.LITERAL)) { var className = (ClassName)queryElementsStack.FindLastAncestorOnPeekByType(ElementType.CLASS_NAME); queryParameters.IndexMechanism.GetIndexesForAttribute(className.Value, Name) ?.ToList() .ForEach(p => { if (className.Indexes == null) { className.Indexes = new Dictionary <int, string>(); } if (!className.Indexes.ContainsKey(p.Key)) { className.Indexes.Add(p.Key, p.Value); treeChanged = true; } }); } return(treeChanged); }
public override bool Optimize(QueryParameters parameters, QueryStack queryStack) { var index = default(KeyValuePair <int, string>); if (Indexes != null && Indexes.Count > 0) { index = Indexes .OrderByDescending(p => parameters.IndexMechanism.GetPessimisticObjectFindCost(p.Key, Cardinality(parameters))) .First(); } if (!index.Equals(Index) && Cardinality(parameters) > parameters.SettingsManager.MaxNumberObjectsFullScan) { Index = index; var selectStatement = (SelectStatement)queryStack.FindLastAncestorOnPeekByType(ElementType.SELECT); selectStatement.Index = index; return(true); } return(false); }