Skip to content

Commit

Permalink
optimize sort by date and docid (#3849)
Browse files Browse the repository at this point in the history
* add pre-sorting of splits and some infrastructure for incremential merge

* implement incremental collector

* rewrite leaf_search to allow for incremental merge

* use incremental collector in leaf search

* extract launching split search into a separate function
  • Loading branch information
trinity-1686a authored Oct 4, 2023
1 parent bd8c135 commit 3cc14f0
Show file tree
Hide file tree
Showing 8 changed files with 618 additions and 102 deletions.
3 changes: 3 additions & 0 deletions quickwit/quickwit-common/src/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ where
.collect();
resulting_top_k
}

#[derive(Clone)]
struct OrderItemPair<O: Ord, T> {
order: O,
item: T,
Expand Down Expand Up @@ -124,6 +126,7 @@ pub trait SortKeyMapper<Value> {
}

/// Progressively compute top-k.
#[derive(Clone)]
pub struct TopK<T, O: Ord, S> {
heap: BinaryHeap<Reverse<OrderItemPair<O, T>>>,
sort_key_mapper: S,
Expand Down
30 changes: 30 additions & 0 deletions quickwit/quickwit-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ where T: Debug
}
}

#[inline]
pub const fn div_ceil(lhs: i64, rhs: i64) -> i64 {
let d = lhs / rhs;
let r = lhs % rhs;
if (r > 0 && rhs > 0) || (r < 0 && rhs < 0) {
d + 1
} else {
d
}
}

#[cfg(test)]
mod tests {
use std::io::ErrorKind;
Expand Down Expand Up @@ -231,4 +242,23 @@ mod tests {
let pretty_sample = PrettySample::new(&[1, 2, 3, 4], 2);
assert_eq!(format!("{pretty_sample:?}"), "[1, 2, and 2 more]");
}

#[test]
fn test_div_ceil() {
assert_eq!(div_ceil(5, 1), 5);
assert_eq!(div_ceil(5, 2), 3);
assert_eq!(div_ceil(6, 2), 3);

assert_eq!(div_ceil(-5, 1), -5);
assert_eq!(div_ceil(-5, 2), -2);
assert_eq!(div_ceil(-6, 2), -3);

assert_eq!(div_ceil(5, -1), -5);
assert_eq!(div_ceil(5, -2), -2);
assert_eq!(div_ceil(6, -2), -3);

assert_eq!(div_ceil(-5, -1), 5);
assert_eq!(div_ceil(-5, -2), 3);
assert_eq!(div_ceil(-6, -2), 3);
}
}
11 changes: 11 additions & 0 deletions quickwit/quickwit-proto/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,14 @@ impl PartialOrd for SortValue {
Some(self.cmp(other))
}
}

impl PartialHit {
/// Helper to get access to the 1st sort value
pub fn sort_value(&self) -> Option<SortValue> {
if let Some(sort_value) = self.sort_value {
sort_value.sort_value
} else {
None
}
}
}
Loading

0 comments on commit 3cc14f0

Please sign in to comment.