Exemplo n.º 1
0
        private bool TryOptimizeIN(SelectASTNode selectASTNode, ReadLogicalElement input, TableDefinition tableDefinition, out CartesianProductElement result)
        {
            if (selectASTNode.Condition is RelOpASTNode relOpASTNode &&
                relOpASTNode.RelationOperator == Compiler.Common.RelOp.In)
            {
                SelectASTNode     innerSelectASTNode     = null;
                IdentifierASTNode outerIdentifierASTNode = null;

                if (relOpASTNode.Right is SelectASTNode)
                {
                    innerSelectASTNode = (SelectASTNode)relOpASTNode.Right;

                    if (relOpASTNode.Left is IdentifierASTNode)
                    {
                        outerIdentifierASTNode = (IdentifierASTNode)relOpASTNode.Left;
                    }
                }

                if (relOpASTNode.Right is IdentifierASTNode)
                {
                    outerIdentifierASTNode = (IdentifierASTNode)relOpASTNode.Right;

                    if (relOpASTNode.Left is SelectASTNode)
                    {
                        innerSelectASTNode = (SelectASTNode)relOpASTNode.Left;
                    }
                }

                if (innerSelectASTNode != null &&
                    outerIdentifierASTNode != null)
                {
                    result = new CartesianProductElement(input, GetElementForTreeNode(innerSelectASTNode) as ReadLogicalElement, GetColumnFromIdentifierNode(tableDefinition, outerIdentifierASTNode), SelectColumnsToColumns(_relationManager.GetTable(innerSelectASTNode.From.Identifier.Identifier), innerSelectASTNode.SelectColumns).First().AttributeDefinition);
                    return(true);
                }
            }

            result = null;
            return(false);
        }
Exemplo n.º 2
0
        public int GetSizeOfCondition(ReadLogicalElement input, Condition condition)
        {
            int sizeOfRelation = input.T();

            if (condition == null)
            {
                return(sizeOfRelation);
            }

            if (condition is AndCondition andCondition)
            {
                return(sizeOfRelation * ((GetSizeOfCondition(input, andCondition.Left) / sizeOfRelation) * (GetSizeOfCondition(input, andCondition.Right) / sizeOfRelation)));
            }
            else if (condition is OrCondition orCondition)
            {
                int m1 = GetSizeOfCondition(input, orCondition.Left);
                int m2 = GetSizeOfCondition(input, orCondition.Right);
                return(sizeOfRelation * (1 - ((1 - (m1 / sizeOfRelation)) * ((m2 / sizeOfRelation)))));
            }
            else if (condition is LeafCondition leafCondition)
            {
                switch (leafCondition.Operation)
                {
                case Compiler.Common.RelOp.Equals:
                    return((int)Math.Round(sizeOfRelation * ((double)1 / (double)input.V(leafCondition.Column))));

                case Compiler.Common.RelOp.GreaterOrEqualThan:
                case Compiler.Common.RelOp.GreaterThan:
                case Compiler.Common.RelOp.LessOrEqualThan:
                case Compiler.Common.RelOp.LessThan:
                case Compiler.Common.RelOp.NotEquals:
                    return(sizeOfRelation);
                }
            }

            return(-1);
        }
 public ProjectionElement(ReadLogicalElement input, List <ProjectionColumn> columns)
     : base(input)
 {
     Columns = columns;
 }
Exemplo n.º 4
0
 public SelectionElement(ReadLogicalElement input, Condition condition)
     : base(input)
 {
     Condition = condition;
 }
 public CartesianProductElement(ReadLogicalElement left, ReadLogicalElement right, AttributeDefinition leftJoinColumn, AttributeDefinition rightJoinColumn)
     : base(left, right)
 {
     LeftJoinColumn  = leftJoinColumn;
     RightJoinColumn = rightJoinColumn;
 }