Skip to content

Commit 37cb363

Browse files
committed
GH-4950 LMDB: extensible ID scheme
Implement an extensible ID scheme for the LmdbStore that also allows to embed values into IDs.
1 parent db88aa5 commit 37cb363

File tree

16 files changed

+1483
-122
lines changed

16 files changed

+1483
-122
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,18 @@ protected void filterUsedIds(Collection<Long> ids) throws IOException {
605605
it.remove();
606606
continue;
607607
}
608-
if (component != 2 && (id & 1) == 1) {
609-
// id is a literal and can only appear in object position
610-
continue;
608+
if (component != 2) {
609+
// optimization: ensure that literals are only tested if they appear in object
610+
// position
611+
switch (ValueIds.getIdType(id)) {
612+
case ValueIds.T_URI:
613+
case ValueIds.T_BNODE:
614+
case ValueIds.T_TRIPLE:
615+
// fall through
616+
default:
617+
// id is a literal, do not test it
618+
continue;
619+
}
611620
}
612621

613622
long subj = c == 0 ? id : -1, pred = c == 1 ? id : -1,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*******************************************************************************/
11+
package org.eclipse.rdf4j.sail.lmdb;
12+
13+
/**
14+
* Constants and functions for working with ids encoded into long values.
15+
*/
16+
public class ValueIds {
17+
/**
18+
* Pointer to an arbitrary value in the value store. This is not used as RDF value.
19+
*/
20+
public static final int T_PTR = 0;
21+
22+
/** Reference to a URI */
23+
public static final int T_URI = 1;
24+
/** Reference to a literal */
25+
public static final int T_LITERAL = 2;
26+
/** Reference to a blank node */
27+
public static final int T_BNODE = 3;
28+
/** Reference to a triple */
29+
public static final int T_TRIPLE = 4;
30+
31+
// inlined values
32+
public static final int T_INTEGER = 16;
33+
public static final int T_DECIMAL = 17;
34+
public static final int T_FLOAT = 18;
35+
public static final int T_DATETIME = 19;
36+
public static final int T_DATETIMESTAMP = 20;
37+
public static final int T_DATE = 21;
38+
public static final int T_BOOLEAN = 22;
39+
public static final int T_SHORTSTRING = 23;
40+
public static final int T_POSITIVE_INTEGER = 24;
41+
public static final int T_NEGATIVE_INTEGER = 25;
42+
public static final int T_NON_NEGATIVE_INTEGER = 26;
43+
public static final int T_NON_POSITIVE_INTEGER = 27;
44+
public static final int T_LONG = 28;
45+
public static final int T_INT = 29;
46+
public static final int T_SHORT = 30;
47+
public static final int T_BYTE = 31;
48+
public static final int T_UNSIGNEDLONG = 32;
49+
public static final int T_UNSIGNEDINT = 33;
50+
public static final int T_UNSIGNEDSHORT = 34;
51+
public static final int T_UNSIGNEDBYTE = 35;
52+
53+
/**
54+
* Returns the type section of the given id.
55+
*
56+
* @param id The id of which the type should be extracted.
57+
* @return The id's type.
58+
*/
59+
public static int getIdType(long id) {
60+
return (int) ((id >> 1) & 0x3F);
61+
}
62+
63+
/**
64+
* Returns the value section of the given id.
65+
*
66+
* @param id The id of which the value should be extracted.
67+
* @return The id's value.
68+
*/
69+
public static long getValue(long id) {
70+
return id >> 7;
71+
}
72+
73+
/**
74+
* Combines an id type and a value into a single long id.
75+
*
76+
* @param idType The id's type.
77+
* @param value The id's value.
78+
* @return A composite id.
79+
*/
80+
public static long createId(int idType, long value) {
81+
return value << 7 | idType << 1;
82+
}
83+
}

0 commit comments

Comments
 (0)