コード例 #1
0
        static bool EqualUseIndex <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session   = sourceCollection.Session;
            CompareByField <Key> comparer  = sourceCollection.Comparer as CompareByField <Key>;
            Expression           leftSide  = binExp.Left;
            Expression           rightSide = binExp.Right;
            object rightValue = GetRightValue(leftSide, rightSide);

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    if (session.TraceIndexUsage)
                    {
                        Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                    }
                    return(true);
                }
            }
            else
            {
                if (comparer != null)
                {
                    MemberExpression returnedEx = null;
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        if (session.TraceIndexUsage)
                        {
                            Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        static bool AndUseIndex <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            while (binExp.NodeType == ExpressionType.AndAlso)
            {
                BinaryExpression leftExpr = (BinaryExpression)binExp.Left;
                binExp = leftExpr;
                if (binExp.NodeType != ExpressionType.Equal && binExp.NodeType != ExpressionType.AndAlso)
                {
                    return(false);
                }
            }
            SessionBase session = sourceCollection.Session;

            if (session.TraceIndexUsage)
            {
                Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
            }
            return(true);
        }
コード例 #3
0
        static bool LessThanUseIndex <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session   = sourceCollection.Session;
            CompareByField <Key> comparer  = sourceCollection.Comparer as CompareByField <Key>;
            Expression           leftSide  = binExp.Left;
            Expression           rightSide = binExp.Right;
            object rightValue = GetRightValue(leftSide, rightSide);

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    if (session.TraceIndexUsage)
                    {
                        Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                    }
                    return(true);
                }
            }
            else
            {
                if (comparer != null)
                {
                    //if we were able to create a hash from the right side (likely)
                    MemberExpression returnedEx = null;
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        if (session.TraceIndexUsage)
                        {
                            Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                        }
                        return(true);
                    }
                    else if (leftSide.NodeType == ExpressionType.Call)
                    {
                        // don't know yet how to handle TODO

                        /*MethodCallExpression expression = leftSide as MethodCallExpression;
                         * Trace.Out.WriteLine("Method: " + expression.Method.Name);
                         * Trace.Out.WriteLine("Args: ");
                         * foreach (var exp in expression.Arguments)
                         * sourceCollection where */
                    }
                }
            }
            return(false);
        }