Skip to content

Commit fbd79ad

Browse files
authored
GH-5447 LMDB Store query performance improvements (#5456)
2 parents 81eab0a + 30e8bc0 commit fbd79ad

68 files changed

Lines changed: 6266 additions & 587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 299 additions & 351 deletions
Large diffs are not rendered by default.

core/collection-factory/api/src/main/java/org/eclipse/rdf4j/collection/factory/impl/DefaultBindingSetKey.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
package org.eclipse.rdf4j.collection.factory.impl;
1313

1414
import java.io.Serializable;
15-
import java.util.Arrays;
1615
import java.util.List;
1716

1817
import org.eclipse.rdf4j.collection.factory.api.BindingSetKey;
@@ -22,12 +21,12 @@ public class DefaultBindingSetKey implements BindingSetKey, Serializable {
2221

2322
private static final long serialVersionUID = 1;
2423

25-
private final Value[] values;
24+
private final List<Value> values;
2625

2726
private final int hash;
2827

2928
public DefaultBindingSetKey(List<Value> values, int hash) {
30-
this.values = values.toArray(new Value[0]);
29+
this.values = values;
3130
this.hash = hash;
3231
}
3332

@@ -39,7 +38,7 @@ public int hashCode() {
3938
@Override
4039
public boolean equals(Object other) {
4140
if (other instanceof DefaultBindingSetKey && other.hashCode() == hash) {
42-
return Arrays.deepEquals(values, ((DefaultBindingSetKey) other).values);
41+
return values.equals(((DefaultBindingSetKey) other).values);
4342
}
4443
return false;
4544
}

core/common/iterator/src/main/java/org/eclipse/rdf4j/common/iteration/CloseableIteration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Iterator;
1515
import java.util.stream.Stream;
1616

17+
import org.eclipse.rdf4j.model.Statement;
18+
1719
/**
1820
* An {@link CloseableIteration} that can be closed to free resources that it is holding. CloseableIterations
1921
* automatically free their resources when exhausted. If not read until exhaustion or if you want to make sure the
@@ -33,6 +35,8 @@
3335
*/
3436
public interface CloseableIteration<E> extends Iterator<E>, AutoCloseable {
3537

38+
EmptyIteration<Statement> EMPTY_STATEMENT_ITERATION = new EmptyIteration<>();
39+
3640
/**
3741
* Convert the results to a Java 8 Stream.
3842
*

core/common/iterator/src/main/java/org/eclipse/rdf4j/common/iteration/DualUnionIteration.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public DualUnionIteration(Comparator<E> cmp,
5050
public static <E> CloseableIteration<? extends E> getWildcardInstance(
5151
CloseableIteration<? extends E> leftIteration, CloseableIteration<? extends E> rightIteration) {
5252

53-
if (rightIteration instanceof EmptyIteration) {
53+
if (leftIteration == EMPTY_STATEMENT_ITERATION) {
54+
return rightIteration;
55+
} else if (rightIteration == EMPTY_STATEMENT_ITERATION) {
56+
return leftIteration;
57+
} else if (rightIteration instanceof EmptyIteration) {
5458
return leftIteration;
5559
} else if (leftIteration instanceof EmptyIteration) {
5660
return rightIteration;
@@ -63,7 +67,11 @@ public static <E> CloseableIteration<? extends E> getWildcardInstance(
6367
public static <E> CloseableIteration<? extends E> getWildcardInstance(Comparator<E> cmp,
6468
CloseableIteration<? extends E> leftIteration, CloseableIteration<? extends E> rightIteration) {
6569

66-
if (rightIteration instanceof EmptyIteration) {
70+
if (leftIteration == EMPTY_STATEMENT_ITERATION) {
71+
return rightIteration;
72+
} else if (rightIteration == EMPTY_STATEMENT_ITERATION) {
73+
return leftIteration;
74+
} else if (rightIteration instanceof EmptyIteration) {
6775
return leftIteration;
6876
} else if (leftIteration instanceof EmptyIteration) {
6977
return rightIteration;
@@ -75,7 +83,11 @@ public static <E> CloseableIteration<? extends E> getWildcardInstance(Comparator
7583
public static <E> CloseableIteration<E> getInstance(CloseableIteration<E> leftIteration,
7684
CloseableIteration<E> rightIteration) {
7785

78-
if (rightIteration instanceof EmptyIteration) {
86+
if (leftIteration == EMPTY_STATEMENT_ITERATION) {
87+
return rightIteration;
88+
} else if (rightIteration == EMPTY_STATEMENT_ITERATION) {
89+
return leftIteration;
90+
} else if (rightIteration instanceof EmptyIteration) {
7991
return leftIteration;
8092
} else if (leftIteration instanceof EmptyIteration) {
8193
return rightIteration;

core/model-api/src/main/java/org/eclipse/rdf4j/model/BNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ default boolean isBNode() {
2727
return true;
2828
}
2929

30+
@Override
31+
default Type getType() {
32+
return Value.Type.BNode;
33+
}
34+
3035
/**
3136
* Retrieves this blank node's identifier.
3237
*

core/model-api/src/main/java/org/eclipse/rdf4j/model/IRI.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ default boolean isIRI() {
3838
return true;
3939
}
4040

41+
@Override
42+
default Type getType() {
43+
return Value.Type.IRI;
44+
}
45+
4146
/**
4247
* Gets the namespace part of this IRI.
4348
* <p>

core/model-api/src/main/java/org/eclipse/rdf4j/model/Literal.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ default boolean isLiteral() {
4747
return true;
4848
}
4949

50+
@Override
51+
default Type getType() {
52+
return Value.Type.Literal;
53+
}
54+
5055
/**
5156
* Gets the label (the lexical value) of this literal.
5257
*

core/model-api/src/main/java/org/eclipse/rdf4j/model/Triple.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ default boolean isTriple() {
3333
return true;
3434
}
3535

36+
@Override
37+
default Type getType() {
38+
return Value.Type.Triple;
39+
}
40+
3641
/**
3742
* Gets the subject of this triple.
3843
*

core/model-api/src/main/java/org/eclipse/rdf4j/model/Value.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
*/
1818
public interface Value extends Serializable {
1919

20+
enum Type {
21+
IRI,
22+
BNode,
23+
Literal,
24+
Triple
25+
}
26+
2027
/**
2128
* Check if the object is an instance of the given type. Typically 2x than using instanceof.
2229
* <p>
@@ -72,6 +79,21 @@ default boolean isTriple() {
7279
return false;
7380
}
7481

82+
default Type getType() {
83+
84+
if (isIRI()) {
85+
return Type.IRI;
86+
} else if (isBNode()) {
87+
return Type.BNode;
88+
} else if (isLiteral()) {
89+
return Type.Literal;
90+
} else if (isTriple()) {
91+
return Type.Triple;
92+
} else {
93+
throw new IllegalStateException("Unknown value type");
94+
}
95+
}
96+
7597
/**
7698
* Returns the String-value of a <var>Value</var> object. This returns either a {@link Literal}'s label, a
7799
* {@link IRI}'s URI or a {@link BNode}'s ID.

core/model-api/src/main/java/org/eclipse/rdf4j/model/ValueFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ public interface ValueFactory {
155155
*/
156156
Literal createLiteral(long value);
157157

158+
/**
159+
* Creates a new typed numerical literal representing the specified value.
160+
*
161+
* @param value The value for the literal.
162+
* @param xsd The XSD datatype to use.
163+
*/
164+
default Literal createLiteral(long value, CoreDatatype.XSD xsd) {
165+
return createLiteral(Long.toString(value), xsd);
166+
}
167+
158168
/**
159169
* Creates a new <var>xsd:float</var>-typed literal representing the specified value.
160170
*

0 commit comments

Comments
 (0)