Skip to content

Commit 19b9ec5

Browse files
committed
working on new ID based join iterator
1 parent 4007b2b commit 19b9ec5

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/LmdbRecordIterator.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.eclipse.rdf4j.common.concurrent.locks.StampedLongAdderLockManager;
2929
import org.eclipse.rdf4j.sail.SailException;
30+
import org.eclipse.rdf4j.sail.lmdb.TripleStore.KeyBuilder;
3031
import org.eclipse.rdf4j.sail.lmdb.TripleStore.TripleIndex;
3132
import org.eclipse.rdf4j.sail.lmdb.TxnManager.Txn;
3233
import org.eclipse.rdf4j.sail.lmdb.util.GroupMatcher;
@@ -95,6 +96,11 @@ class LmdbRecordIterator implements RecordIterator {
9596

9697
LmdbRecordIterator(TripleIndex index, boolean rangeSearch, long subj, long pred, long obj,
9798
long context, boolean explicit, Txn txnRef) throws IOException {
99+
this(index, null, rangeSearch, subj, pred, obj, context, explicit, txnRef);
100+
}
101+
102+
LmdbRecordIterator(TripleIndex index, KeyBuilder keyBuilder, boolean rangeSearch, long subj,
103+
long pred, long obj, long context, boolean explicit, Txn txnRef) throws IOException {
98104
this.subj = subj;
99105
this.pred = pred;
100106
this.obj = obj;
@@ -107,14 +113,25 @@ class LmdbRecordIterator implements RecordIterator {
107113
this.index = index;
108114
if (rangeSearch) {
109115
minKeyBuf = pool.getKeyBuffer();
110-
index.getMinKey(minKeyBuf, subj, pred, obj, context);
116+
if (keyBuilder != null) {
117+
minKeyBuf.clear();
118+
keyBuilder.writeMin(minKeyBuf);
119+
} else {
120+
index.getMinKey(minKeyBuf, subj, pred, obj, context);
121+
}
111122
minKeyBuf.flip();
112123

113124
this.maxKey = pool.getVal();
114125
this.maxKeyBuf = pool.getKeyBuffer();
115-
index.getMaxKey(maxKeyBuf, subj, pred, obj, context);
126+
if (keyBuilder != null) {
127+
maxKeyBuf.clear();
128+
keyBuilder.writeMax(maxKeyBuf);
129+
} else {
130+
index.getMaxKey(maxKeyBuf, subj, pred, obj, context);
131+
}
116132
maxKeyBuf.flip();
117133
this.maxKey.mv_data(maxKeyBuf);
134+
118135
} else {
119136
// Even when we can't bound with a prefix (no rangeSearch), we can still
120137
// position the cursor closer to the first potentially matching key when
@@ -128,6 +145,7 @@ class LmdbRecordIterator implements RecordIterator {
128145
minKeyBuf = null;
129146
}
130147
this.maxKey = null;
148+
this.maxKeyBuf = null;
131149
}
132150

133151
this.matchValues = subj > 0 || pred > 0 || obj > 0 || context >= 0;

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/LmdbSailStore.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,13 @@ public CloseableIteration<? extends Statement> getStatements(StatementOrder stat
12421242
}
12431243

12441244
boolean rangeSearch = chosen.getPatternScore(subjID, predID, objID, contextID) > 0;
1245-
RecordIterator records = new LmdbRecordIterator(chosen, rangeSearch, subjID, predID, objID, contextID,
1246-
explicit, txn);
1245+
TripleStore.KeyBuilder keyBuilder = rangeSearch
1246+
? chosen.keyBuilder(subjID, predID, objID, contextID)
1247+
: null;
1248+
RecordIterator records = keyBuilder != null
1249+
? new LmdbRecordIterator(chosen, keyBuilder, rangeSearch, subjID, predID, objID, contextID,
1250+
explicit, txn)
1251+
: new LmdbRecordIterator(chosen, rangeSearch, subjID, predID, objID, contextID, explicit, txn);
12471252

12481253
boolean sBound = subj != null;
12491254
boolean pBound = pred != null;

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/TripleStore.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,12 @@ interface DupIndex {
15711571
int getPatternScore(long subj, long pred, long obj, long context);
15721572
}
15731573

1574+
interface KeyBuilder {
1575+
void writeMin(ByteBuffer buffer);
1576+
1577+
void writeMax(ByteBuffer buffer);
1578+
}
1579+
15741580
@FunctionalInterface
15751581
private interface PatternScoreFunction {
15761582
int score(long subj, long pred, long obj, long context);
@@ -1741,6 +1747,21 @@ public int getPatternScore(long subj, long pred, long obj, long context) {
17411747
return patternScoreFunction.score(subj, pred, obj, context);
17421748
}
17431749

1750+
KeyBuilder keyBuilder(long subj, long pred, long obj, long context) {
1751+
return new KeyBuilder() {
1752+
1753+
@Override
1754+
public void writeMin(ByteBuffer buffer) {
1755+
getMinKey(buffer, subj, pred, obj, context);
1756+
}
1757+
1758+
@Override
1759+
public void writeMax(ByteBuffer buffer) {
1760+
getMaxKey(buffer, subj, pred, obj, context);
1761+
}
1762+
};
1763+
}
1764+
17441765
void getMinKey(ByteBuffer bb, long subj, long pred, long obj, long context) {
17451766
subj = subj <= 0 ? 0 : subj;
17461767
pred = pred <= 0 ? 0 : pred;

0 commit comments

Comments
 (0)