Beispiel #1
0
        /// <summary>
        /// Analye EQUALS (=) node.
        /// </summary>
        /// <param name="equalsNode">node to analyze</param>
        /// <param name="queryGraph">store relationships between stream properties</param>
        /// <param name="isOuterJoin">if set to <c>true</c> [is outer join].</param>
        internal static void AnalyzeEqualsNode(ExprEqualsNode equalsNode, QueryGraph queryGraph, bool isOuterJoin)
        {
            if ((equalsNode.ChildNodes[0] is ExprIdentNode) &&
                (equalsNode.ChildNodes[1] is ExprIdentNode))
            {
                var identNodeLeft  = (ExprIdentNode)equalsNode.ChildNodes[0];
                var identNodeRight = (ExprIdentNode)equalsNode.ChildNodes[1];

                if (identNodeLeft.StreamId != identNodeRight.StreamId)
                {
                    queryGraph.AddStrictEquals(identNodeLeft.StreamId, identNodeLeft.ResolvedPropertyName, identNodeLeft,
                                               identNodeRight.StreamId, identNodeRight.ResolvedPropertyName, identNodeRight);
                }

                return;
            }
            if (isOuterJoin)        // outerjoins don't use constants or one-way expression-derived information to evaluate join
            {
                return;
            }

            // handle constant-compare or transformation case
            var           indexedStream   = -1;
            ExprIdentNode indexedPropExpr = null;
            ExprNode      exprNodeNoIdent = null;

            if (equalsNode.ChildNodes[0] is ExprIdentNode)
            {
                indexedPropExpr = (ExprIdentNode)equalsNode.ChildNodes[0];
                indexedStream   = indexedPropExpr.StreamId;
                exprNodeNoIdent = equalsNode.ChildNodes[1];
            }
            else if (equalsNode.ChildNodes[1] is ExprIdentNode)
            {
                indexedPropExpr = (ExprIdentNode)equalsNode.ChildNodes[1];
                indexedStream   = indexedPropExpr.StreamId;
                exprNodeNoIdent = equalsNode.ChildNodes[0];
            }
            if (indexedStream == -1)
            {
                return;     // require property of right/left side of equals
            }

            var eligibility = EligibilityUtil.VerifyInputStream(exprNodeNoIdent, indexedStream);

            if (!eligibility.Eligibility.IsEligible())
            {
                return;
            }

            if (eligibility.Eligibility == Eligibility.REQUIRE_NONE)
            {
                queryGraph.AddUnkeyedExpression(indexedStream, indexedPropExpr, exprNodeNoIdent);
            }
            else
            {
                queryGraph.AddKeyedExpression(indexedStream, indexedPropExpr, eligibility.StreamNum.Value, exprNodeNoIdent);
            }
        }
Beispiel #2
0
        private static void AnalyzeInNodeSingleIndex(ExprInNode inNode, QueryGraph queryGraph)
        {
            if (!(inNode.ChildNodes[0] is ExprIdentNode))
            {
                return;
            }
            var testIdent      = (ExprIdentNode)inNode.ChildNodes[0];
            var testIdentClass = TypeHelper.GetBoxedType(testIdent.ExprEvaluator.ReturnType);
            int indexedStream  = testIdent.StreamId;

            ExprNode[] setExpressions = GetInNodeSetExpressions(inNode);
            if (setExpressions.Length == 0)
            {
                return;
            }

            var perStreamExprs = new LinkedHashMap <int?, IList <ExprNode> >();

            foreach (ExprNode exprNodeSet in setExpressions)
            {
                if (exprNodeSet.ExprEvaluator.ReturnType.GetBoxedType() != testIdentClass)
                {
                    continue;
                }
                if (exprNodeSet is ExprIdentNode)
                {
                    var setIdent = (ExprIdentNode)exprNodeSet;
                    AddToList(setIdent.StreamId, setIdent, perStreamExprs);
                }
                else
                {
                    EligibilityDesc eligibility = EligibilityUtil.VerifyInputStream(exprNodeSet, indexedStream);
                    if (!eligibility.Eligibility.IsEligible())
                    {
                        continue;
                    }
                    AddToList(eligibility.StreamNum, exprNodeSet, perStreamExprs);
                }
            }

            foreach (var entry in perStreamExprs)
            {
                ExprNode[] exprNodes = ExprNodeUtility.ToArray(entry.Value);
                if (entry.Key == null)
                {
                    queryGraph.AddInSetSingleIndexUnkeyed(testIdent.StreamId, testIdent, exprNodes);
                    continue;
                }
                if (entry.Key.Value != indexedStream)
                {
                    queryGraph.AddInSetSingleIndex(testIdent.StreamId, testIdent, entry.Key.Value, exprNodes);
                }
            }
        }
Beispiel #3
0
        private static void AnalyzeRelationalOpNode(ExprRelationalOpNode relNode, QueryGraph queryGraph)
        {
            if (((relNode.ChildNodes[0] is ExprIdentNode)) &&
                ((relNode.ChildNodes[1] is ExprIdentNode)))
            {
                var identNodeLeft  = (ExprIdentNode)relNode.ChildNodes[0];
                var identNodeRight = (ExprIdentNode)relNode.ChildNodes[1];

                if (identNodeLeft.StreamId != identNodeRight.StreamId)
                {
                    queryGraph.AddRelationalOpStrict(
                        identNodeLeft.StreamId, identNodeLeft,
                        identNodeRight.StreamId, identNodeRight,
                        relNode.RelationalOpEnum);
                }
                return;
            }

            var              indexedStream   = -1;
            ExprIdentNode    indexedPropExpr = null;
            ExprNode         exprNodeNoIdent = null;
            RelationalOpEnum relop           = relNode.RelationalOpEnum;

            if (relNode.ChildNodes[0] is ExprIdentNode)
            {
                indexedPropExpr = (ExprIdentNode)relNode.ChildNodes[0];
                indexedStream   = indexedPropExpr.StreamId;
                exprNodeNoIdent = relNode.ChildNodes[1];
            }
            else if (relNode.ChildNodes[1] is ExprIdentNode)
            {
                indexedPropExpr = (ExprIdentNode)relNode.ChildNodes[1];
                indexedStream   = indexedPropExpr.StreamId;
                exprNodeNoIdent = relNode.ChildNodes[0];
                relop           = relop.Reversed();
            }
            if (indexedStream == -1)
            {
                return;     // require property of right/left side of equals
            }

            var eligibility = EligibilityUtil.VerifyInputStream(exprNodeNoIdent, indexedStream);

            if (!eligibility.Eligibility.IsEligible())
            {
                return;
            }

            queryGraph.AddRelationalOp(indexedStream, indexedPropExpr, eligibility.StreamNum, exprNodeNoIdent, relop);
        }
Beispiel #4
0
        private static void AnalyzeInNodeMultiIndex(ExprInNode inNode, QueryGraph queryGraph)
        {
            ExprNode[] setExpressions = GetInNodeSetExpressions(inNode);
            if (setExpressions.Length == 0)
            {
                return;
            }

            var perStreamExprs = new LinkedHashMap <int?, IList <ExprNode> >();

            foreach (ExprNode exprNodeSet in setExpressions)
            {
                if (!(exprNodeSet is ExprIdentNode))
                {
                    continue;
                }
                var setIdent = (ExprIdentNode)exprNodeSet;
                AddToList(setIdent.StreamId, setIdent, perStreamExprs);
            }
            if (perStreamExprs.IsEmpty())
            {
                return;
            }

            var testExpr     = inNode.ChildNodes[0];
            var testExprType = testExpr.ExprEvaluator.ReturnType.GetBoxedType();

            if (perStreamExprs.Count > 1)
            {
                return;
            }
            var entry = perStreamExprs.First();

            ExprNode[] exprNodes = ExprNodeUtility.ToArray(entry.Value);
            foreach (ExprNode node in exprNodes)
            {
                var exprType = node.ExprEvaluator.ReturnType;
                if (exprType.GetBoxedType() != testExprType)
                {
                    return;
                }
            }

            int?testStreamNum;
            int setStream = entry.Key.Value;

            if (!(testExpr is ExprIdentNode))
            {
                EligibilityDesc eligibility = EligibilityUtil.VerifyInputStream(testExpr, setStream);
                if (!eligibility.Eligibility.IsEligible())
                {
                    return;
                }
                if (eligibility.Eligibility == Eligibility.REQUIRE_ONE && setStream == eligibility.StreamNum)
                {
                    return;
                }
                testStreamNum = eligibility.StreamNum;
            }
            else
            {
                testStreamNum = ((ExprIdentNode)testExpr).StreamId;
            }

            if (testStreamNum == null)
            {
                queryGraph.AddInSetMultiIndexUnkeyed(testExpr, setStream, exprNodes);
            }
            else
            {
                if (testStreamNum.Equals(entry.Key))
                {
                    return;
                }
                queryGraph.AddInSetMultiIndex(testStreamNum.Value, testExpr, setStream, exprNodes);
            }
        }