Skip to content

Commit 17395e8

Browse files
committed
working on new ID based join iterator
1 parent 46974b1 commit 17395e8

File tree

5 files changed

+270
-181
lines changed

5 files changed

+270
-181
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ private void initializeInternal(TripleIndex index, KeyBuilder keyBuilder, boolea
150150
// }
151151

152152
this.index = index;
153-
long prevSubj = this.subj;
154-
long prevPred = this.pred;
155-
long prevObj = this.obj;
156-
long prevContext = this.context;
153+
long prevSubj = minKeyBuf != null ? this.subj : TripleStore.NO_PREVIOUS_ID;
154+
long prevPred = minKeyBuf != null ? this.pred : TripleStore.NO_PREVIOUS_ID;
155+
long prevObj = minKeyBuf != null ? this.obj : TripleStore.NO_PREVIOUS_ID;
156+
long prevContext = minKeyBuf != null ? this.context : TripleStore.NO_PREVIOUS_ID;
157157

158158
this.subj = subj;
159159
this.pred = pred;

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public class TripleStore implements Closeable {
123123
public static final int CONTEXT_IDX = 3;
124124

125125
static final int MAX_KEY_LENGTH = 4 * 9;
126+
static final long NO_PREVIOUS_ID = Long.MIN_VALUE;
126127

127128
/**
128129
* The default triple indexes.
@@ -812,7 +813,8 @@ protected void filterUsedIds(Collection<Long> ids) throws IOException {
812813
maxKey.mv_data(maxKeyBuf);
813814

814815
keyBuf.clear();
815-
index.getMinKey(keyBuf, subj, pred, obj, context, 0, 0, 0, 0);
816+
index.getMinKey(keyBuf, subj, pred, obj, context, NO_PREVIOUS_ID, NO_PREVIOUS_ID,
817+
NO_PREVIOUS_ID, NO_PREVIOUS_ID);
816818
keyBuf.flip();
817819

818820
// set cursor to min key
@@ -918,7 +920,8 @@ private double estimateWithTransaction(Pool pool, Statistics statistics, MemoryS
918920
statistics.reset();
919921

920922
keyBuf.clear();
921-
index.getMinKey(keyBuf, subj, pred, obj, context, 0, 0, 0, 0);
923+
index.getMinKey(keyBuf, subj, pred, obj, context, NO_PREVIOUS_ID, NO_PREVIOUS_ID, NO_PREVIOUS_ID,
924+
NO_PREVIOUS_ID);
922925
keyBuf.flip();
923926

924927
int dbi = index.getDB(explicit);
@@ -1888,7 +1891,8 @@ KeyBuilder keyBuilder(long subj, long pred, long obj, long context) {
18881891

18891892
@Override
18901893
public void writeMin(ByteBuffer buffer) {
1891-
getMinKey(buffer, subj, pred, obj, context, 0, 0, 0, 0);
1894+
getMinKey(buffer, subj, pred, obj, context, NO_PREVIOUS_ID, NO_PREVIOUS_ID, NO_PREVIOUS_ID,
1895+
NO_PREVIOUS_ID);
18921896
}
18931897

18941898
@Override
@@ -1904,7 +1908,12 @@ void getMinKey(ByteBuffer bb, long subj, long pred, long obj, long context, long
19041908
pred = pred <= 0 ? 0 : pred;
19051909
obj = obj <= 0 ? 0 : obj;
19061910
context = context <= 0 ? 0 : context;
1907-
toKey(bb, subj, pred, obj, context);
1911+
long prevSubjNorm = prevSubj == NO_PREVIOUS_ID ? NO_PREVIOUS_ID : (prevSubj <= 0 ? 0 : prevSubj);
1912+
long prevPredNorm = prevPred == NO_PREVIOUS_ID ? NO_PREVIOUS_ID : (prevPred <= 0 ? 0 : prevPred);
1913+
long prevObjNorm = prevObj == NO_PREVIOUS_ID ? NO_PREVIOUS_ID : (prevObj <= 0 ? 0 : prevObj);
1914+
long prevContextNorm = prevContext == NO_PREVIOUS_ID ? NO_PREVIOUS_ID
1915+
: (prevContext <= 0 ? 0 : prevContext);
1916+
toKey(bb, subj, pred, obj, context, prevSubjNorm, prevPredNorm, prevObjNorm, prevContextNorm);
19081917
}
19091918

19101919
void getMaxKey(ByteBuffer bb, long subj, long pred, long obj, long context) {
@@ -1996,6 +2005,11 @@ public void print() {
19962005
}
19972006

19982007
void toKey(ByteBuffer bb, long subj, long pred, long obj, long context) {
2008+
toKey(bb, subj, pred, obj, context, NO_PREVIOUS_ID, NO_PREVIOUS_ID, NO_PREVIOUS_ID, NO_PREVIOUS_ID);
2009+
}
2010+
2011+
void toKey(ByteBuffer bb, long subj, long pred, long obj, long context, long prevSubj, long prevPred,
2012+
long prevObj, long prevContext) {
19992013

20002014
boolean shouldCache = threeOfFourAreZeroOrMax(subj, pred, obj, context);
20012015
if (shouldCache) {
@@ -2012,7 +2026,9 @@ void toKey(ByteBuffer bb, long subj, long pred, long obj, long context) {
20122026
}
20132027

20142028
// Pass through to the keyWriter with caching hint
2015-
keyWriter.write(bb, subj, pred, obj, context, shouldCache);
2029+
boolean hasPrev = prevSubj != NO_PREVIOUS_ID;
2030+
keyWriter.write(bb, subj, pred, obj, context, shouldCache, hasPrev, prevSubj, prevPred, prevObj,
2031+
prevContext);
20162032
}
20172033

20182034
void keyToQuad(ByteBuffer key, long[] quad) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ public static int calcListLengthUnsigned(long a, long b, long c, long d) {
246246
return calcLengthUnsigned(a) + calcLengthUnsigned(b) + calcLengthUnsigned(c) + calcLengthUnsigned(d);
247247
}
248248

249+
/**
250+
* Advances the {@link ByteBuffer#position()} by the number of bytes required to encode the supplied value using the
251+
* unsigned variable-length format, without writing any data. This assumes the buffer already contains the encoded
252+
* representation at the current position.
253+
*
254+
* @param bb buffer whose position should be advanced
255+
* @param value value whose encoded length should be skipped
256+
*/
257+
public static void advanceUnsigned(ByteBuffer bb, long value) {
258+
bb.position(bb.position() + calcLengthUnsigned(value));
259+
}
260+
249261
/**
250262
* The number of bytes required to represent the given number minus one. The descriptor can be encoded in 3 bits.
251263
*

0 commit comments

Comments
 (0)