private LiteralExpression ParseBooleanLiteral() { bool value = _token.Id == TokenId.TRUE; NextToken(); return(LiteralExpression.FromBoolean(value)); }
private ExpressionNode CreateProbeColumnRef(RowBufferEntry probeColumn) { if (!ProbingEnabled) { return(LiteralExpression.FromBoolean(true)); } RowBufferEntryExpression probeColumnRef = new RowBufferEntryExpression(probeColumn); return(probeColumnRef); }
public override ExpressionNode VisitBinaryExpression(BinaryExpression expression) { if (expression.Op == BinaryOperator.LogicalAnd) { return(base.VisitBinaryExpression(expression)); } else if (expression.Op == BinaryOperator.Equal) { RowBufferEntry[] leftRowBufferEntries = AstUtil.GetRowBufferEntryReferences(expression.Left); RowBufferEntry[] rightRowBufferEntries = AstUtil.GetRowBufferEntryReferences(expression.Right); if (leftRowBufferEntries.Length == 1 && rightRowBufferEntries.Length == 1) { RowBufferEntry leftRowBufferEntry = leftRowBufferEntries[0]; RowBufferEntry rightRowBufferEntry = rightRowBufferEntries[0]; if (leftRowBufferEntry != rightRowBufferEntry) { // Both expressions depend on extactly one row buffer entry but // they are not refering to the same row buffer entry. bool leftDependsOnLeft = ArrayHelpers.Contains(_leftDefinedEntries, leftRowBufferEntry); bool rightDependsOnRight = ArrayHelpers.Contains(_rightDefinedEntries, rightRowBufferEntry); bool leftDependsOnRight = ArrayHelpers.Contains(_rightDefinedEntries, leftRowBufferEntry); bool rightDependsOnLeft = ArrayHelpers.Contains(_leftDefinedEntries, rightRowBufferEntry); if (leftDependsOnRight && rightDependsOnLeft) { ExpressionNode oldLeft = expression.Left; expression.Left = expression.Right; expression.Right = oldLeft; leftDependsOnLeft = true; rightDependsOnRight = true; } if (leftDependsOnLeft && rightDependsOnRight) { _equalPredicates.Add(expression); return(LiteralExpression.FromBoolean(true)); } } } } return(expression); }
public override ExpressionNode VisitExistsSubselect(ExistsSubselect expression) { AlgebraNode input = GetAndResetLastNode(); ResultAlgebraNode algebrizedQuery = Algebrizer.Convert(expression.Query); if (!expression.Negated && AstUtil.WillProduceAtLeastOneRow(algebrizedQuery)) { if (input == null) { SetLastAlgebraNode(CreateConstantScan()); } else { SetLastAlgebraNode(input); } return(LiteralExpression.FromBoolean(true)); } if (!expression.Negated && !ProbingEnabled && input == null) { SetLastAlgebraNode(algebrizedQuery); return(LiteralExpression.FromBoolean(true)); } else { if (input == null) { input = CreateConstantScan(); } RowBufferEntry probeColumn = CreateProbeColumn(); JoinAlgebraNode joinAlgebraNode = new JoinAlgebraNode(); joinAlgebraNode.PassthruPredicate = CurrentPassthruPredicate; joinAlgebraNode.ProbeBufferEntry = probeColumn; joinAlgebraNode.Left = input; joinAlgebraNode.Right = algebrizedQuery; joinAlgebraNode.Op = expression.Negated ? JoinAlgebraNode.JoinOperator.LeftAntiSemiJoin : JoinAlgebraNode.JoinOperator.LeftSemiJoin; SetLastAlgebraNode(joinAlgebraNode); return(CreateProbeColumnRef(probeColumn)); } }
public override ExpressionNode VisitBinaryExpression(BinaryExpression expression) { if (expression.Op == BinaryOperator.LogicalAnd) { return(base.VisitBinaryExpression(expression)); } else if (expression.Op == BinaryOperator.Equal) { RowBufferEntry[] leftRowBufferEntries = AstUtil.GetRowBufferEntryReferences(expression.Left); RowBufferEntry[] rightRowBufferEntries = AstUtil.GetRowBufferEntryReferences(expression.Right); if (leftRowBufferEntries.Length == 1 && rightRowBufferEntries.Length == 1) { RowBufferEntry leftRowBufferEntry = leftRowBufferEntries[0]; RowBufferEntry rightRowBufferEntry = rightRowBufferEntries[0]; bool leftIsOuter = IsOuterReference(leftRowBufferEntry); bool rightIsOuter = IsOuterReference(rightRowBufferEntry); if (leftRowBufferEntry != rightRowBufferEntry && leftIsOuter ^ rightIsOuter) { // Both expressions depend on extactly one row buffer entry but // they are not refering to the same row buffer entry and // only one is an outer reference. SpoolExpression spoolExpression = new SpoolExpression(); if (leftIsOuter) { spoolExpression.IndexExpression = expression.Right; spoolExpression.ProbeExpression = expression.Left; } else { spoolExpression.IndexExpression = expression.Left; spoolExpression.ProbeExpression = expression.Right; } _spoolExpressions.Add(spoolExpression); return(LiteralExpression.FromBoolean(true)); } } } return(expression); }
public override ExpressionNode VisitIsNullExpression(IsNullExpression expression) { base.VisitIsNullExpression(expression); ConstantExpression constantExpression = expression.Expression as ConstantExpression; if (constantExpression != null) { if (expression.Negated) { return(LiteralExpression.FromBoolean(constantExpression.GetValue() != null)); } else { return(LiteralExpression.FromBoolean(constantExpression.GetValue() == null)); } } return(expression); }
public override ExpressionNode VisitBinaryExpression(BinaryExpression expression) { base.VisitBinaryExpression(expression); ConstantExpression leftConstant = expression.Left as ConstantExpression; ConstantExpression rightConstant = expression.Right as ConstantExpression; if (leftConstant != null && rightConstant != null) { // Both operands are constants, compute the result and return a constant node. try { return(LiteralExpression.FromTypedValue(expression.GetValue(), expression.ExpressionType)); } catch (RuntimeException ex) { _errorReporter.CannotFoldConstants(ex); } } else if ((leftConstant != null || rightConstant != null) && (expression.Op == BinaryOperator.LogicalAnd || expression.Op == BinaryOperator.LogicalOr)) { // We have a boolean AND or OR expression where one operand is a constant. Check if we // already know the result. if (expression.Op == BinaryOperator.LogicalAnd) { // Check if one operand is false if (leftConstant != null && !leftConstant.IsNullValue && !leftConstant.AsBoolean || rightConstant != null && !rightConstant.IsNullValue && !rightConstant.AsBoolean) { return(LiteralExpression.FromBoolean(false)); } } else { // Check if one operand is true if (leftConstant != null && !leftConstant.IsNullValue && leftConstant.AsBoolean || rightConstant != null && !rightConstant.IsNullValue && rightConstant.AsBoolean) { return(LiteralExpression.FromBoolean(true)); } } // We don't know the result but we can throw away the and/or expression // by replacing it with the unknown part. if (leftConstant != null && !leftConstant.IsNullValue) { return(expression.Right); } else if (rightConstant != null && !rightConstant.IsNullValue) { return(expression.Left); } return(expression); } // If we getting here we return the orginal one. return(expression); }
public override ExpressionNode VisitAllAnySubselect(AllAnySubselect expression) { expression.Left = VisitExpression(expression.Left); ResultAlgebraNode algebrizedQuery = Algebrizer.Convert(expression.Query); ExpressionNode leftExpression = expression.Left; RowBufferEntryExpression rightExpression = new RowBufferEntryExpression(); rightExpression.RowBufferEntry = algebrizedQuery.OutputList[0]; ExpressionBuilder expressionBuilder = new ExpressionBuilder(); expressionBuilder.Push(leftExpression); expressionBuilder.Push(rightExpression); expressionBuilder.PushBinary(expression.Op); bool negated = (expression.Type == AllAnySubselect.AllAnyType.All); if (negated) { expressionBuilder.PushUnary(UnaryOperator.LogicalNot); expressionBuilder.Push(leftExpression); expressionBuilder.PushIsNull(); expressionBuilder.Push(rightExpression); expressionBuilder.PushIsNull(); expressionBuilder.PushNAry(LogicalOperator.Or); } ExpressionNode filterPredicate = expressionBuilder.Pop(); FilterAlgebraNode filterAlgebraNode = new FilterAlgebraNode(); filterAlgebraNode.Input = algebrizedQuery; filterAlgebraNode.Predicate = filterPredicate; AlgebraNode input = GetAndResetLastNode(); if (!negated && !ProbingEnabled && input == null) { SetLastAlgebraNode(filterAlgebraNode); return(LiteralExpression.FromBoolean(true)); } else { if (input == null) { input = CreateConstantScan(); } RowBufferEntry probeColumn = CreateProbeColumn(); JoinAlgebraNode joinAlgebraNode = new JoinAlgebraNode(); joinAlgebraNode.PassthruPredicate = CurrentPassthruPredicate; joinAlgebraNode.ProbeBufferEntry = probeColumn; joinAlgebraNode.Left = input; joinAlgebraNode.Right = filterAlgebraNode; joinAlgebraNode.Op = negated ? JoinAlgebraNode.JoinOperator.LeftAntiSemiJoin : JoinAlgebraNode.JoinOperator.LeftSemiJoin; SetLastAlgebraNode(joinAlgebraNode); return(CreateProbeColumnRef(probeColumn)); } }