Skip to content

Commit c14d975

Browse files
committed
feat: add early prefix check in inverse queries
Before parsing each key, verify that it still matches the seek prefix. This avoids iterating through keys that are lexicographically close but cannot match. This significantly improves performance for queries for non-existent prefixes that have many shorter prefix matches in the database.
1 parent 857b5f8 commit c14d975

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

backend/balboa-rocksdb/rocksdb-impl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// balboa
2-
// Copyright (c) 2018, 2019 DCSO GmbH
2+
// Copyright (c) 2018, 2026 DCSO GmbH
33

44
#include <stdio.h>
55
#include <stdlib.h>
@@ -467,6 +467,10 @@ static int blb_rocksdb_query_by_i(
467467
keys_visited += 1;
468468
size_t key_len = 0;
469469
const char* key = rocksdb_iter_key(it, &key_len);
470+
if(key_len < prefix_len
471+
|| memcmp(key, dbc->scrtch_inv, prefix_len) != 0) {
472+
break;
473+
}
470474
char* err = NULL;
471475

472476
enum TokIdx { RDATA = 3, SENSORID = 2, RRNAME = 1, RRTYPE = 0, FIELDS = 4 };

0 commit comments

Comments
 (0)