1010 *******************************************************************************/
1111package org .eclipse .rdf4j .sail .lmdb ;
1212
13- import static org .eclipse .rdf4j .sail .lmdb .LmdbUtil .E ;
1413import static org .lwjgl .util .lmdb .LMDB .MDB_FIRST ;
1514import static org .lwjgl .util .lmdb .LMDB .MDB_FIRST_DUP ;
1615import static org .lwjgl .util .lmdb .LMDB .MDB_GET_BOTH_RANGE ;
2221import static org .lwjgl .util .lmdb .LMDB .mdb_cmp ;
2322import static org .lwjgl .util .lmdb .LMDB .mdb_cursor_close ;
2423import static org .lwjgl .util .lmdb .LMDB .mdb_cursor_get ;
25- import static org .lwjgl .util .lmdb .LMDB .mdb_cursor_open ;
2624import static org .lwjgl .util .lmdb .LMDB .mdb_cursor_renew ;
2725import static org .lwjgl .util .lmdb .LMDB .mdb_dcmp ;
2826
3432import org .eclipse .rdf4j .sail .lmdb .TripleStore .TripleIndex ;
3533import org .eclipse .rdf4j .sail .lmdb .TxnManager .Txn ;
3634import org .eclipse .rdf4j .sail .lmdb .util .EntryMatcher ;
37- import org .lwjgl .PointerBuffer ;
38- import org .lwjgl .system .MemoryStack ;
3935import org .lwjgl .system .MemoryUtil ;
4036import org .lwjgl .util .lmdb .MDBVal ;
4137import 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