diff --git a/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer/BindingSetAssignmentInlinerOptimizer.java b/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer/BindingSetAssignmentInlinerOptimizer.java index 2d6c903d105..75350a62b69 100644 --- a/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer/BindingSetAssignmentInlinerOptimizer.java +++ b/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer/BindingSetAssignmentInlinerOptimizer.java @@ -72,6 +72,9 @@ public void meet(Filter node) throws RuntimeException { public void meet(LeftJoin leftJoin) { leftJoin.getLeftArg().visit(this); // we can not pre-bind values for the optional part of the left-join + + // in a left-join, we can pre-bind variables in the RHS _if_, after pre-binding in the LHS, those variables + // are now fixed. } @Override diff --git a/core/queryparser/sparql/src/test/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilderTest.java b/core/queryparser/sparql/src/test/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilderTest.java index 37c1bf3e540..90ec4eecaee 100644 --- a/core/queryparser/sparql/src/test/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilderTest.java +++ b/core/queryparser/sparql/src/test/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilderTest.java @@ -19,7 +19,9 @@ import java.util.List; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.query.algebra.BindingSetAssignment; import org.eclipse.rdf4j.query.algebra.Extension; +import org.eclipse.rdf4j.query.algebra.Join; import org.eclipse.rdf4j.query.algebra.Order; import org.eclipse.rdf4j.query.algebra.Projection; import org.eclipse.rdf4j.query.algebra.Service; @@ -82,6 +84,29 @@ public void testAskQuerySolutionModifiers() { } + @Test + public void testValuesOptionalQuery() throws Exception { + String query = "select ?parent ?child\n" + + "where {\n" + + " values ?type {}\n" + + " ?parent ?type .\n" + + " optional {\n" + + " ?child ?parent ;\n" + + " ?type .\n" + + " }\n" + + "}"; + + TupleExprBuilder builder = new TupleExprBuilder(SimpleValueFactory.getInstance()); + ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(query); + TupleExpr result = builder.visit(qc, null); + + assertThat(result).isInstanceOf(Projection.class); + Join topJoin = (Join) ((Projection) result).getArg(); + + assertThat(topJoin.getLeftArg()).isInstanceOf(BindingSetAssignment.class); + + } + @Test public void testNegatedPathWithFixedObject() { String query = "ASK WHERE { ?s ! . }"; diff --git a/core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/benchmark/SPARQLValuesClauseBenchmark.java b/core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/benchmark/SPARQLValuesClauseBenchmark.java index 4917ef0341c..d3560e6ca92 100644 --- a/core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/benchmark/SPARQLValuesClauseBenchmark.java +++ b/core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/benchmark/SPARQLValuesClauseBenchmark.java @@ -153,6 +153,19 @@ public void afterClass() { @Benchmark public long valuesOptionalQuery() { try (SailRepositoryConnection connection = repository.getConnection()) { +// +// System.out.println("ONLY PARSED:"); +// System.out.println(connection.prepareTupleQuery(query_with_values_clause)); +// System.out.println("\nUNOPTIMIZED:"); +// System.out.println( +// connection.prepareTupleQuery(query_with_values_clause).explain(Explanation.Level.Unoptimized)); +// +// System.out.println(); +// System.out.println("OPTIMIZED:"); +// System.out.println( +// connection.prepareTupleQuery(query_with_values_clause).explain(Explanation.Level.Optimized)); + +// return 0L; return connection .prepareTupleQuery(query_with_values_clause) .evaluate() @@ -164,6 +177,7 @@ public long valuesOptionalQuery() { @Benchmark public long simpleEquivalentQuery() { try (SailRepositoryConnection connection = repository.getConnection()) { + return connection .prepareTupleQuery(query_without_values_clause) .evaluate()