From: <mrp...@us...> - 2011-05-25 20:41:53
|
Revision: 4551 http://bigdata.svn.sourceforge.net/bigdata/?rev=4551&view=rev Author: mrpersonick Date: 2011-05-25 20:41:47 +0000 (Wed, 25 May 2011) Log Message: ----------- fixed a performance regression by optimizing a CompareBOp into a SameTermBOp when one of the operands is a Constant<URI> Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.java 2011-05-25 20:25:52 UTC (rev 4550) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.java 2011-05-25 20:41:47 UTC (rev 4551) @@ -26,11 +26,16 @@ import java.util.Map; +import org.openrdf.query.algebra.Compare.CompareOp; + import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.NV; +import com.bigdata.bop.PipelineOp; import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.constraints.CompareBOp.Annotations; /** * Compare two terms for exact equality. @@ -42,13 +47,30 @@ */ private static final long serialVersionUID = 1L; + public interface Annotations extends PipelineOp.Annotations { + + /** + * The compare operator, which is a {@link CompareOp} enum value. + * Must be either EQ or NE. + */ + String OP = (CompareBOp.class.getName() + ".op").intern(); + + } + public SameTermBOp(final IValueExpression<? extends IV> left, final IValueExpression<? extends IV> right) { - this(new BOp[] { left, right }, null); + this(left, right, CompareOp.EQ); } + public SameTermBOp(final IValueExpression<? extends IV> left, + final IValueExpression<? extends IV> right, final CompareOp op) { + + this(new BOp[] { left, right }, NV.asMap(new NV(Annotations.OP, op))); + + } + /** * Required shallow copy constructor. */ @@ -59,6 +81,11 @@ if (args.length != 2 || args[0] == null || args[1] == null) throw new IllegalArgumentException(); + final CompareOp op = (CompareOp) getRequiredProperty(Annotations.OP); + + if (!(op == CompareOp.EQ || op == CompareOp.NE)) + throw new IllegalArgumentException(); + } /** @@ -77,7 +104,12 @@ if (left == null || right == null) throw new SparqlTypeErrorException(); - return left.equals(right); + final CompareOp op = (CompareOp) getRequiredProperty(Annotations.OP); + + switch(op) { + case NE: return !left.equals(right); + default: return left.equals(right); + } } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-05-25 20:25:52 UTC (rev 4550) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-05-25 20:41:47 UTC (rev 4551) @@ -1932,11 +1932,35 @@ } private IValueExpression<? extends IV> toVE(final Compare compare) { - final IValueExpression<? extends IV> iv1 = + final IValueExpression<? extends IV> left = toVE(compare.getLeftArg()); - final IValueExpression<? extends IV> iv2 = + final IValueExpression<? extends IV> right = toVE(compare.getRightArg()); - return new CompareBOp(iv1, iv2, compare.getOperator()); + + /* + * If the term is a Constant<URI> and the op is EQ or NE then we can + * do a sameTerm optimization. + */ + final CompareOp op = compare.getOperator(); + if (op == CompareOp.EQ || op == CompareOp.NE) { + + if (left instanceof Constant) { + final IV iv = ((Constant<? extends IV>) left).get(); + if (iv.isURI()) { + return new SameTermBOp(left, right, op); + } + } + + if (right instanceof Constant) { + final IV iv = ((Constant<? extends IV>) right).get(); + if (iv.isURI()) { + return new SameTermBOp(left, right, op); + } + } + + } + + return new CompareBOp(left, right, compare.getOperator()); } private IValueExpression<? extends IV> toVE(final Bound bound) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |