https://slatedb.io logo
I was going though the SortedRunIterator
# general
s
I was going though the SortedRunIterator and db_state code, I found that we linearly scan SSTs metadata to find intersections. SSTs metadata already has firstKey and SortedRun SSTs are sorted, partitioned and mutually exclusive. Is there a reason we don’t binary_search to pick the SST? Are there correctness or edge‑case constraints that prevent this? Reference code block
Copy code
Rust
fn table_idx_covering_range(&self, range: &BytesRange) -> Range<usize> {
        let mut min_idx = None;
        let mut max_idx = 0;

        for idx in 0..self.ssts.len() {
            let current_sst = &self.ssts[idx];

            let upper_bound = if idx + 1 < self.ssts.len() {
                let next_sst = &self.ssts[idx + 1];
                Excluded(next_sst.compacted_effective_start_key().clone())
            } else {
                Unbounded
            };

            if current_sst.intersects_range(upper_bound, range) {
                if min_idx.is_none() {
                    min_idx = Some(idx);
                }

                max_idx = idx;
            }
        }

        match min_idx {
            Some(min_idx) => min_idx..(max_idx + 1),
            None => 0..0,
        }
    }
c
Honestly, not sure. I'm not super familiar with this code. It's been around a while and gone through some mutations (I think from @dmvk or @jason). But I think a binary search would work. I suspect the thinking was simply that SR lists are pretty short, so doing it linearly made for easier code.