Skip to content

Commit 5dfe593

Browse files
committed
Introduce configurable split position for triple indexes.
1 parent f29017d commit 5dfe593

File tree

8 files changed

+393
-133
lines changed

8 files changed

+393
-133
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*******************************************************************************/
1111
package org.eclipse.rdf4j.sail.lmdb;
1212

13-
import static org.eclipse.rdf4j.sail.lmdb.LmdbUtil.E;
1413
import static org.lwjgl.util.lmdb.LMDB.MDB_FIRST;
1514
import static org.lwjgl.util.lmdb.LMDB.MDB_FIRST_DUP;
1615
import static org.lwjgl.util.lmdb.LMDB.MDB_GET_BOTH_RANGE;
@@ -22,7 +21,6 @@
2221
import static org.lwjgl.util.lmdb.LMDB.mdb_cmp;
2322
import static org.lwjgl.util.lmdb.LMDB.mdb_cursor_close;
2423
import static org.lwjgl.util.lmdb.LMDB.mdb_cursor_get;
25-
import static org.lwjgl.util.lmdb.LMDB.mdb_cursor_open;
2624
import static org.lwjgl.util.lmdb.LMDB.mdb_cursor_renew;
2725
import static org.lwjgl.util.lmdb.LMDB.mdb_dcmp;
2826

@@ -34,8 +32,6 @@
3432
import org.eclipse.rdf4j.sail.lmdb.TripleStore.TripleIndex;
3533
import org.eclipse.rdf4j.sail.lmdb.TxnManager.Txn;
3634
import org.eclipse.rdf4j.sail.lmdb.util.EntryMatcher;
37-
import org.lwjgl.PointerBuffer;
38-
import org.lwjgl.system.MemoryStack;
3935
import org.lwjgl.system.MemoryUtil;
4036
import org.lwjgl.util.lmdb.MDBVal;
4137
import org.slf4j.Logger;
@@ -72,13 +68,13 @@ static class State {
7268

7369
private final MDBVal valueData = MDBVal.malloc();
7470

75-
private final ByteBuffer minKeyBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 2);
71+
private final ByteBuffer minKeyBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 4);
7672

77-
private final ByteBuffer minValueBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 2);
73+
private final ByteBuffer minValueBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 4);
7874

79-
private final ByteBuffer maxKeyBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 2);
75+
private final ByteBuffer maxKeyBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 4);
8076

81-
private final ByteBuffer maxValueBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 2);
77+
private final ByteBuffer maxValueBuf = MemoryUtil.memAlloc((Long.BYTES + 1) * 4);
8278

8379
private long[] quad;
8480
private long[] patternQuad;
@@ -105,6 +101,7 @@ void close() {
105101

106102
private final Thread ownerThread = Thread.currentThread();
107103
private final State state;
104+
private final boolean keyELementsFixed;
108105
private volatile boolean closed = false;
109106
private boolean fetchNext = false;
110107

@@ -115,6 +112,8 @@ void close() {
115112
this.state.quad = new long[] { subj, pred, obj, context };
116113
this.state.index = index;
117114
this.state.indexScore = indexScore;
115+
this.keyELementsFixed = indexScore >= index.getIndexSplitPosition();
116+
118117
// prepare min and max keys if index can be used
119118
// otherwise, leave as null to indicate full scan
120119
if (indexScore > 0) {
@@ -217,15 +216,15 @@ public long[] next() {
217216
// set cursor to min key
218217
state.keyData.mv_data(state.minKeyBuf);
219218
// set range on key is only required if less than the first two key elements are fixed
220-
lastResult = state.indexScore >= 2 ? MDB_SUCCESS
219+
lastResult = keyELementsFixed ? MDB_SUCCESS
221220
: mdb_cursor_get(state.cursor, state.keyData, state.valueData, MDB_SET_RANGE);
222221
if (lastResult == MDB_SUCCESS) {
223222
state.valueData.mv_data(state.minValueBuf);
224223
lastResult = mdb_cursor_get(state.cursor, state.keyData, state.valueData, MDB_GET_BOTH_RANGE);
225224
if (lastResult != MDB_SUCCESS) {
226225
lastResult = mdb_cursor_get(state.cursor, state.keyData, state.valueData, MDB_FIRST_DUP);
227226
} else {
228-
isDupValue = state.indexScore >= 2;
227+
isDupValue = keyELementsFixed;
229228
}
230229
}
231230
} else {

0 commit comments

Comments
 (0)