pub struct WindowTopN;Expand description
Physical optimizer rule that converts per-partition ROW_NUMBER top-K
queries into a more efficient plan using PartitionedTopKExec.
§Pattern Detected
FilterExec(rn <= K)
[optional ProjectionExec]
BoundedWindowAggExec(ROW_NUMBER PARTITION BY ... ORDER BY ...)
SortExec(partition_keys, order_keys)§Replacement
[optional ProjectionExec]
BoundedWindowAggExec(ROW_NUMBER PARTITION BY ... ORDER BY ...)
PartitionedTopKExec(partition_keys, order_keys, fetch=K)The FilterExec is removed entirely (all output rows have rn ∈ {1..K}).
The SortExec is replaced by PartitionedTopKExec which maintains a
per-partition top-K heap instead of sorting the entire dataset.
§Supported Predicates
rn <= K→ fetch = Krn < K→ fetch = K - 1K >= rn(flipped) → fetch = KK > rn(flipped) → fetch = K - 1
§When the Rule Fires
All of the following must be true:
- Config flag
enable_window_topnistrue - The plan matches
FilterExec → [ProjectionExec] → BoundedWindowAggExec → SortExec - The window function is
ROW_NUMBER(notRANK,DENSE_RANK, etc.) ROW_NUMBERhas aPARTITION BYclause (global top-K is already handled bySortExecwithfetch)- The filter predicate compares the window output column to an integer
literal using
<=,<,>=, or>
Implementations§
Source§impl WindowTopN
impl WindowTopN
Trait Implementations§
Source§impl Clone for WindowTopN
impl Clone for WindowTopN
Source§fn clone(&self) -> WindowTopN
fn clone(&self) -> WindowTopN
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WindowTopN
impl Debug for WindowTopN
Source§impl Default for WindowTopN
impl Default for WindowTopN
Source§fn default() -> WindowTopN
fn default() -> WindowTopN
Returns the “default value” for a type. Read more
Source§impl PhysicalOptimizerRule for WindowTopN
impl PhysicalOptimizerRule for WindowTopN
Source§fn optimize(
&self,
plan: Arc<dyn ExecutionPlan>,
config: &ConfigOptions,
) -> Result<Arc<dyn ExecutionPlan>>
fn optimize( &self, plan: Arc<dyn ExecutionPlan>, config: &ConfigOptions, ) -> Result<Arc<dyn ExecutionPlan>>
Rewrite
plan to an optimized form. Read moreSource§fn schema_check(&self) -> bool
fn schema_check(&self) -> bool
A flag to indicate whether the physical planner should validate that the rule will not
change the schema of the plan after the rewriting.
Some of the optimization rules might change the nullable properties of the schema
and should disable the schema check.
Source§fn optimize_with_context(
&self,
plan: Arc<dyn ExecutionPlan>,
context: &dyn PhysicalOptimizerContext,
) -> Result<Arc<dyn ExecutionPlan>>
fn optimize_with_context( &self, plan: Arc<dyn ExecutionPlan>, context: &dyn PhysicalOptimizerContext, ) -> Result<Arc<dyn ExecutionPlan>>
Rewrite
plan with access to extended context (statistics registry, etc.). Read moreAuto Trait Implementations§
impl Freeze for WindowTopN
impl RefUnwindSafe for WindowTopN
impl Send for WindowTopN
impl Sync for WindowTopN
impl Unpin for WindowTopN
impl UnsafeUnpin for WindowTopN
impl UnwindSafe for WindowTopN
Blanket Implementations§
impl<T> Allocation for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 more