예제 #1
0
        /// <summary>
        /// Given an index with a defined set of hash(equals) and range(btree) props and uniqueness flag,
        /// and given a list of indexable properties and accessors for both hash and range,
        /// return the ordered keys and coercion information.
        /// </summary>
        /// <param name="indexMultiKey">index definition</param>
        /// <param name="hashIndexPropsProvided">hash indexable properties</param>
        /// <param name="hashJoinedProps">keys for hash indexable properties</param>
        /// <param name="rangeIndexPropsProvided">btree indexable properties</param>
        /// <param name="rangeJoinedProps">keys for btree indexable properties</param>
        /// <returns>ordered set of key information</returns>
        public static IndexKeyInfo CompileIndexKeyInfo(
            IndexMultiKey indexMultiKey,
            string[] hashIndexPropsProvided,
            SubordPropHashKey[] hashJoinedProps,
            string[] rangeIndexPropsProvided,
            SubordPropRangeKey[] rangeJoinedProps)
        {
            // map the order of indexed columns (key) to the key information available
            var indexedKeyProps       = indexMultiKey.HashIndexedProps;
            var isCoerceHash          = false;
            var hashesDesc            = new SubordPropHashKey[indexedKeyProps.Length];
            var hashPropCoercionTypes = new Type[indexedKeyProps.Length];

            for (var i = 0; i < indexedKeyProps.Length; i++)
            {
                var indexField = indexedKeyProps[i].IndexPropName;
                var index      = CollectionUtil.FindItem(hashIndexPropsProvided, indexField);
                if (index == -1)
                {
                    throw new IllegalStateException("Could not find index property for lookup '" + indexedKeyProps[i]);
                }
                hashesDesc[i]            = hashJoinedProps[index];
                hashPropCoercionTypes[i] = indexedKeyProps[i].CoercionType;
                var evaluatorHashkey = hashesDesc[i].HashKey.KeyExpr.ExprEvaluator;
                if (evaluatorHashkey != null && TypeHelper.GetBoxedType(indexedKeyProps[i].CoercionType) != TypeHelper.GetBoxedType(evaluatorHashkey.ReturnType))     // we allow null evaluator
                {
                    isCoerceHash = true;
                }
            }

            // map the order of range columns (range) to the range information available
            indexedKeyProps = indexMultiKey.RangeIndexedProps;
            var rangesDesc             = new SubordPropRangeKey[indexedKeyProps.Length];
            var rangePropCoercionTypes = new Type[indexedKeyProps.Length];
            var isCoerceRange          = false;

            for (var i = 0; i < indexedKeyProps.Length; i++)
            {
                var indexField = indexedKeyProps[i].IndexPropName;
                var index      = CollectionUtil.FindItem(rangeIndexPropsProvided, indexField);
                if (index == -1)
                {
                    throw new IllegalStateException("Could not find range property for lookup '" + indexedKeyProps[i]);
                }
                rangesDesc[i]             = rangeJoinedProps[index];
                rangePropCoercionTypes[i] = rangeJoinedProps[index].CoercionType;
                if (TypeHelper.GetBoxedType(indexedKeyProps[i].CoercionType) != TypeHelper.GetBoxedType(rangePropCoercionTypes[i]))
                {
                    isCoerceRange = true;
                }
            }

            return(new IndexKeyInfo(hashesDesc,
                                    new CoercionDesc(isCoerceHash, hashPropCoercionTypes), rangesDesc, new CoercionDesc(isCoerceRange, rangePropCoercionTypes)));
        }
예제 #2
0
        private static SubordinateQueryPlannerIndexPropDesc GetIndexPropDesc(IDictionary <String, SubordPropHashKey> hashProps, IDictionary <String, SubordPropRangeKey> rangeProps)
        {
            // hash property names and types
            var hashIndexPropsProvided = new string[hashProps.Count];
            var hashIndexCoercionType  = new Type[hashProps.Count];
            var hashJoinedProps        = new SubordPropHashKey[hashProps.Count];
            var count = 0;

            foreach (var entry in hashProps)
            {
                hashIndexPropsProvided[count] = entry.Key;
                hashIndexCoercionType[count]  = entry.Value.CoercionType;
                hashJoinedProps[count++]      = entry.Value;
            }

            // range property names and types
            var rangeIndexPropsProvided = new string[rangeProps.Count];
            var rangeIndexCoercionType  = new Type[rangeProps.Count];
            var rangeJoinedProps        = new SubordPropRangeKey[rangeProps.Count];

            count = 0;
            foreach (var entry in rangeProps)
            {
                rangeIndexPropsProvided[count] = entry.Key;
                rangeIndexCoercionType[count]  = entry.Value.CoercionType;
                rangeJoinedProps[count++]      = entry.Value;
            }

            // Add all joined fields to an array for sorting
            var listPair = SubordinateQueryPlannerUtil.ToListOfHashedAndBtreeProps(hashIndexPropsProvided,
                                                                                   hashIndexCoercionType, rangeIndexPropsProvided, rangeIndexCoercionType);

            return(new SubordinateQueryPlannerIndexPropDesc(hashIndexPropsProvided, hashIndexCoercionType,
                                                            rangeIndexPropsProvided, rangeIndexCoercionType, listPair,
                                                            hashJoinedProps, rangeJoinedProps));
        }
 /// <summary>Ctor. </summary>
 public SubordIndexedTableLookupStrategySingleCoercingFactory(bool isNWOnTrigger, int streamCountOuter, SubordPropHashKey hashKey, Type coercionType)
     : base(isNWOnTrigger, streamCountOuter, hashKey)
 {
     _coercionType = coercionType;
 }
예제 #4
0
        public static SubordinateQueryPlanDesc PlanSubquery(EventType[] outerStreams,
                                                            SubordPropPlan joinDesc,
                                                            bool isNWOnTrigger,
                                                            bool forceTableScan,
                                                            IndexHint optionalIndexHint,
                                                            bool indexShare,
                                                            int subqueryNumber,
                                                            bool isVirtualDataWindow,
                                                            EventTableIndexMetadata indexMetadata,
                                                            ICollection <string> optionalUniqueKeyProps,
                                                            bool onlyUseExistingIndexes,
                                                            string statementName,
                                                            string statementId,
                                                            Attribute[] annotations)
        {
            if (isVirtualDataWindow)
            {
                var indexProps = GetIndexPropDesc(joinDesc.HashProps, joinDesc.RangeProps);
                var lookupStrategyFactoryVdw = new SubordTableLookupStrategyFactoryVDW(statementName, statementId, annotations,
                                                                                       outerStreams,
                                                                                       indexProps.HashJoinedProps,
                                                                                       new CoercionDesc(false, indexProps.HashIndexCoercionType),
                                                                                       indexProps.RangeJoinedProps,
                                                                                       new CoercionDesc(false, indexProps.RangeIndexCoercionType),
                                                                                       isNWOnTrigger,
                                                                                       joinDesc, forceTableScan, indexProps.ListPair);
                return(new SubordinateQueryPlanDesc(lookupStrategyFactoryVdw, null));
            }

            var          hashKeys              = Collections.GetEmptyList <SubordPropHashKey>();
            CoercionDesc hashKeyCoercionTypes  = null;
            var          rangeKeys             = Collections.GetEmptyList <SubordPropRangeKey>();
            CoercionDesc rangeKeyCoercionTypes = null;

            ExprNode[] inKeywordSingleIdxKeys = null;
            ExprNode   inKeywordMultiIdxKey   = null;

            SubordinateQueryIndexDesc[] indexDescs;
            if (joinDesc.InKeywordSingleIndex != null)
            {
                var single    = joinDesc.InKeywordSingleIndex;
                var keyInfo   = new SubordPropHashKey(new QueryGraphValueEntryHashKeyedExpr(single.Expressions[0], false), null, single.CoercionType);
                var indexDesc = FindOrSuggestIndex(
                    Collections.SingletonMap(single.IndexedProp, keyInfo),
                    Collections.GetEmptyMap <string, SubordPropRangeKey>(), optionalIndexHint, indexShare, subqueryNumber,
                    indexMetadata, optionalUniqueKeyProps, onlyUseExistingIndexes);
                if (indexDesc == null)
                {
                    return(null);
                }
                var desc = new SubordinateQueryIndexDesc(indexDesc.IndexKeyInfo, indexDesc.IndexName, indexDesc.IndexMultiKey, indexDesc.QueryPlanIndexItem);
                indexDescs             = new SubordinateQueryIndexDesc[] { desc };
                inKeywordSingleIdxKeys = single.Expressions;
            }
            else if (joinDesc.InKeywordMultiIndex != null)
            {
                var multi = joinDesc.InKeywordMultiIndex;

                indexDescs = new SubordinateQueryIndexDesc[multi.IndexedProp.Length];
                for (var i = 0; i < multi.IndexedProp.Length; i++)
                {
                    var keyInfo   = new SubordPropHashKey(new QueryGraphValueEntryHashKeyedExpr(multi.Expression, false), null, multi.CoercionType);
                    var indexDesc = FindOrSuggestIndex(
                        Collections.SingletonMap(multi.IndexedProp[i], keyInfo),
                        Collections.GetEmptyMap <string, SubordPropRangeKey>(), optionalIndexHint, indexShare, subqueryNumber,
                        indexMetadata, optionalUniqueKeyProps, onlyUseExistingIndexes);
                    if (indexDesc == null)
                    {
                        return(null);
                    }
                    indexDescs[i] = indexDesc;
                }
                inKeywordMultiIdxKey = multi.Expression;
            }
            else
            {
                var indexDesc = FindOrSuggestIndex(joinDesc.HashProps,
                                                   joinDesc.RangeProps, optionalIndexHint, false, subqueryNumber,
                                                   indexMetadata, optionalUniqueKeyProps, onlyUseExistingIndexes);
                if (indexDesc == null)
                {
                    return(null);
                }
                var indexKeyInfo = indexDesc.IndexKeyInfo;
                hashKeys              = indexKeyInfo.OrderedHashDesc;
                hashKeyCoercionTypes  = indexKeyInfo.OrderedKeyCoercionTypes;
                rangeKeys             = indexKeyInfo.OrderedRangeDesc;
                rangeKeyCoercionTypes = indexKeyInfo.OrderedRangeCoercionTypes;
                var desc = new SubordinateQueryIndexDesc(indexDesc.IndexKeyInfo, indexDesc.IndexName, indexDesc.IndexMultiKey, indexDesc.QueryPlanIndexItem);
                indexDescs = new SubordinateQueryIndexDesc[] { desc };
            }

            if (forceTableScan)
            {
                return(null);
            }

            var lookupStrategyFactory = SubordinateTableLookupStrategyUtil.GetLookupStrategy(outerStreams,
                                                                                             hashKeys, hashKeyCoercionTypes, rangeKeys, rangeKeyCoercionTypes, inKeywordSingleIdxKeys, inKeywordMultiIdxKey, isNWOnTrigger);

            return(new SubordinateQueryPlanDesc(lookupStrategyFactory, indexDescs));
        }
예제 #5
0
 public SubordIndexedTableLookupStrategySingleExprFactory(bool isNWOnTrigger, int streamCountOuter, SubordPropHashKey hashKey)
 {
     StreamCountOuter = streamCountOuter;
     Evaluator        = hashKey.HashKey.KeyExpr.ExprEvaluator;
     IsNWOnTrigger    = isNWOnTrigger;
     StrategyDesc     = new LookupStrategyDesc(LookupStrategyType.SINGLEEXPR, new String[] { hashKey.HashKey.KeyExpr.ToExpressionStringMinPrecedenceSafe() });
 }