Skip to content

Commit 3cc14f0

Browse files
optimize sort by date and docid (#3849)
* 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
1 parent bd8c135 commit 3cc14f0

File tree

8 files changed

+618
-102
lines changed

8 files changed

+618
-102
lines changed

quickwit/quickwit-common/src/binary_heap.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ where
9393
.collect();
9494
resulting_top_k
9595
}
96+
97+
#[derive(Clone)]
9698
struct OrderItemPair<O: Ord, T> {
9799
order: O,
98100
item: T,
@@ -124,6 +126,7 @@ pub trait SortKeyMapper<Value> {
124126
}
125127

126128
/// Progressively compute top-k.
129+
#[derive(Clone)]
127130
pub struct TopK<T, O: Ord, S> {
128131
heap: BinaryHeap<Reverse<OrderItemPair<O, T>>>,
129132
sort_key_mapper: S,

quickwit/quickwit-common/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ where T: Debug
176176
}
177177
}
178178

179+
#[inline]
180+
pub const fn div_ceil(lhs: i64, rhs: i64) -> i64 {
181+
let d = lhs / rhs;
182+
let r = lhs % rhs;
183+
if (r > 0 && rhs > 0) || (r < 0 && rhs < 0) {
184+
d + 1
185+
} else {
186+
d
187+
}
188+
}
189+
179190
#[cfg(test)]
180191
mod tests {
181192
use std::io::ErrorKind;
@@ -231,4 +242,23 @@ mod tests {
231242
let pretty_sample = PrettySample::new(&[1, 2, 3, 4], 2);
232243
assert_eq!(format!("{pretty_sample:?}"), "[1, 2, and 2 more]");
233244
}
245+
246+
#[test]
247+
fn test_div_ceil() {
248+
assert_eq!(div_ceil(5, 1), 5);
249+
assert_eq!(div_ceil(5, 2), 3);
250+
assert_eq!(div_ceil(6, 2), 3);
251+
252+
assert_eq!(div_ceil(-5, 1), -5);
253+
assert_eq!(div_ceil(-5, 2), -2);
254+
assert_eq!(div_ceil(-6, 2), -3);
255+
256+
assert_eq!(div_ceil(5, -1), -5);
257+
assert_eq!(div_ceil(5, -2), -2);
258+
assert_eq!(div_ceil(6, -2), -3);
259+
260+
assert_eq!(div_ceil(-5, -1), 5);
261+
assert_eq!(div_ceil(-5, -2), 3);
262+
assert_eq!(div_ceil(-6, -2), 3);
263+
}
234264
}

quickwit/quickwit-proto/src/search/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,14 @@ impl PartialOrd for SortValue {
117117
Some(self.cmp(other))
118118
}
119119
}
120+
121+
impl PartialHit {
122+
/// Helper to get access to the 1st sort value
123+
pub fn sort_value(&self) -> Option<SortValue> {
124+
if let Some(sort_value) = self.sort_value {
125+
sort_value.sort_value
126+
} else {
127+
None
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)