Exemplo n.º 1
0
        /// <summary>
        ///     Find a matching index for the property names supplied.
        /// </summary>
        /// <param name="indexProps">property names to search for</param>
        /// <param name="rangeProps">range props</param>
        /// <returns>-1 if not found, or offset within indexes if found</returns>
        public Pair<TableLookupIndexReqKey, int[]> GetIndexNum(
            string[] indexProps,
            string[] rangeProps)
        {
            // find an exact match first
            var proposed = new QueryPlanIndexItemForge(
                indexProps,
                new Type[indexProps.Length],
                rangeProps,
                new Type[rangeProps.Length],
                false,
                null,
                null);
            foreach (var entry in Items) {
                if (entry.Value.EqualsCompareSortedProps(proposed)) {
                    return new Pair<TableLookupIndexReqKey, int[]>(entry.Key, null);
                }
            }

            // find partial match second, i.e. for unique indexes where the where-clause is overspecific
            foreach (var entry in Items) {
                if (entry.Value.RangeProps == null || entry.Value.RangeProps.Length == 0) {
                    var indexes = QueryPlanIndexUniqueHelper.CheckSufficientGetAssignment(
                        entry.Value.HashProps,
                        indexProps);
                    if (indexes != null && indexes.Length != 0) {
                        return new Pair<TableLookupIndexReqKey, int[]>(entry.Key, indexes);
                    }
                }
            }

            return null;
        }
Exemplo n.º 2
0
        public bool EqualsCompareSortedProps(QueryPlanIndexItemForge other)
        {
            if (IsUnique != other.IsUnique) {
                return false;
            }

            var otherIndexProps = CollectionUtil.CopySortArray(other.HashProps);
            var thisIndexProps = CollectionUtil.CopySortArray(HashProps);
            var otherRangeProps = CollectionUtil.CopySortArray(other.RangeProps);
            var thisRangeProps = CollectionUtil.CopySortArray(RangeProps);
            var compared = CollectionUtil.Compare(otherIndexProps, thisIndexProps) &&
                           CollectionUtil.Compare(otherRangeProps, thisRangeProps);
            return compared && AdvancedIndexProvisionDesc == null && other.AdvancedIndexProvisionDesc == null;
        }