pub struct TopNResult { /* private fields */ }Expand description
Top-N result using a bounded heap for ORDER BY + LIMIT optimization
This is O(n log k) instead of O(n log n) for full sort, where k = limit. For large datasets with small limits (e.g., 1M rows, LIMIT 10), this can be 5-50x faster.
Implementations§
Source§impl TopNResult
impl TopNResult
Sourcepub fn new<F>(
inner: Box<dyn QueryResult>,
compare: F,
limit: usize,
offset: usize,
) -> Result<Self>
pub fn new<F>( inner: Box<dyn QueryResult>, compare: F, limit: usize, offset: usize, ) -> Result<Self>
Create a new top-N result using BinaryHeap for bounded sorting
Uses a max-heap of size k (limit + offset) to efficiently find top-k elements. Only keeps k rows in memory at any time, making it memory-efficient for small limits.
§Arguments
inner- Source result to processcompare- Comparison function for ordering (returns Less if a should come before b)limit- Maximum number of rows to returnoffset- Number of rows to skip (we need limit + offset rows in heap)
pub fn new_with_context<F>( inner: Box<dyn QueryResult>, compare: F, limit: usize, offset: usize, ctx: &ExecutionContext, ) -> Result<Self>
pub fn from_rows_with_budget( columns: Vec<String>, rows: RowVec, budget: RetainedRowsBudget, ) -> Self
Trait Implementations§
Source§impl QueryResult for TopNResult
impl QueryResult for TopNResult
Source§fn scan(&self, dest: &mut [Value]) -> Result<()>
fn scan(&self, dest: &mut [Value]) -> Result<()>
Scans the current row into the provided values Read more
Source§fn rows_affected(&self) -> i64
fn rows_affected(&self) -> i64
Returns the number of rows affected by an INSERT, UPDATE, or DELETE
Source§fn last_insert_id(&self) -> i64
fn last_insert_id(&self) -> i64
Returns the last inserted ID for an INSERT operation
Source§fn with_aliases(
self: Box<Self>,
aliases: FxHashMap<String, String>,
) -> Box<dyn QueryResult>
fn with_aliases( self: Box<Self>, aliases: FxHashMap<String, String>, ) -> Box<dyn QueryResult>
Sets column aliases for this result Read more
Source§fn columns_arc(&self) -> Option<CompactArc<Vec<String>>>
fn columns_arc(&self) -> Option<CompactArc<Vec<String>>>
Returns column names as Arc for zero-copy sharing Read more
Source§fn try_into_arc_rows(&mut self) -> Option<CompactArc<Vec<Row>>>
fn try_into_arc_rows(&mut self) -> Option<CompactArc<Vec<Row>>>
Try to extract all rows as
CompactArc<Vec<Row>> for zero-copy joins Read moreSource§fn estimated_count(&self) -> Option<usize>
fn estimated_count(&self) -> Option<usize>
Returns an estimate of the total number of rows in the result. Read more
Source§fn supports_typed_batches(&self) -> bool
fn supports_typed_batches(&self) -> bool
Whether the result can yield decoded typed column batches without
constructing a row/value object for every result record. Read more
Source§fn typed_batch_fallback_reason(&self) -> Option<TypedBatchFallbackReason>
fn typed_batch_fallback_reason(&self) -> Option<TypedBatchFallbackReason>
If
supports_typed_batches() is false, return the best semantic reason. Read moreSource§fn next_typed_batch(&mut self) -> Result<Option<TypedColumnBatch>, Error>
fn next_typed_batch(&mut self) -> Result<Option<TypedColumnBatch>, Error>
Advance to the next typed column batch. Read more
Auto Trait Implementations§
impl Freeze for TopNResult
impl RefUnwindSafe for TopNResult
impl Send for TopNResult
impl Sync for TopNResult
impl Unpin for TopNResult
impl UnsafeUnpin for TopNResult
impl UnwindSafe for TopNResult
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
Mutably borrows from an owned value. Read more