public Expression makeOptimizedFunctionCall( ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, final Expression... arguments) throws XPathException { // See if we can deduce the answer from the cardinality int c = arguments[0].getCardinality(); if (c == StaticProperty.ALLOWS_ONE_OR_MORE) { return Literal.makeLiteral(BooleanValue.FALSE, arguments[0]); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.TRUE, arguments[0]); } // Rewrite // empty(A|B) => empty(A) and empty(B) if (arguments[0] instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) arguments[0]; if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo); } } return null; }
public Expression makeOptimizedFunctionCall( ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, final Expression... arguments) throws XPathException { // See if we can deduce the answer from the cardinality int c = arguments[0].getCardinality(); if (c == StaticProperty.ALLOWS_ONE_OR_MORE) { return Literal.makeLiteral(BooleanValue.FALSE, arguments[0]); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.TRUE, arguments[0]); } // Rewrite // empty(A|B) => empty(A) and empty(B) if (arguments[0] instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) arguments[0]; if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo); } } return null; }
public Expression makeOptimizedFunctionCall( ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, final Expression... arguments) throws XPathException { // See if we can deduce the answer from the cardinality int c = arguments[0].getCardinality(); if (c == StaticProperty.ALLOWS_ONE_OR_MORE) { return Literal.makeLiteral(BooleanValue.TRUE, arguments[0]); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.FALSE, arguments[0]); } // Don't sort the argument arguments[0] = arguments[0].unordered(false, visitor.isOptimizeForStreaming()); // Rewrite // exists(A|B) => exists(A) or exists(B) if (arguments[0] instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) arguments[0]; if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getRhsExpression()); return new OrExpression(e0, e1).optimize(visitor, contextInfo); } } return null; }
public Expression makeOptimizedFunctionCall( ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, final Expression... arguments) throws XPathException { // See if we can deduce the answer from the cardinality int c = arguments[0].getCardinality(); if (c == StaticProperty.ALLOWS_ONE_OR_MORE) { return Literal.makeLiteral(BooleanValue.TRUE, arguments[0]); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.FALSE, arguments[0]); } // Don't sort the argument arguments[0] = arguments[0].unordered(false, visitor.isOptimizeForStreaming()); // Rewrite // exists(A|B) => exists(A) or exists(B) if (arguments[0] instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) arguments[0]; if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getRhsExpression()); return new OrExpression(e0, e1).optimize(visitor, contextInfo); } } return null; }
if (v.getOperator() == Token.UNION) { int newop = (operation == EXISTS ? Token.OR : Token.AND); FunctionCall e0 = SystemFunction.makeSystemFunction(
if (v.getOperator() == Token.UNION) { int newop = (operation == EXISTS ? Token.OR : Token.AND); FunctionCall e0 = SystemFunction.makeSystemFunction(
if (v.getOperator() == Token.UNION) { int newop = (operation == EXISTS ? Token.OR : Token.AND); FunctionCall e0 = SystemFunction.makeSystemFunction(
public Expression optimize(/*@NotNull*/ ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e2 = super.optimize(visitor, contextInfo); if (e2 != this) { return e2; } // See if we can deduce the answer from the cardinality int c = getArg(0).getCardinality(); if (!Cardinality.allowsZero(c)) { return Literal.makeLiteral(BooleanValue.TRUE, e2); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.FALSE, e2); } // Don't sort the argument setArg(0, getArg(0).unordered(false, visitor.isOptimizeForStreaming())); // Rewrite // exists(A|B) => exists(A) or exists(B) if (getArg(0) instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) getArg(0); if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getRhsExpression()); return new OrExpression(e0, e1).optimize(visitor, contextInfo); } } return this; }
public Expression optimize(/*@NotNull*/ ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e2 = super.optimize(visitor, contextInfo); if (e2 != this) { return e2; } // See if we can deduce the answer from the cardinality int c = getArg(0).getCardinality(); if (!Cardinality.allowsZero(c)) { return Literal.makeLiteral(BooleanValue.TRUE, e2); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.FALSE, e2); } // Don't sort the argument setArg(0, getArg(0).unordered(false, visitor.isOptimizeForStreaming())); // Rewrite // exists(A|B) => exists(A) or exists(B) if (getArg(0) instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) getArg(0); if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("exists", getRetainedStaticContext(), v.getRhsExpression()); return new OrExpression(e0, e1).optimize(visitor, contextInfo); } } return this; }
if (v.getOperator() == Token.UNION && !visitor.isOptimizeForStreaming()) { Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression());
if (v.getOperator() == Token.UNION && !visitor.isOptimizeForStreaming()) { Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression());