|
@@ -188,15 +188,11 @@ static const uint8_t lookup_ordering_2bound[3][3] = {
|
|
|
static int index_triple(
|
|
|
LSUP_MDBStore *store, StoreOp op, LSUP_TripleKey spok, LSUP_Key ck);
|
|
|
|
|
|
-inline static LSUP_rc lookup_0bound(
|
|
|
- MDBStore *store, MDBIterator *it, size_t *ct);
|
|
|
-inline static LSUP_rc lookup_1bound(
|
|
|
- MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct);
|
|
|
-inline static LSUP_rc lookup_2bound(
|
|
|
- MDBStore *store, uint8_t idx0, uint8_t idx1,
|
|
|
- MDBIterator *it, size_t *ct);
|
|
|
-inline static LSUP_rc lookup_3bound(
|
|
|
- MDBStore *store, MDBIterator *it, size_t *ct);
|
|
|
+inline static LSUP_rc lookup_0bound (MDBIterator *it, size_t *ct);
|
|
|
+inline static LSUP_rc lookup_1bound (uint8_t idx0, MDBIterator *it, size_t *ct);
|
|
|
+inline static LSUP_rc lookup_2bound (
|
|
|
+ uint8_t idx0, uint8_t idx1, MDBIterator *it, size_t *ct);
|
|
|
+inline static LSUP_rc lookup_3bound(MDBIterator *it, size_t *ct);
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -564,7 +560,7 @@ LSUP_mdbstore_lookup(
|
|
|
it->luk[0] = spok[0];
|
|
|
it->luk[1] = spok[1];
|
|
|
it->luk[2] = spok[2];
|
|
|
- RCNL (lookup_3bound (store, it, ct));
|
|
|
+ RCNL (lookup_3bound (it, ct));
|
|
|
|
|
|
} else if (spok[0] != NULL_KEY) {
|
|
|
it->luk[0] = spok[0];
|
|
@@ -574,16 +570,16 @@ LSUP_mdbstore_lookup(
|
|
|
if (spok[1] != NULL_KEY) {
|
|
|
it->luk[1] = spok[1];
|
|
|
idx1 = 1;
|
|
|
- RCNL (lookup_2bound (store, idx0, idx1, it, ct));
|
|
|
+ RCNL (lookup_2bound (idx0, idx1, it, ct));
|
|
|
|
|
|
// s ? o
|
|
|
} else if (spok[2] != NULL_KEY) {
|
|
|
it->luk[1] = spok[2];
|
|
|
idx1 = 2;
|
|
|
- RCNL (lookup_2bound (store, idx0, idx1, it, ct));
|
|
|
+ RCNL (lookup_2bound (idx0, idx1, it, ct));
|
|
|
|
|
|
// s ? ?
|
|
|
- } else RCNL (lookup_1bound (store, idx0, it, ct));
|
|
|
+ } else RCNL (lookup_1bound (idx0, it, ct));
|
|
|
|
|
|
} else if (spok[1] != NULL_KEY) {
|
|
|
it->luk[0] = spok[1];
|
|
@@ -593,19 +589,19 @@ LSUP_mdbstore_lookup(
|
|
|
if (spok[2] != NULL_KEY) {
|
|
|
it->luk[1] = spok[2];
|
|
|
idx1 = 2;
|
|
|
- RCNL (lookup_2bound (store, idx0, idx1, it, ct));
|
|
|
+ RCNL (lookup_2bound (idx0, idx1, it, ct));
|
|
|
|
|
|
// ? p ?
|
|
|
- } else RCNL (lookup_1bound (store, idx0, it, ct));
|
|
|
+ } else RCNL (lookup_1bound (idx0, it, ct));
|
|
|
|
|
|
// ? ? o
|
|
|
} else if (spok[2] != NULL_KEY) {
|
|
|
it->luk[0] = spok[2];
|
|
|
idx0 = 2;
|
|
|
- RCNL (lookup_1bound (store, idx0, it, ct));
|
|
|
+ RCNL (lookup_1bound (idx0, it, ct));
|
|
|
|
|
|
// ? ? ? (all terms unbound)
|
|
|
- } else RCNL (lookup_0bound (store, it, ct));
|
|
|
+ } else RCNL (lookup_0bound (it, ct));
|
|
|
|
|
|
return it;
|
|
|
}
|
|
@@ -1042,11 +1038,11 @@ it_next_3bound (MDBIterator *it)
|
|
|
/* * * Term-specific lookups. * * */
|
|
|
|
|
|
inline static LSUP_rc
|
|
|
-lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
+lookup_0bound (MDBIterator *it, size_t *ct)
|
|
|
{
|
|
|
- if (store->txn) it->txn = store->txn;
|
|
|
+ if (it->store->txn) it->txn = it->store->txn;
|
|
|
else {
|
|
|
- it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
+ it->rc = mdb_txn_begin (it->store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
if (it->rc != MDB_SUCCESS) {
|
|
|
fprintf (
|
|
|
stderr, "%s:%d [%s]: Database error: %s\n",
|
|
@@ -1058,7 +1054,8 @@ lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
if (ct) {
|
|
|
if (it->ck != NULL_KEY) {
|
|
|
// Look up by given context.
|
|
|
- it->rc = mdb_cursor_open (it->txn, store->dbi[IDX_C_SPO], &it->cur);
|
|
|
+ it->rc = mdb_cursor_open (
|
|
|
+ it->txn, it->store->dbi[IDX_C_SPO], &it->cur);
|
|
|
|
|
|
it->key.mv_data = &it->ck;
|
|
|
it->key.mv_size = KLEN;
|
|
@@ -1072,14 +1069,14 @@ lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
} else {
|
|
|
// Look up all contexts.
|
|
|
MDB_stat stat;
|
|
|
- mdb_stat (it->txn, store->dbi[IDX_S_PO], &stat);
|
|
|
+ mdb_stat (it->txn, it->store->dbi[IDX_S_PO], &stat);
|
|
|
|
|
|
*ct = stat.ms_entries;
|
|
|
}
|
|
|
TRACE ("Found %lu keys.", *ct);
|
|
|
}
|
|
|
|
|
|
- mdb_cursor_open (it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
|
+ mdb_cursor_open (it->txn, it->store->dbi[IDX_SPO_C], &it->cur);
|
|
|
|
|
|
it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_FIRST);
|
|
|
mdb_cursor_close (it->cur);
|
|
@@ -1099,16 +1096,17 @@ lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
|
|
|
inline static LSUP_rc
|
|
|
-lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
+lookup_1bound (uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
{
|
|
|
it->term_order = (const uint8_t*)lookup_ordering_1bound[idx0];
|
|
|
|
|
|
TRACE ("Looking up 1 bound term: %lx\n", it->luk[0]);
|
|
|
|
|
|
if (!it->txn) {
|
|
|
- if (store->txn) it->txn = store->txn;
|
|
|
+ if (it->store->txn) it->txn = it->store->txn;
|
|
|
else {
|
|
|
- it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
+ it->rc = mdb_txn_begin (
|
|
|
+ it->store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
if (it->rc != MDB_SUCCESS) {
|
|
|
fprintf (
|
|
|
stderr, "%s:%d [%s]: Database error: %s",
|
|
@@ -1118,7 +1116,7 @@ lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- mdb_cursor_open (it->txn, store->dbi[lookup_indices[idx0]], &it->cur);
|
|
|
+ mdb_cursor_open (it->txn, it->store->dbi[lookup_indices[idx0]], &it->cur);
|
|
|
|
|
|
it->key.mv_data = it->luk;
|
|
|
it->key.mv_size = KLEN;
|
|
@@ -1143,7 +1141,7 @@ lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
ct_it->data = it->data;
|
|
|
ct_it->i = 0;
|
|
|
|
|
|
- LSUP_rc rc = lookup_1bound (store, idx0, ct_it, NULL);
|
|
|
+ LSUP_rc rc = lookup_1bound (idx0, ct_it, NULL);
|
|
|
if (rc < 0) return rc;
|
|
|
|
|
|
while (LSUP_mdbiter_next (ct_it, NULL) != LSUP_END) {
|
|
@@ -1180,9 +1178,7 @@ lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
|
|
|
inline static LSUP_rc
|
|
|
-lookup_2bound(
|
|
|
- MDBStore *store, uint8_t idx0, uint8_t idx1,
|
|
|
- MDBIterator *it, size_t *ct)
|
|
|
+lookup_2bound(uint8_t idx0, uint8_t idx1, MDBIterator *it, size_t *ct)
|
|
|
{
|
|
|
uint8_t luk1_offset, luk2_offset;
|
|
|
MDB_dbi dbi = 0;
|
|
@@ -1206,7 +1202,7 @@ lookup_2bound(
|
|
|
luk1_offset = 1;
|
|
|
luk2_offset = 0;
|
|
|
}
|
|
|
- dbi = store->dbi[lookup_indices[i + 3]];
|
|
|
+ dbi = it->store->dbi[lookup_indices[i + 3]];
|
|
|
TRACE(
|
|
|
"Looking up 2 bound in %s\n",
|
|
|
db_labels[lookup_indices[i + 3]]);
|
|
@@ -1228,9 +1224,10 @@ lookup_2bound(
|
|
|
luk[luk2_offset] = it->luk[1];
|
|
|
|
|
|
if (!it->txn) {
|
|
|
- if (store->txn) it->txn = store->txn;
|
|
|
+ if (it->store->txn) it->txn = it->store->txn;
|
|
|
else {
|
|
|
- it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
+ it->rc = mdb_txn_begin (
|
|
|
+ it->store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
if (it->rc != MDB_SUCCESS) {
|
|
|
fprintf (
|
|
|
stderr, "%s:%d [%s]: Database error: %s",
|
|
@@ -1262,7 +1259,7 @@ lookup_2bound(
|
|
|
ct_it->ck = it->ck;
|
|
|
ct_it->store = it->store;
|
|
|
ct_it->txn = it->txn;
|
|
|
- lookup_2bound (store, idx0, idx1, ct_it, NULL);
|
|
|
+ lookup_2bound (idx0, idx1, ct_it, NULL);
|
|
|
|
|
|
while (LSUP_mdbiter_next (ct_it, NULL) != LSUP_END) {
|
|
|
ct[0] ++;
|
|
@@ -1297,15 +1294,15 @@ lookup_2bound(
|
|
|
|
|
|
|
|
|
inline static LSUP_rc
|
|
|
-lookup_3bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
+lookup_3bound (MDBIterator *it, size_t *ct)
|
|
|
{
|
|
|
TRACE(
|
|
|
"Looking up 3 bound: {%lx, %lx, %lx}",
|
|
|
it->luk[0], it->luk[1], it->luk[2]);
|
|
|
|
|
|
- if (store->txn) it->txn = store->txn;
|
|
|
+ if (it->store->txn) it->txn = it->store->txn;
|
|
|
else {
|
|
|
- it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
+ it->rc = mdb_txn_begin (it->store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
if (it->rc != MDB_SUCCESS) {
|
|
|
fprintf (
|
|
|
stderr, "%s:%d [%s]: Database error: %s\n",
|
|
@@ -1317,14 +1314,15 @@ lookup_3bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
it->key.mv_data = it->luk;
|
|
|
|
|
|
if (it->ck != NULL_KEY) {
|
|
|
- it->rc = mdb_cursor_open (it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
|
+ it->rc = mdb_cursor_open (
|
|
|
+ it->txn, it->store->dbi[IDX_SPO_C], &it->cur);
|
|
|
|
|
|
it->key.mv_size = TRP_KLEN;
|
|
|
it->data.mv_data = &it->ck;
|
|
|
it->data.mv_size = KLEN;
|
|
|
|
|
|
} else {
|
|
|
- it->rc = mdb_cursor_open (it->txn, store->dbi[IDX_S_PO], &it->cur);
|
|
|
+ it->rc = mdb_cursor_open (it->txn, it->store->dbi[IDX_S_PO], &it->cur);
|
|
|
|
|
|
it->key.mv_size = KLEN;
|
|
|
it->data.mv_data = it->luk + 1;
|