diff --git a/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/QueryBenchmarkTest.java b/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/QueryBenchmarkTest.java index b033da1f9fd..7a0fc04b60f 100644 --- a/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/QueryBenchmarkTest.java +++ b/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/QueryBenchmarkTest.java @@ -11,6 +11,8 @@ package org.eclipse.rdf4j.sail.lmdb; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -48,6 +50,11 @@ public class QueryBenchmarkTest { private static final String query3; private static final String query4; private static final String query5; + private static final String optionalLhsFilterQuery; + private static final String optionalRhsFilterQuery; + private static final String orderedUnionLimitQuery; + private static final String subSelectQuery; + private static final String multipleSubSelectQuery; static List statementList; @@ -58,6 +65,16 @@ public class QueryBenchmarkTest { query3 = IOUtils.toString(getResourceAsStream("benchmarkFiles/query3.qr"), StandardCharsets.UTF_8); query4 = IOUtils.toString(getResourceAsStream("benchmarkFiles/query4.qr"), StandardCharsets.UTF_8); query5 = IOUtils.toString(getResourceAsStream("benchmarkFiles/query5.qr"), StandardCharsets.UTF_8); + optionalLhsFilterQuery = IOUtils.toString( + getResourceAsStream("benchmarkFiles/optional-lhs-filter.qr"), StandardCharsets.UTF_8); + optionalRhsFilterQuery = IOUtils.toString( + getResourceAsStream("benchmarkFiles/optional-rhs-filter.qr"), StandardCharsets.UTF_8); + orderedUnionLimitQuery = IOUtils.toString( + getResourceAsStream("benchmarkFiles/ordered-union-limit.qr"), StandardCharsets.UTF_8); + subSelectQuery = IOUtils.toString(getResourceAsStream("benchmarkFiles/sub-select.qr"), + StandardCharsets.UTF_8); + multipleSubSelectQuery = IOUtils.toString( + getResourceAsStream("benchmarkFiles/multiple-sub-select.qr"), StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } @@ -128,6 +145,61 @@ public void distinctPredicatesQuery() { } } + @Test + public void optionalLhsFilterQueryProducesExpectedCount() { + try (SailRepositoryConnection connection = repository.getConnection()) { + long count; + try (var stream = connection.prepareTupleQuery(optionalLhsFilterQuery).evaluate().stream()) { + count = stream.count(); + } + assertEquals(34904L, count); + } + } + + @Test + public void optionalRhsFilterQueryProducesExpectedCount() { + try (SailRepositoryConnection connection = repository.getConnection()) { + long count; + try (var stream = connection.prepareTupleQuery(optionalRhsFilterQuery).evaluate().stream()) { + count = stream.count(); + } + assertEquals(37917L, count); + } + } + + @Test + public void orderedUnionLimitQueryProducesExpectedCount() { + try (SailRepositoryConnection connection = repository.getConnection()) { + long count; + try (var stream = connection.prepareTupleQuery(orderedUnionLimitQuery).evaluate().stream()) { + count = stream.count(); + } + assertEquals(250L, count); + } + } + + @Test + public void subSelectQueryProducesExpectedCount() { + try (SailRepositoryConnection connection = repository.getConnection()) { + long count; + try (var stream = connection.prepareTupleQuery(subSelectQuery).evaluate().stream()) { + count = stream.count(); + } + assertEquals(16035L, count); + } + } + + @Test + public void multipleSubSelectQueryProducesExpectedCount() { + try (SailRepositoryConnection connection = repository.getConnection()) { + long count; + try (var stream = connection.prepareTupleQuery(multipleSubSelectQuery).evaluate().stream()) { + count = stream.count(); + } + assertEquals(27881L, count); + } + } + @Test public void removeByQuery() { try (SailRepositoryConnection connection = repository.getConnection()) { diff --git a/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/benchmark/QueryBenchmark.java b/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/benchmark/QueryBenchmark.java index 504b9cd3b5c..d4a93a3060e 100644 --- a/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/benchmark/QueryBenchmark.java +++ b/core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/benchmark/QueryBenchmark.java @@ -67,6 +67,9 @@ public class QueryBenchmark { private static final String common_themes; private static final String different_datasets_with_similar_distributions; private static final String long_chain; + private static final String optional_lhs_filter; + private static final String optional_rhs_filter; + private static final String ordered_union_limit; private static final String lots_of_optional; private static final String minus; private static final String nested_optionals; @@ -74,6 +77,8 @@ public class QueryBenchmark { private static final String query_distinct_predicates; private static final String simple_filter_not; private static final String wild_card_chain_with_common_ends; + private static final String sub_select; + private static final String multiple_sub_select; static { try { @@ -83,6 +88,12 @@ public class QueryBenchmark { getResourceAsStream("benchmarkFiles/different-datasets-with-similar-distributions.qr"), StandardCharsets.UTF_8); long_chain = IOUtils.toString(getResourceAsStream("benchmarkFiles/long-chain.qr"), StandardCharsets.UTF_8); + optional_lhs_filter = IOUtils.toString(getResourceAsStream("benchmarkFiles/optional-lhs-filter.qr"), + StandardCharsets.UTF_8); + optional_rhs_filter = IOUtils.toString(getResourceAsStream("benchmarkFiles/optional-rhs-filter.qr"), + StandardCharsets.UTF_8); + ordered_union_limit = IOUtils.toString(getResourceAsStream("benchmarkFiles/ordered-union-limit.qr"), + StandardCharsets.UTF_8); lots_of_optional = IOUtils.toString(getResourceAsStream("benchmarkFiles/lots-of-optional.qr"), StandardCharsets.UTF_8); minus = IOUtils.toString(getResourceAsStream("benchmarkFiles/minus.qr"), StandardCharsets.UTF_8); @@ -102,6 +113,9 @@ public class QueryBenchmark { StandardCharsets.UTF_8); wild_card_chain_with_common_ends = IOUtils.toString( getResourceAsStream("benchmarkFiles/wild-card-chain-with-common-ends.qr"), StandardCharsets.UTF_8); + sub_select = IOUtils.toString(getResourceAsStream("benchmarkFiles/sub-select.qr"), StandardCharsets.UTF_8); + multiple_sub_select = IOUtils.toString( + getResourceAsStream("benchmarkFiles/multiple-sub-select.qr"), StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); @@ -241,6 +255,33 @@ public long nested_optionals() { } } + @Benchmark + public long optional_lhs_filter() { + try (SailRepositoryConnection connection = repository.getConnection()) { + return count(connection + .prepareTupleQuery(optional_lhs_filter) + .evaluate()); + } + } + + @Benchmark + public long optional_rhs_filter() { + try (SailRepositoryConnection connection = repository.getConnection()) { + return count(connection + .prepareTupleQuery(optional_rhs_filter) + .evaluate()); + } + } + + @Benchmark + public long ordered_union_limit() { + try (SailRepositoryConnection connection = repository.getConnection()) { + return count(connection + .prepareTupleQuery(ordered_union_limit) + .evaluate()); + } + } + // @Benchmark // public long particularly_large_join_surface() { // try (SailRepositoryConnection connection = repository.getConnection()) { @@ -270,6 +311,24 @@ public long simple_filter_not() { } } + @Benchmark + public long sub_select() { + try (SailRepositoryConnection connection = repository.getConnection()) { + return count(connection + .prepareTupleQuery(sub_select) + .evaluate()); + } + } + + @Benchmark + public long multiple_sub_select() { + try (SailRepositoryConnection connection = repository.getConnection()) { + return count(connection + .prepareTupleQuery(multiple_sub_select) + .evaluate()); + } + } + // @Benchmark // public long wild_card_chain_with_common_ends() { // try (SailRepositoryConnection connection = repository.getConnection()) { diff --git a/core/sail/lmdb/src/test/resources/benchmarkFiles/multiple-sub-select.qr b/core/sail/lmdb/src/test/resources/benchmarkFiles/multiple-sub-select.qr new file mode 100644 index 00000000000..9e625124653 --- /dev/null +++ b/core/sail/lmdb/src/test/resources/benchmarkFiles/multiple-sub-select.qr @@ -0,0 +1,41 @@ +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: +PREFIX dcat: +PREFIX dc: +PREFIX skos: +PREFIX foaf: +PREFIX dct: + +SELECT ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 where { +{ + select * where { + ?a a ?type2. + ?b a ?type1. + + ?b dcat:dataset ?a. + + ?a dcat:distribution ?mbox. + ?a dct:language ?language. + FILTER (?type1 != ?type2) + ?a dct:identifier ?identifier. + + } +} + + + { + select distinct ?a (count(?dist) as ?count) ?language2 where { + ?a a ?type2. + ?a dcat:distribution ?dist. + ?a dct:language ?language2. + } group by ?a ?language2 having (?count > 2) + } + +} + + + diff --git a/core/sail/lmdb/src/test/resources/benchmarkFiles/optional-lhs-filter.qr b/core/sail/lmdb/src/test/resources/benchmarkFiles/optional-lhs-filter.qr new file mode 100644 index 00000000000..cca9cc1afc3 --- /dev/null +++ b/core/sail/lmdb/src/test/resources/benchmarkFiles/optional-lhs-filter.qr @@ -0,0 +1,24 @@ +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: +PREFIX dcat: +PREFIX dc: +PREFIX skos: +PREFIX foaf: +PREFIX dct: + +SELECT * WHERE { + VALUES ?distType { dcat:Distribution dcat:distribution } + + ?dist a ?distType. + ?dist dc:license ?license . + + OPTIONAL { + ?a dcat:distribution ?dist. + + FILTER(?license = ) + } +} diff --git a/core/sail/lmdb/src/test/resources/benchmarkFiles/optional-rhs-filter.qr b/core/sail/lmdb/src/test/resources/benchmarkFiles/optional-rhs-filter.qr new file mode 100644 index 00000000000..fcc6cc55e7c --- /dev/null +++ b/core/sail/lmdb/src/test/resources/benchmarkFiles/optional-rhs-filter.qr @@ -0,0 +1,24 @@ +PREFIX eu-lang: +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: +PREFIX dcat: +PREFIX dc: +PREFIX skos: +PREFIX foaf: +PREFIX dct: + +SELECT * WHERE { + VALUES ?distType { dcat:Distribution dcat:distribution } + + ?dist a ?distType. + + OPTIONAL { + ?a dcat:distribution ?dist. + ?a dct:language $lang. + FILTER(?lang = eu-lang:ENG) + } +} diff --git a/core/sail/lmdb/src/test/resources/benchmarkFiles/ordered-union-limit.qr b/core/sail/lmdb/src/test/resources/benchmarkFiles/ordered-union-limit.qr new file mode 100644 index 00000000000..0fa673160ae --- /dev/null +++ b/core/sail/lmdb/src/test/resources/benchmarkFiles/ordered-union-limit.qr @@ -0,0 +1,34 @@ +PREFIX eu-filetype: +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: +PREFIX dcat: +PREFIX dc: +PREFIX skos: +PREFIX foaf: +PREFIX dct: + +SELECT ?dist ?value WHERE { + { + SELECT ?dist ?value WHERE { + ?dist a dcat:Distribution ; + dct:license ?value . + } + ORDER BY ?value ?dist + LIMIT 200 + } + UNION + { + SELECT ?dist ?value WHERE { + ?dist a dcat:Distribution ; + dct:format ?value . + } + ORDER BY ?value ?dist + LIMIT 200 + } +} +ORDER BY ?value ?dist +LIMIT 250 diff --git a/core/sail/lmdb/src/test/resources/benchmarkFiles/sub-select.qr b/core/sail/lmdb/src/test/resources/benchmarkFiles/sub-select.qr new file mode 100644 index 00000000000..81a2fbcd2b1 --- /dev/null +++ b/core/sail/lmdb/src/test/resources/benchmarkFiles/sub-select.qr @@ -0,0 +1,38 @@ +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: +PREFIX dcat: +PREFIX dc: +PREFIX skos: +PREFIX foaf: +PREFIX dct: + +SELECT ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 where { + + ?a a ?type2. + ?b a ?type1. + + ?b dcat:dataset ?a. + + ?a dcat:distribution ?mbox. + ?a dct:language ?language. + FILTER (?type1 != ?type2) + ?a dct:identifier ?identifier. + + BIND(?a as ?c) + + { + select distinct ?c (count(?dist) as ?count) ?language2 where { + ?c a ?type2. + ?c dcat:distribution ?dist. + ?c dct:language ?language2. + } group by ?c ?language2 having (?count > 2) + } + +} group by ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 order by ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 + + +