1010 *******************************************************************************/
1111package org .eclipse .rdf4j .sail .lmdb ;
1212
13+ import java .nio .ByteBuffer ;
14+
1315import org .eclipse .rdf4j .common .annotation .InternalUseOnly ;
1416import org .eclipse .rdf4j .common .order .StatementOrder ;
1517import org .eclipse .rdf4j .common .transaction .IsolationLevel ;
2224 */
2325public interface LmdbEvaluationDataset {
2426
27+ @ InternalUseOnly
28+ final class KeyRangeBuffers {
29+ private final ByteBuffer minKey ;
30+ private final ByteBuffer maxKey ;
31+
32+ public KeyRangeBuffers (ByteBuffer minKey , ByteBuffer maxKey ) {
33+ this .minKey = minKey ;
34+ this .maxKey = maxKey ;
35+ }
36+
37+ public static KeyRangeBuffers acquire () {
38+ Pool pool = Pool .get ();
39+ return new KeyRangeBuffers (pool .getKeyBuffer (), pool .getKeyBuffer ());
40+ }
41+
42+ public ByteBuffer minKey () {
43+ return minKey ;
44+ }
45+
46+ public ByteBuffer maxKey () {
47+ return maxKey ;
48+ }
49+ }
50+
2551 /**
2652 * Create a {@link RecordIterator} for the supplied {@link StatementPattern}, taking into account any existing
2753 * bindings.
@@ -33,6 +59,21 @@ public interface LmdbEvaluationDataset {
3359 */
3460 RecordIterator getRecordIterator (StatementPattern pattern , BindingSet bindings ) throws QueryEvaluationException ;
3561
62+ @ InternalUseOnly
63+ default RecordIterator getRecordIterator (StatementPattern pattern , BindingSet bindings , KeyRangeBuffers keyBuffers )
64+ throws QueryEvaluationException {
65+ return getRecordIterator (pattern , bindings );
66+ }
67+
68+ @ InternalUseOnly
69+ default RecordIterator getRecordIterator (StatementPattern pattern , BindingSet bindings , KeyRangeBuffers keyBuffers ,
70+ RecordIterator iteratorReuse ) throws QueryEvaluationException {
71+ if (iteratorReuse != null ) {
72+ iteratorReuse .close ();
73+ }
74+ return getRecordIterator (pattern , bindings , keyBuffers );
75+ }
76+
3677 /**
3778 * Create a {@link RecordIterator} for the supplied pattern, expressed as internal IDs, using the current binding
3879 * snapshot.
@@ -61,6 +102,12 @@ public interface LmdbEvaluationDataset {
61102 RecordIterator getRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex , int ctxIndex ,
62103 long [] patternIds ) throws QueryEvaluationException ;
63104
105+ @ InternalUseOnly
106+ default RecordIterator getRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex , int ctxIndex ,
107+ long [] patternIds , KeyRangeBuffers keyBuffers ) throws QueryEvaluationException {
108+ return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds );
109+ }
110+
64111 /**
65112 * Variant of {@link #getRecordIterator(long[], int, int, int, int, long[])} that allows callers to supply reusable
66113 * scratch buffers. Implementations should treat {@code binding} as read-only and (when {@code bindingReuse} is
@@ -74,26 +121,45 @@ RecordIterator getRecordIterator(long[] binding, int subjIndex, int predIndex, i
74121 @ InternalUseOnly
75122 default RecordIterator getRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex , int ctxIndex ,
76123 long [] patternIds , long [] bindingReuse ) throws QueryEvaluationException {
77- return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , bindingReuse , null );
124+ return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , null , bindingReuse ,
125+ null );
78126 }
79127
80128 @ InternalUseOnly
81129 default RecordIterator getRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex , int ctxIndex ,
82130 long [] patternIds , long [] bindingReuse , long [] quadReuse ) throws QueryEvaluationException {
131+ return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , null , bindingReuse ,
132+ quadReuse );
133+ }
134+
135+ @ InternalUseOnly
136+ default RecordIterator getRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex , int ctxIndex ,
137+ long [] patternIds , KeyRangeBuffers keyBuffers , long [] bindingReuse , long [] quadReuse )
138+ throws QueryEvaluationException {
83139 return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds );
84140 }
85141
142+ @ InternalUseOnly
143+ default RecordIterator getRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex , int ctxIndex ,
144+ long [] patternIds , KeyRangeBuffers keyBuffers , long [] bindingReuse , long [] quadReuse ,
145+ RecordIterator iteratorReuse )
146+ throws QueryEvaluationException {
147+ if (iteratorReuse != null ) {
148+ iteratorReuse .close ();
149+ }
150+ return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , keyBuffers ,
151+ bindingReuse , quadReuse );
152+ }
153+
86154 /**
87155 * Create an ordered {@link RecordIterator} for the supplied pattern expressed via internal IDs and binding indexes.
88156 * Implementations may fall back to the unordered iterator when the requested order is unsupported.
89157 */
90158 @ InternalUseOnly
91159 default RecordIterator getOrderedRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex ,
92160 int ctxIndex , long [] patternIds , StatementOrder order ) throws QueryEvaluationException {
93- if (order == null ) {
94- return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds );
95- }
96- return null ;
161+ return getOrderedRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , order , null ,
162+ null , null );
97163 }
98164
99165 /**
@@ -103,31 +169,54 @@ default RecordIterator getOrderedRecordIterator(long[] binding, int subjIndex, i
103169 @ InternalUseOnly
104170 default RecordIterator getOrderedRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex ,
105171 int ctxIndex , long [] patternIds , StatementOrder order , long [] reuse ) throws QueryEvaluationException {
106- if (order == null ) {
107- return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , reuse , null );
108- }
109- return null ;
172+ return getOrderedRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , order , null ,
173+ reuse , null );
110174 }
111175
112176 @ InternalUseOnly
113177 default RecordIterator getOrderedRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex ,
114178 int ctxIndex , long [] patternIds , StatementOrder order , long [] bindingReuse , long [] quadReuse )
115179 throws QueryEvaluationException {
180+ return getOrderedRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , order , null ,
181+ bindingReuse , quadReuse );
182+ }
183+
184+ @ InternalUseOnly
185+ default RecordIterator getOrderedRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex ,
186+ int ctxIndex , long [] patternIds , StatementOrder order , KeyRangeBuffers keyBuffers , long [] bindingReuse ,
187+ long [] quadReuse ) throws QueryEvaluationException {
116188 if (order == null ) {
117- return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , bindingReuse ,
118- quadReuse );
189+ return getRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , keyBuffers ,
190+ bindingReuse , quadReuse );
119191 }
120192 return null ;
121193 }
122194
195+ @ InternalUseOnly
196+ default RecordIterator getOrderedRecordIterator (long [] binding , int subjIndex , int predIndex , int objIndex ,
197+ int ctxIndex , long [] patternIds , StatementOrder order , KeyRangeBuffers keyBuffers , long [] bindingReuse ,
198+ long [] quadReuse , RecordIterator iteratorReuse ) throws QueryEvaluationException {
199+ if (iteratorReuse != null ) {
200+ iteratorReuse .close ();
201+ }
202+ return getOrderedRecordIterator (binding , subjIndex , predIndex , objIndex , ctxIndex , patternIds , order ,
203+ keyBuffers ,
204+ bindingReuse , quadReuse );
205+ }
206+
123207 /**
124208 * Create an ordered {@link RecordIterator} for the supplied pattern. Implementations may fall back to the unordered
125209 * iterator when the requested order is unsupported.
126210 */
127211 default RecordIterator getOrderedRecordIterator (StatementPattern pattern , BindingSet bindings , StatementOrder order )
128212 throws QueryEvaluationException {
213+ return getOrderedRecordIterator (pattern , bindings , order , null );
214+ }
215+
216+ default RecordIterator getOrderedRecordIterator (StatementPattern pattern , BindingSet bindings , StatementOrder order ,
217+ KeyRangeBuffers keyBuffers ) throws QueryEvaluationException {
129218 if (order == null ) {
130- return getRecordIterator (pattern , bindings );
219+ return getRecordIterator (pattern , bindings , keyBuffers );
131220 }
132221 return null ;
133222 }
@@ -137,6 +226,16 @@ default boolean supportsOrder(long[] binding, int subjIndex, int predIndex, int
137226 return order == null ;
138227 }
139228
229+ /**
230+ * Determine the most suitable LMDB index for the supplied binding pattern.
231+ *
232+ * @return the field sequence of the selected index (e.g. {@code \"spoc\"}), or {@code null} when no advice is
233+ * available
234+ */
235+ default String selectBestIndex (long subj , long pred , long obj , long context ) {
236+ return null ;
237+ }
238+
140239 /**
141240 * @return the {@link ValueStore} backing this dataset.
142241 */
0 commit comments