Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ impl<S: Storage> State<S> {
NormalizationRuleImpl::CombineFilter,
],
)
.batch(
"TopK".to_string(),
HepBatchStrategy::once_topdown(),
vec![NormalizationRuleImpl::TopK],
)
.batch(
"Expression Remapper".to_string(),
HepBatchStrategy::once_topdown(),
Expand All @@ -249,6 +254,7 @@ impl<S: Storage> State<S> {
ImplementationRuleImpl::IndexScan,
ImplementationRuleImpl::FunctionScan,
ImplementationRuleImpl::Sort,
ImplementationRuleImpl::TopK,
ImplementationRuleImpl::Values,
// DML
ImplementationRuleImpl::Analyze,
Expand Down
1 change: 1 addition & 0 deletions src/execution/dql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) mod seq_scan;
pub(crate) mod show_table;
pub(crate) mod show_view;
pub(crate) mod sort;
pub(crate) mod top_k;
pub(crate) mod union;
pub(crate) mod values;

Expand Down
28 changes: 19 additions & 9 deletions src/execution/dql/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::pin::Pin;
pub(crate) type BumpVec<'bump, T> = bumpalo::collections::Vec<'bump, T>;

#[derive(Clone)]
pub(crate) struct NullableVec<'a, T>(BumpVec<'a, Option<T>>);
pub(crate) struct NullableVec<'a, T>(pub(crate) BumpVec<'a, Option<T>>);

impl<'a, T> NullableVec<'a, T> {
#[inline]
Expand Down Expand Up @@ -49,17 +49,31 @@ impl<'a, T> NullableVec<'a, T> {
}
}

struct RemappingIterator<'a> {
pub struct RemappingIterator<'a> {
pos: usize,
tuples: NullableVec<'a, (usize, Tuple)>,
indices: BumpVec<'a, usize>,
}

impl RemappingIterator<'_> {
pub fn new<'a>(
pos: usize,
tuples: NullableVec<'a, (usize, Tuple)>,
indices: BumpVec<'a, usize>,
) -> RemappingIterator<'a> {
RemappingIterator {
pos,
tuples,
indices,
}
}
}

impl Iterator for RemappingIterator<'_> {
type Item = Tuple;

fn next(&mut self) -> Option<Self::Item> {
if self.pos > self.tuples.len() - 1 {
if self.pos > self.indices.len() - 1 {
return None;
}
let (_, tuple) = self.tuples.take(self.indices[self.pos]);
Expand Down Expand Up @@ -147,11 +161,7 @@ impl SortBy {
}
let indices = radix_sort(sort_keys, arena);

Ok(Box::new(RemappingIterator {
pos: 0,
tuples,
indices,
}))
Ok(Box::new(RemappingIterator::new(0, tuples, indices)))
}
SortBy::Fast => {
let fn_nulls_first = |nulls_first: bool| {
Expand Down Expand Up @@ -484,7 +494,7 @@ mod test {
SortField {
expr: ScalarExpression::Reference {
expr: Box::new(ScalarExpression::Empty),
pos: 0,
pos: 1,
},
asc: asc_2,
nulls_first: nulls_first_2,
Expand Down
Loading
Loading