pub struct OrderBy { /* private fields */ }Expand description
Order by specification for queries
Implementations§
Source§impl OrderBy
impl OrderBy
Sourcepub fn compare<R>(
&self,
a: &R,
b: &R,
get_value: impl Fn(&R, &str) -> Value,
) -> Ordering
pub fn compare<R>( &self, a: &R, b: &R, get_value: impl Fn(&R, &str) -> Value, ) -> Ordering
Compare two rows according to all sort keys
The get_value closure takes a row and column name, returning the value.
Sourcepub fn sort_rows<R>(
&self,
rows: &mut [R],
get_value: impl Fn(&R, &str) -> Value,
)
pub fn sort_rows<R>( &self, rows: &mut [R], get_value: impl Fn(&R, &str) -> Value, )
Sort a slice of rows in place
Sourcepub fn dispatch_sort<R>(
&self,
rows: Vec<R>,
prefix_keys: usize,
limit: Option<usize>,
get_value: impl Fn(&R, &str) -> Value,
) -> Vec<R>
pub fn dispatch_sort<R>( &self, rows: Vec<R>, prefix_keys: usize, limit: Option<usize>, get_value: impl Fn(&R, &str) -> Value, ) -> Vec<R>
Phase 3.2 dispatch entry point. Combines OrderBy::sort_rows
and incremental_sort_top_k behind a single callable that
the planner / executor invokes after deciding the strategy
via planner::pathkeys::plan_sort.
prefix_keys is the number of leading sort keys the input
already satisfies (0 if unknown). limit is the LIMIT k for
top-k early termination, or None for an unbounded sort.
Behavior matrix:
prefix_keys == 0&&limit == None→ fullsort_rows.prefix_keys == 0&&limit == Some(k)→ full sort then truncate to k.prefix_keys > 0&&limit == Some(k)→ callincremental_sort_top_k(prefix_keys, k).prefix_keys > 0&&limit == None→ walk groups and sort within each, no early termination (still cheaper than full sort because each group is independent).
Sourcepub fn incremental_sort_top_k<R>(
&self,
rows: Vec<R>,
prefix_keys: usize,
k: usize,
get_value: impl Fn(&R, &str) -> Value,
) -> Vec<R>
pub fn incremental_sort_top_k<R>( &self, rows: Vec<R>, prefix_keys: usize, k: usize, get_value: impl Fn(&R, &str) -> Value, ) -> Vec<R>
Incremental top-K sort.
Fase 4 P3 win: when the upstream operator already returns
rows in prefix_keys order (e.g. an index scan whose key
is a prefix of the requested ORDER BY), this method walks
the input in chunks of equal-prefix rows, sorts each chunk
by the remaining keys, emits up to k rows total, and
terminates as soon as the budget is met.
Mirrors PG’s nodeIncrementalSort.c algorithm, simplified:
- Walk
rowsleft-to-right, grouping by equal-prefix. - For each group, full-sort by
self.keys[prefix_keys..](the suffix not already covered by upstream order). - Append at most
k - emittedrows from the sorted group to the output, then advance to the next group. - Stop iteration entirely once
emitted == k.
Caller contract: rows MUST already be sorted by
self.keys[..prefix_keys]. Violating this produces wrong
results — the planner is responsible for verifying input
pathkey order before choosing this operator.
When prefix_keys == 0 this degenerates to a regular
top-k sort using sort_rows + truncate. When
prefix_keys >= self.keys.len() the input is already
fully ordered and the method just truncates.
Sourcepub fn referenced_columns(&self) -> Vec<&str>
pub fn referenced_columns(&self) -> Vec<&str>
Get all referenced columns
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OrderBy
impl RefUnwindSafe for OrderBy
impl Send for OrderBy
impl Sync for OrderBy
impl Unpin for OrderBy
impl UnsafeUnpin for OrderBy
impl UnwindSafe for OrderBy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request