Skip to content

Commit 3bd9c3d

Browse files
authored
Add LMDB benchmarks for optional filters and complex sub-selects (#5467)
1 parent 5b490de commit 3bd9c3d

7 files changed

Lines changed: 292 additions & 0 deletions

File tree

core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/QueryBenchmarkTest.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
package org.eclipse.rdf4j.sail.lmdb;
1313

14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
1416
import java.io.File;
1517
import java.io.IOException;
1618
import java.io.InputStream;
@@ -48,6 +50,11 @@ public class QueryBenchmarkTest {
4850
private static final String query3;
4951
private static final String query4;
5052
private static final String query5;
53+
private static final String optionalLhsFilterQuery;
54+
private static final String optionalRhsFilterQuery;
55+
private static final String orderedUnionLimitQuery;
56+
private static final String subSelectQuery;
57+
private static final String multipleSubSelectQuery;
5158

5259
static List<Statement> statementList;
5360

@@ -58,6 +65,16 @@ public class QueryBenchmarkTest {
5865
query3 = IOUtils.toString(getResourceAsStream("benchmarkFiles/query3.qr"), StandardCharsets.UTF_8);
5966
query4 = IOUtils.toString(getResourceAsStream("benchmarkFiles/query4.qr"), StandardCharsets.UTF_8);
6067
query5 = IOUtils.toString(getResourceAsStream("benchmarkFiles/query5.qr"), StandardCharsets.UTF_8);
68+
optionalLhsFilterQuery = IOUtils.toString(
69+
getResourceAsStream("benchmarkFiles/optional-lhs-filter.qr"), StandardCharsets.UTF_8);
70+
optionalRhsFilterQuery = IOUtils.toString(
71+
getResourceAsStream("benchmarkFiles/optional-rhs-filter.qr"), StandardCharsets.UTF_8);
72+
orderedUnionLimitQuery = IOUtils.toString(
73+
getResourceAsStream("benchmarkFiles/ordered-union-limit.qr"), StandardCharsets.UTF_8);
74+
subSelectQuery = IOUtils.toString(getResourceAsStream("benchmarkFiles/sub-select.qr"),
75+
StandardCharsets.UTF_8);
76+
multipleSubSelectQuery = IOUtils.toString(
77+
getResourceAsStream("benchmarkFiles/multiple-sub-select.qr"), StandardCharsets.UTF_8);
6178
} catch (IOException e) {
6279
throw new RuntimeException(e);
6380
}
@@ -128,6 +145,61 @@ public void distinctPredicatesQuery() {
128145
}
129146
}
130147

148+
@Test
149+
public void optionalLhsFilterQueryProducesExpectedCount() {
150+
try (SailRepositoryConnection connection = repository.getConnection()) {
151+
long count;
152+
try (var stream = connection.prepareTupleQuery(optionalLhsFilterQuery).evaluate().stream()) {
153+
count = stream.count();
154+
}
155+
assertEquals(34904L, count);
156+
}
157+
}
158+
159+
@Test
160+
public void optionalRhsFilterQueryProducesExpectedCount() {
161+
try (SailRepositoryConnection connection = repository.getConnection()) {
162+
long count;
163+
try (var stream = connection.prepareTupleQuery(optionalRhsFilterQuery).evaluate().stream()) {
164+
count = stream.count();
165+
}
166+
assertEquals(37917L, count);
167+
}
168+
}
169+
170+
@Test
171+
public void orderedUnionLimitQueryProducesExpectedCount() {
172+
try (SailRepositoryConnection connection = repository.getConnection()) {
173+
long count;
174+
try (var stream = connection.prepareTupleQuery(orderedUnionLimitQuery).evaluate().stream()) {
175+
count = stream.count();
176+
}
177+
assertEquals(250L, count);
178+
}
179+
}
180+
181+
@Test
182+
public void subSelectQueryProducesExpectedCount() {
183+
try (SailRepositoryConnection connection = repository.getConnection()) {
184+
long count;
185+
try (var stream = connection.prepareTupleQuery(subSelectQuery).evaluate().stream()) {
186+
count = stream.count();
187+
}
188+
assertEquals(16035L, count);
189+
}
190+
}
191+
192+
@Test
193+
public void multipleSubSelectQueryProducesExpectedCount() {
194+
try (SailRepositoryConnection connection = repository.getConnection()) {
195+
long count;
196+
try (var stream = connection.prepareTupleQuery(multipleSubSelectQuery).evaluate().stream()) {
197+
count = stream.count();
198+
}
199+
assertEquals(27881L, count);
200+
}
201+
}
202+
131203
@Test
132204
public void removeByQuery() {
133205
try (SailRepositoryConnection connection = repository.getConnection()) {

core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/benchmark/QueryBenchmark.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,18 @@ public class QueryBenchmark {
6767
private static final String common_themes;
6868
private static final String different_datasets_with_similar_distributions;
6969
private static final String long_chain;
70+
private static final String optional_lhs_filter;
71+
private static final String optional_rhs_filter;
72+
private static final String ordered_union_limit;
7073
private static final String lots_of_optional;
7174
private static final String minus;
7275
private static final String nested_optionals;
7376
private static final String particularly_large_join_surface;
7477
private static final String query_distinct_predicates;
7578
private static final String simple_filter_not;
7679
private static final String wild_card_chain_with_common_ends;
80+
private static final String sub_select;
81+
private static final String multiple_sub_select;
7782

7883
static {
7984
try {
@@ -83,6 +88,12 @@ public class QueryBenchmark {
8388
getResourceAsStream("benchmarkFiles/different-datasets-with-similar-distributions.qr"),
8489
StandardCharsets.UTF_8);
8590
long_chain = IOUtils.toString(getResourceAsStream("benchmarkFiles/long-chain.qr"), StandardCharsets.UTF_8);
91+
optional_lhs_filter = IOUtils.toString(getResourceAsStream("benchmarkFiles/optional-lhs-filter.qr"),
92+
StandardCharsets.UTF_8);
93+
optional_rhs_filter = IOUtils.toString(getResourceAsStream("benchmarkFiles/optional-rhs-filter.qr"),
94+
StandardCharsets.UTF_8);
95+
ordered_union_limit = IOUtils.toString(getResourceAsStream("benchmarkFiles/ordered-union-limit.qr"),
96+
StandardCharsets.UTF_8);
8697
lots_of_optional = IOUtils.toString(getResourceAsStream("benchmarkFiles/lots-of-optional.qr"),
8798
StandardCharsets.UTF_8);
8899
minus = IOUtils.toString(getResourceAsStream("benchmarkFiles/minus.qr"), StandardCharsets.UTF_8);
@@ -102,6 +113,9 @@ public class QueryBenchmark {
102113
StandardCharsets.UTF_8);
103114
wild_card_chain_with_common_ends = IOUtils.toString(
104115
getResourceAsStream("benchmarkFiles/wild-card-chain-with-common-ends.qr"), StandardCharsets.UTF_8);
116+
sub_select = IOUtils.toString(getResourceAsStream("benchmarkFiles/sub-select.qr"), StandardCharsets.UTF_8);
117+
multiple_sub_select = IOUtils.toString(
118+
getResourceAsStream("benchmarkFiles/multiple-sub-select.qr"), StandardCharsets.UTF_8);
105119

106120
} catch (IOException e) {
107121
throw new RuntimeException(e);
@@ -241,6 +255,33 @@ public long nested_optionals() {
241255
}
242256
}
243257

258+
@Benchmark
259+
public long optional_lhs_filter() {
260+
try (SailRepositoryConnection connection = repository.getConnection()) {
261+
return count(connection
262+
.prepareTupleQuery(optional_lhs_filter)
263+
.evaluate());
264+
}
265+
}
266+
267+
@Benchmark
268+
public long optional_rhs_filter() {
269+
try (SailRepositoryConnection connection = repository.getConnection()) {
270+
return count(connection
271+
.prepareTupleQuery(optional_rhs_filter)
272+
.evaluate());
273+
}
274+
}
275+
276+
@Benchmark
277+
public long ordered_union_limit() {
278+
try (SailRepositoryConnection connection = repository.getConnection()) {
279+
return count(connection
280+
.prepareTupleQuery(ordered_union_limit)
281+
.evaluate());
282+
}
283+
}
284+
244285
// @Benchmark
245286
// public long particularly_large_join_surface() {
246287
// try (SailRepositoryConnection connection = repository.getConnection()) {
@@ -270,6 +311,24 @@ public long simple_filter_not() {
270311
}
271312
}
272313

314+
@Benchmark
315+
public long sub_select() {
316+
try (SailRepositoryConnection connection = repository.getConnection()) {
317+
return count(connection
318+
.prepareTupleQuery(sub_select)
319+
.evaluate());
320+
}
321+
}
322+
323+
@Benchmark
324+
public long multiple_sub_select() {
325+
try (SailRepositoryConnection connection = repository.getConnection()) {
326+
return count(connection
327+
.prepareTupleQuery(multiple_sub_select)
328+
.evaluate());
329+
}
330+
}
331+
273332
// @Benchmark
274333
// public long wild_card_chain_with_common_ends() {
275334
// try (SailRepositoryConnection connection = repository.getConnection()) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
PREFIX dcat: <http://www.w3.org/ns/dcat#>
8+
PREFIX dc: <http://purl.org/dc/terms/>
9+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
10+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
11+
PREFIX dct: <http://purl.org/dc/terms/>
12+
13+
SELECT ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 where {
14+
{
15+
select * where {
16+
?a a ?type2.
17+
?b a ?type1.
18+
19+
?b dcat:dataset ?a.
20+
21+
?a dcat:distribution ?mbox.
22+
?a dct:language ?language.
23+
FILTER (?type1 != ?type2)
24+
?a dct:identifier ?identifier.
25+
26+
}
27+
}
28+
29+
30+
{
31+
select distinct ?a (count(?dist) as ?count) ?language2 where {
32+
?a a ?type2.
33+
?a dcat:distribution ?dist.
34+
?a dct:language ?language2.
35+
} group by ?a ?language2 having (?count > 2)
36+
}
37+
38+
}
39+
40+
41+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
PREFIX dcat: <http://www.w3.org/ns/dcat#>
8+
PREFIX dc: <http://purl.org/dc/terms/>
9+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
10+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
11+
PREFIX dct: <http://purl.org/dc/terms/>
12+
13+
SELECT * WHERE {
14+
VALUES ?distType { dcat:Distribution dcat:distribution }
15+
16+
?dist a ?distType.
17+
?dist dc:license ?license .
18+
19+
OPTIONAL {
20+
?a dcat:distribution ?dist.
21+
22+
FILTER(?license = <http://wiki.data.gouv.fr/wiki/Licence_Ouverte_/_Open_Licence>)
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
PREFIX eu-lang: <http://publications.europa.eu/resource/authority/language/>
2+
PREFIX ex: <http://example.com/ns#>
3+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
4+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
5+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
6+
PREFIX sh: <http://www.w3.org/ns/shacl#>
7+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
8+
PREFIX dcat: <http://www.w3.org/ns/dcat#>
9+
PREFIX dc: <http://purl.org/dc/terms/>
10+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
11+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
12+
PREFIX dct: <http://purl.org/dc/terms/>
13+
14+
SELECT * WHERE {
15+
VALUES ?distType { dcat:Distribution dcat:distribution }
16+
17+
?dist a ?distType.
18+
19+
OPTIONAL {
20+
?a dcat:distribution ?dist.
21+
?a dct:language $lang.
22+
FILTER(?lang = eu-lang:ENG)
23+
}
24+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PREFIX eu-filetype: <http://publications.europa.eu/resource/authority/file-type/>
2+
PREFIX ex: <http://example.com/ns#>
3+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
4+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
5+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
6+
PREFIX sh: <http://www.w3.org/ns/shacl#>
7+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
8+
PREFIX dcat: <http://www.w3.org/ns/dcat#>
9+
PREFIX dc: <http://purl.org/dc/terms/>
10+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
11+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
12+
PREFIX dct: <http://purl.org/dc/terms/>
13+
14+
SELECT ?dist ?value WHERE {
15+
{
16+
SELECT ?dist ?value WHERE {
17+
?dist a dcat:Distribution ;
18+
dct:license ?value .
19+
}
20+
ORDER BY ?value ?dist
21+
LIMIT 200
22+
}
23+
UNION
24+
{
25+
SELECT ?dist ?value WHERE {
26+
?dist a dcat:Distribution ;
27+
dct:format ?value .
28+
}
29+
ORDER BY ?value ?dist
30+
LIMIT 200
31+
}
32+
}
33+
ORDER BY ?value ?dist
34+
LIMIT 250
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
PREFIX dcat: <http://www.w3.org/ns/dcat#>
8+
PREFIX dc: <http://purl.org/dc/terms/>
9+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
10+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
11+
PREFIX dct: <http://purl.org/dc/terms/>
12+
13+
SELECT ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 where {
14+
15+
?a a ?type2.
16+
?b a ?type1.
17+
18+
?b dcat:dataset ?a.
19+
20+
?a dcat:distribution ?mbox.
21+
?a dct:language ?language.
22+
FILTER (?type1 != ?type2)
23+
?a dct:identifier ?identifier.
24+
25+
BIND(?a as ?c)
26+
27+
{
28+
select distinct ?c (count(?dist) as ?count) ?language2 where {
29+
?c a ?type2.
30+
?c dcat:distribution ?dist.
31+
?c dct:language ?language2.
32+
} group by ?c ?language2 having (?count > 2)
33+
}
34+
35+
} group by ?type1 ?type2 ?language2 ?mbox ?count ?identifier2 order by ?type1 ?type2 ?language2 ?mbox ?count ?identifier2
36+
37+
38+

0 commit comments

Comments
 (0)