MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / scan_index_values

Method scan_index_values

nodedb/src/engine/sparse/btree_index.rs:346–383  ·  view source on GitHub ↗

Index-only scan: return `(doc_id, field_value)` pairs without touching DOCUMENTS.

(
        &self,
        tenant_id: u64,
        collection: &str,
        field: &str,
        limit: usize,
    )

Source from the content-addressed store, hash-verified

344
345 /// Index-only scan: return `(doc_id, field_value)` pairs without touching DOCUMENTS.
346 pub fn scan_index_values(
347 &self,
348 tenant_id: u64,
349 collection: &str,
350 field: &str,
351 limit: usize,
352 ) -> crate::Result<Vec<(String, String)>> {
353 let prefix = format!("{tenant_id}:{collection}:{field}:");
354 let end = format!("{tenant_id}:{collection}:{field}:\u{ffff}");
355
356 let read_txn = self.db.begin_read().map_err(|e| redb_err("read txn", e))?;
357 let table = read_txn
358 .open_table(INDEXES)
359 .map_err(|e| redb_err("open table", e))?;
360
361 let range = table
362 .range(prefix.as_str()..end.as_str())
363 .map_err(|e| redb_err("index range", e))?;
364
365 let mut results = Vec::with_capacity(limit.min(256));
366 for entry in range {
367 if results.len() >= limit {
368 break;
369 }
370 let entry = entry.map_err(|e| redb_err("index entry", e))?;
371 let key = entry.0.value().to_string();
372 if let Some(rest) = key.strip_prefix(&prefix)
373 && let Some(colon_pos) = rest.rfind(':')
374 {
375 let value = &rest[..colon_pos];
376 let doc_id = &rest[colon_pos + 1..];
377 results.push((doc_id.to_string(), value.to_string()));
378 }
379 }
380
381 debug!(collection, field, count = results.len(), "index-only scan");
382 Ok(results)
383 }
384
385 /// Insert a document by raw pre-formed key (snapshot restore).
386 pub fn put_raw(&self, key: &str, value: &[u8]) -> crate::Result<()> {

Callers

nothing calls this directly

Calls 6

to_stringMethod · 0.80
redb_errFunction · 0.70
rangeMethod · 0.45
as_strMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected