public static Pair <IndexMultiKey, EventTableIndexEntryBase> FindIndexBestAvailable <T>( IDictionary <IndexMultiKey, T> tablesAvailable, ISet <string> keyPropertyNames, ISet <string> rangePropertyNames, IList <IndexHintInstruction> optionalIndexHintInstructions) where T : EventTableIndexEntryBase { if (keyPropertyNames.IsEmpty() && rangePropertyNames.IsEmpty()) { return(null); } // determine candidates IList <IndexedPropDesc> hashProps = new List <IndexedPropDesc>(); foreach (var keyPropertyName in keyPropertyNames) { hashProps.Add(new IndexedPropDesc(keyPropertyName, null)); } IList <IndexedPropDesc> rangeProps = new List <IndexedPropDesc>(); foreach (var rangePropertyName in rangePropertyNames) { rangeProps.Add(new IndexedPropDesc(rangePropertyName, null)); } var indexCandidates = EventTableIndexUtil .FindCandidates(tablesAvailable, hashProps, rangeProps) .Transform <IndexMultiKey, EventTableIndexEntryBase, IndexMultiKey, T>( k => k, v => v, k => k, v => v as T); // handle hint if (optionalIndexHintInstructions != null) { var found = EventTableIndexUtil.FindByIndexHint(indexCandidates, optionalIndexHintInstructions); if (found != null) { return(GetPair(tablesAvailable, found)); } } // no candidates if (indexCandidates == null || indexCandidates.IsEmpty()) { if (Log.IsDebugEnabled) { Log.Debug("No index found."); } return(null); } return(GetBestCandidate(indexCandidates)); }
public static IndexMultiKey FindIndexConsiderTyping(IDictionary <IndexMultiKey, EventTableIndexMetadataEntry> tableIndexesRefCount, IList <IndexedPropDesc> hashProps, IList <IndexedPropDesc> btreeProps, IList <IndexHintInstruction> optionalIndexHintInstructions) { if (hashProps.IsEmpty() && btreeProps.IsEmpty()) { throw new ArgumentException("Invalid zero element list for hash and btree columns"); } var indexCandidates = //(IDictionary<IndexMultiKey, EventTableIndexRepositoryEntry>) EventTableIndexUtil.FindCandidates(tableIndexesRefCount, hashProps, btreeProps); // if there are hints, follow these if (optionalIndexHintInstructions != null) { var found = EventTableIndexUtil.FindByIndexHint(indexCandidates, optionalIndexHintInstructions); if (found != null) { return(found); } } // Get an existing table, if any, matching the exact requirement, prefer unique var indexPropKeyMatch = EventTableIndexUtil.FindExactMatchNameAndType(tableIndexesRefCount.Keys, true, hashProps, btreeProps); if (indexPropKeyMatch == null) { indexPropKeyMatch = EventTableIndexUtil.FindExactMatchNameAndType(tableIndexesRefCount.Keys, false, hashProps, btreeProps); } if (indexPropKeyMatch != null) { return(indexPropKeyMatch); } if (indexCandidates.IsEmpty()) { return(null); } var transIndexCandidates = indexCandidates.Transform <IndexMultiKey, EventTableIndexEntryBase, IndexMultiKey, EventTableIndexMetadataEntry>( k => k, v => v, k => k, v => (EventTableIndexMetadataEntry)v); return(GetBestCandidate(transIndexCandidates).First); }