From 93b6f21974881bcdc2ae291a9b899d35f54e5fd3 Mon Sep 17 00:00:00 2001 From: Junhao Liu Date: Wed, 21 Feb 2024 17:04:20 -0600 Subject: [PATCH 1/4] fix typo --- datafusion/physical-plan/src/sorts/sort.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs index 2d8237011fff6..1fc8d759d54e5 100644 --- a/datafusion/physical-plan/src/sorts/sort.rs +++ b/datafusion/physical-plan/src/sorts/sort.rs @@ -373,7 +373,7 @@ impl ExternalSorter { } /// Writes any `in_memory_batches` to a spill file and clears - /// the batches. The contents of the spil file are sorted. + /// the batches. The contents of the spill file are sorted. /// /// Returns the amount of memory freed. async fn spill(&mut self) -> Result { @@ -726,7 +726,7 @@ impl SortExec { /// Specify the partitioning behavior of this sort exec /// /// If `preserve_partitioning` is true, sorts each partition - /// individually, producing one sorted strema for each input partition. + /// individually, producing one sorted stream for each input partition. /// /// If `preserve_partitioning` is false, sorts and merges all /// input partitions producing a single, sorted partition. From d7406a8d40aaa8f70d0c839746b2d0a8918f6cea Mon Sep 17 00:00:00 2001 From: Junhao Liu Date: Mon, 4 Mar 2024 14:56:38 -0600 Subject: [PATCH 2/4] initial try --- .../physical-plan/src/sorts/partial_sort.rs | 38 +++++++++++++------ datafusion/physical-plan/src/sorts/sort.rs | 6 +-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/datafusion/physical-plan/src/sorts/partial_sort.rs b/datafusion/physical-plan/src/sorts/partial_sort.rs index 500df6153fdba..7dd7fc2d6397f 100644 --- a/datafusion/physical-plan/src/sorts/partial_sort.rs +++ b/datafusion/physical-plan/src/sorts/partial_sort.rs @@ -73,7 +73,8 @@ use datafusion_common::Result; use datafusion_execution::{RecordBatchStream, TaskContext}; use datafusion_physical_expr::LexOrdering; -use futures::{ready, Stream, StreamExt}; +use crate::stream::RecordBatchStreamAdapter; +use futures::{ready, Stream, StreamExt, TryStreamExt}; use log::trace; /// Partial Sort execution plan. @@ -272,7 +273,7 @@ impl ExecutionPlan for PartialSortExec { ) -> Result { trace!("Start PartialSortExec::execute for partition {} of context session_id {} and task_id {:?}", partition, context.session_id(), context.task_id()); - let input = self.input.execute(partition, context.clone())?; + let mut input = self.input.execute(partition, context.clone())?; trace!( "End PartialSortExec's input.execute for partition: {}", @@ -282,16 +283,31 @@ impl ExecutionPlan for PartialSortExec { // Make sure common prefix length is larger than 0 // Otherwise, we should use SortExec. assert!(self.common_prefix_length > 0); + let execution_options = &context.session_config().options().execution; - Ok(Box::pin(PartialSortStream { - input, - expr: self.expr.clone(), - common_prefix_length: self.common_prefix_length, - in_mem_batches: vec![], - fetch: self.fetch, - is_closed: false, - baseline_metrics: BaselineMetrics::new(&self.metrics_set, partition), - })) + let mut sorter = crate::sorts::sort::ExternalSorter::new( + partition, + input.schema(), + self.expr.clone(), + context.session_config().batch_size(), + self.fetch, + execution_options.sort_spill_reservation_bytes, + execution_options.sort_in_place_threshold_bytes, + &self.metrics_set, + context.runtime_env(), + ); + + Ok(Box::pin(RecordBatchStreamAdapter::new( + self.schema(), + futures::stream::once(async move { + while let Some(batch) = input.next().await { + let batch = batch?; + sorter.insert_batch(batch).await?; + } + sorter.sort() + }) + .try_flatten(), + ))) } fn metrics(&self) -> Option { diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs index e4df24e02bf2e..234d17df2ecde 100644 --- a/datafusion/physical-plan/src/sorts/sort.rs +++ b/datafusion/physical-plan/src/sorts/sort.rs @@ -197,7 +197,7 @@ impl ExternalSorterMetrics { /// /// in_mem_batches /// ``` -struct ExternalSorter { +pub(crate) struct ExternalSorter { /// schema of the output (and the input) schema: SchemaRef, /// Potentially unsorted in memory buffer @@ -277,7 +277,7 @@ impl ExternalSorter { /// Appends an unsorted [`RecordBatch`] to `in_mem_batches` /// /// Updates memory usage metrics, and possibly triggers spilling to disk - async fn insert_batch(&mut self, input: RecordBatch) -> Result<()> { + pub(crate) async fn insert_batch(&mut self, input: RecordBatch) -> Result<()> { if input.num_rows() == 0 { return Ok(()); } @@ -322,7 +322,7 @@ impl ExternalSorter { /// /// 2. A combined streaming merge incorporating both in-memory /// batches and data from spill files on disk. - fn sort(&mut self) -> Result { + pub(crate) fn sort(&mut self) -> Result { if self.spilled_before() { let mut streams = vec![]; if !self.in_mem_batches.is_empty() { From 9c6bc44c4d3ba5423f887ccb98a38b4026e35ef4 Mon Sep 17 00:00:00 2001 From: Junhao Liu Date: Tue, 5 Mar 2024 11:00:27 -0600 Subject: [PATCH 3/4] feat: reuse external sorter to implement partial sort --- .../physical-plan/src/sorts/partial_sort.rs | 381 ++++-------------- datafusion/physical-plan/src/sorts/sort.rs | 61 +++ 2 files changed, 136 insertions(+), 306 deletions(-) diff --git a/datafusion/physical-plan/src/sorts/partial_sort.rs b/datafusion/physical-plan/src/sorts/partial_sort.rs index 7dd7fc2d6397f..51221f911d921 100644 --- a/datafusion/physical-plan/src/sorts/partial_sort.rs +++ b/datafusion/physical-plan/src/sorts/partial_sort.rs @@ -53,28 +53,21 @@ use std::any::Any; use std::fmt::Debug; -use std::pin::Pin; use std::sync::Arc; -use std::task::{Context, Poll}; use crate::expressions::PhysicalSortExpr; -use crate::metrics::{BaselineMetrics, ExecutionPlanMetricsSet, MetricsSet}; -use crate::sorts::sort::sort_batch; +use crate::metrics::{ExecutionPlanMetricsSet, MetricsSet}; use crate::{ DisplayAs, DisplayFormatType, Distribution, ExecutionPlan, ExecutionPlanProperties, Partitioning, PlanProperties, SendableRecordBatchStream, Statistics, }; -use arrow::compute::concat_batches; -use arrow::datatypes::SchemaRef; -use arrow::record_batch::RecordBatch; -use datafusion_common::utils::evaluate_partition_ranges; use datafusion_common::Result; -use datafusion_execution::{RecordBatchStream, TaskContext}; +use datafusion_execution::TaskContext; use datafusion_physical_expr::LexOrdering; use crate::stream::RecordBatchStreamAdapter; -use futures::{ready, Stream, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt}; use log::trace; /// Partial Sort execution plan. @@ -296,13 +289,13 @@ impl ExecutionPlan for PartialSortExec { &self.metrics_set, context.runtime_env(), ); - + let prefix = self.common_prefix_length; Ok(Box::pin(RecordBatchStreamAdapter::new( self.schema(), futures::stream::once(async move { while let Some(batch) = input.next().await { let batch = batch?; - sorter.insert_batch(batch).await?; + sorter.insert_batch_with_prefix(batch, prefix).await?; } sorter.sort() }) @@ -319,145 +312,24 @@ impl ExecutionPlan for PartialSortExec { } } -struct PartialSortStream { - /// The input plan - input: SendableRecordBatchStream, - /// Sort expressions - expr: Vec, - /// Length of prefix common to input ordering and required ordering of plan - /// should be more than 0 otherwise PartialSort is not applicable - common_prefix_length: usize, - /// Used as a buffer for part of the input not ready for sort - in_mem_batches: Vec, - /// Fetch top N results - fetch: Option, - /// Whether the stream has finished returning all of its data or not - is_closed: bool, - /// Execution metrics - baseline_metrics: BaselineMetrics, -} - -impl Stream for PartialSortStream { - type Item = Result; - - fn poll_next( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { - let poll = self.poll_next_inner(cx); - self.baseline_metrics.record_poll(poll) - } - - fn size_hint(&self) -> (usize, Option) { - // we can't predict the size of incoming batches so re-use the size hint from the input - self.input.size_hint() - } -} - -impl RecordBatchStream for PartialSortStream { - fn schema(&self) -> SchemaRef { - self.input.schema() - } -} - -impl PartialSortStream { - fn poll_next_inner( - self: &mut Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll>> { - if self.is_closed { - return Poll::Ready(None); - } - let result = match ready!(self.input.poll_next_unpin(cx)) { - Some(Ok(batch)) => { - if let Some(slice_point) = - self.get_slice_point(self.common_prefix_length, &batch)? - { - self.in_mem_batches.push(batch.slice(0, slice_point)); - let remaining_batch = - batch.slice(slice_point, batch.num_rows() - slice_point); - let sorted_batch = self.sort_in_mem_batches(); - self.in_mem_batches.push(remaining_batch); - sorted_batch - } else { - self.in_mem_batches.push(batch); - Ok(RecordBatch::new_empty(self.schema())) - } - } - Some(Err(e)) => Err(e), - None => { - self.is_closed = true; - // once input is consumed, sort the rest of the inserted batches - self.sort_in_mem_batches() - } - }; - - Poll::Ready(Some(result)) - } - - /// Returns a sorted RecordBatch from in_mem_batches and clears in_mem_batches - /// - /// If fetch is specified for PartialSortStream `sort_in_mem_batches` will limit - /// the last RecordBatch returned and will mark the stream as closed - fn sort_in_mem_batches(self: &mut Pin<&mut Self>) -> Result { - let input_batch = concat_batches(&self.schema(), &self.in_mem_batches)?; - self.in_mem_batches.clear(); - let result = sort_batch(&input_batch, &self.expr, self.fetch)?; - if let Some(remaining_fetch) = self.fetch { - // remaining_fetch - result.num_rows() is always be >= 0 - // because result length of sort_batch with limit cannot be - // more than the requested limit - self.fetch = Some(remaining_fetch - result.num_rows()); - if remaining_fetch == result.num_rows() { - self.is_closed = true; - } - } - Ok(result) - } - - /// Return the end index of the second last partition if the batch - /// can be partitioned based on its already sorted columns - /// - /// Return None if the batch cannot be partitioned, which means the - /// batch does not have the information for a safe sort - fn get_slice_point( - &self, - common_prefix_len: usize, - batch: &RecordBatch, - ) -> Result> { - let common_prefix_sort_keys = (0..common_prefix_len) - .map(|idx| self.expr[idx].evaluate_to_sort_column(batch)) - .collect::>>()?; - let partition_points = - evaluate_partition_ranges(batch.num_rows(), &common_prefix_sort_keys)?; - // If partition points are [0..100], [100..200], [200..300] - // we should return 200, which is the safest and furthest partition boundary - // Please note that we shouldn't return 300 (which is number of rows in the batch), - // because this boundary may change with new data. - if partition_points.len() >= 2 { - Ok(Some(partition_points[partition_points.len() - 2].end)) - } else { - Ok(None) - } - } -} - #[cfg(test)] mod tests { + use std::collections::HashMap; use arrow::array::*; use arrow::compute::SortOptions; use arrow::datatypes::*; + use datafusion_execution::config::SessionConfig; + use datafusion_execution::runtime_env::{RuntimeConfig, RuntimeEnv}; use futures::FutureExt; - use itertools::Itertools; use datafusion_common::assert_batches_eq; + use crate::coalesce_partitions::CoalescePartitionsExec; use crate::collect; use crate::expressions::col; use crate::memory::MemoryExec; - use crate::sorts::sort::SortExec; use crate::test; use crate::test::assert_is_pending; use crate::test::exec::{assert_strong_count_converges_to_zero, BlockingExec}; @@ -515,7 +387,7 @@ mod tests { "| 1 | 3 | 3 |", "+---+---+---+", ]; - assert_eq!(2, result.len()); + assert_eq!(1, result.len()); assert_batches_eq!(expected_after_sort, &result); assert_eq!( task_ctx.runtime_env().memory_pool.reserved(), @@ -526,6 +398,62 @@ mod tests { Ok(()) } + #[tokio::test] + async fn test_partial_sort_spill() -> Result<()> { + // trigger spill w/ 100 batches + let session_config = SessionConfig::new(); + let sort_spill_reservation_bytes = session_config + .options() + .execution + .sort_spill_reservation_bytes; + let rt_config = RuntimeConfig::new() + .with_memory_limit(sort_spill_reservation_bytes + 12288, 1.0); + let runtime = Arc::new(RuntimeEnv::new(rt_config)?); + let task_ctx = Arc::new( + TaskContext::default() + .with_session_config(session_config) + .with_runtime(runtime), + ); + + let partitions = 100; + let input = test::scan_partitioned(partitions); + let schema = input.schema(); + + let sort_exec = Arc::new(PartialSortExec::new( + vec![PhysicalSortExpr { + expr: col("i", &schema)?, + options: SortOptions::default(), + }], + Arc::new(CoalescePartitionsExec::new(input)), + 1, + )); + + let result = collect(sort_exec.clone(), task_ctx.clone()).await?; + + assert_eq!(result.len(), 2); + + // Now, validate metrics + let metrics = sort_exec.metrics().unwrap(); + + assert_eq!(metrics.output_rows().unwrap(), 10000); + assert!(metrics.elapsed_compute().unwrap() > 0); + assert!(metrics.spill_count().unwrap() > 0); + assert!(metrics.spilled_bytes().unwrap() > 0); + + let columns = result[0].columns(); + + let i = as_primitive_array::(&columns[0]); + assert_eq!(i.value(0), 0); + assert_eq!(i.value(i.len() - 1), 81); + + assert_eq!( + task_ctx.runtime_env().memory_pool.reserved(), + 0, + "The sort should have returned all memory used back to the memory manager" + ); + + Ok(()) + } #[tokio::test] async fn test_partial_sort_with_fetch() -> Result<()> { let task_ctx = Arc::new(TaskContext::default()); @@ -579,7 +507,7 @@ mod tests { "| 1 | 3 | 0 |", "+---+---+---+", ]; - assert_eq!(2, result.len()); + assert_eq!(1, result.len()); assert_batches_eq!(expected_after_sort, &result); assert_eq!( task_ctx.runtime_env().memory_pool.reserved(), @@ -638,7 +566,7 @@ mod tests { )); let result = collect(partial_sort_exec, task_ctx.clone()).await?; - assert_eq!(2, result.len()); + assert_eq!(1, result.len()); assert_eq!( task_ctx.runtime_env().memory_pool.reserved(), 0, @@ -663,157 +591,6 @@ mod tests { Ok(()) } - fn prepare_partitioned_input() -> Arc { - let batch1 = test::build_table_i32( - ("a", &vec![1; 100]), - ("b", &(0..100).rev().collect()), - ("c", &(0..100).rev().collect()), - ); - let batch2 = test::build_table_i32( - ("a", &[&vec![1; 25][..], &vec![2; 75][..]].concat()), - ("b", &(100..200).rev().collect()), - ("c", &(0..100).collect()), - ); - let batch3 = test::build_table_i32( - ("a", &[&vec![3; 50][..], &vec![4; 50][..]].concat()), - ("b", &(150..250).rev().collect()), - ("c", &(0..100).rev().collect()), - ); - let batch4 = test::build_table_i32( - ("a", &vec![4; 100]), - ("b", &(50..150).rev().collect()), - ("c", &(0..100).rev().collect()), - ); - let schema = batch1.schema(); - Arc::new( - MemoryExec::try_new( - &[vec![batch1, batch2, batch3, batch4]], - schema.clone(), - None, - ) - .unwrap(), - ) as Arc - } - - #[tokio::test] - async fn test_partitioned_input_partial_sort() -> Result<()> { - let task_ctx = Arc::new(TaskContext::default()); - let mem_exec = prepare_partitioned_input(); - let option_asc = SortOptions { - descending: false, - nulls_first: false, - }; - let option_desc = SortOptions { - descending: false, - nulls_first: false, - }; - let schema = mem_exec.schema(); - let partial_sort_executor = PartialSortExec::new( - vec![ - PhysicalSortExpr { - expr: col("a", &schema)?, - options: option_asc, - }, - PhysicalSortExpr { - expr: col("b", &schema)?, - options: option_desc, - }, - PhysicalSortExpr { - expr: col("c", &schema)?, - options: option_asc, - }, - ], - mem_exec.clone(), - 1, - ); - let partial_sort_exec = - Arc::new(partial_sort_executor.clone()) as Arc; - let sort_exec = Arc::new(SortExec::new( - partial_sort_executor.expr, - partial_sort_executor.input, - )) as Arc; - let result = collect(partial_sort_exec, task_ctx.clone()).await?; - assert_eq!( - result.iter().map(|r| r.num_rows()).collect_vec(), - [0, 125, 125, 0, 150] - ); - - assert_eq!( - task_ctx.runtime_env().memory_pool.reserved(), - 0, - "The sort should have returned all memory used back to the memory manager" - ); - let partial_sort_result = concat_batches(&schema, &result).unwrap(); - let sort_result = collect(sort_exec, task_ctx.clone()).await?; - assert_eq!(sort_result[0], partial_sort_result); - - Ok(()) - } - - #[tokio::test] - async fn test_partitioned_input_partial_sort_with_fetch() -> Result<()> { - let task_ctx = Arc::new(TaskContext::default()); - let mem_exec = prepare_partitioned_input(); - let schema = mem_exec.schema(); - let option_asc = SortOptions { - descending: false, - nulls_first: false, - }; - let option_desc = SortOptions { - descending: false, - nulls_first: false, - }; - for (fetch_size, expected_batch_num_rows) in [ - (Some(50), vec![0, 50]), - (Some(120), vec![0, 120]), - (Some(150), vec![0, 125, 25]), - (Some(250), vec![0, 125, 125]), - ] { - let partial_sort_executor = PartialSortExec::new( - vec![ - PhysicalSortExpr { - expr: col("a", &schema)?, - options: option_asc, - }, - PhysicalSortExpr { - expr: col("b", &schema)?, - options: option_desc, - }, - PhysicalSortExpr { - expr: col("c", &schema)?, - options: option_asc, - }, - ], - mem_exec.clone(), - 1, - ) - .with_fetch(fetch_size); - - let partial_sort_exec = - Arc::new(partial_sort_executor.clone()) as Arc; - let sort_exec = Arc::new( - SortExec::new(partial_sort_executor.expr, partial_sort_executor.input) - .with_fetch(fetch_size), - ) as Arc; - let result = collect(partial_sort_exec, task_ctx.clone()).await?; - assert_eq!( - result.iter().map(|r| r.num_rows()).collect_vec(), - expected_batch_num_rows - ); - - assert_eq!( - task_ctx.runtime_env().memory_pool.reserved(), - 0, - "The sort should have returned all memory used back to the memory manager" - ); - let partial_sort_result = concat_batches(&schema, &result)?; - let sort_result = collect(sort_exec, task_ctx.clone()).await?; - assert_eq!(sort_result[0], partial_sort_result); - } - - Ok(()) - } - #[tokio::test] async fn test_sort_metadata() -> Result<()> { let task_ctx = Arc::new(TaskContext::default()); @@ -847,20 +624,12 @@ mod tests { )); let result: Vec = collect(partial_sort_exec, task_ctx).await?; - let expected_batch = vec![ - RecordBatch::try_new( - schema.clone(), - vec![Arc::new( - vec![1, 1].into_iter().map(Some).collect::(), - )], - )?, - RecordBatch::try_new( - schema.clone(), - vec![Arc::new( - vec![2].into_iter().map(Some).collect::(), - )], - )?, - ]; + let expected_batch = vec![RecordBatch::try_new( + schema.clone(), + vec![Arc::new( + vec![1, 1, 2].into_iter().map(Some).collect::(), + )], + )?]; // Data is correct assert_eq!(&expected_batch, &result); @@ -976,7 +745,7 @@ mod tests { let result: Vec = collect(partial_sort_exec.clone(), task_ctx).await?; assert_batches_eq!(expected, &result); - assert_eq!(result.len(), 2); + assert_eq!(result.len(), 1); let metrics = partial_sort_exec.metrics().unwrap(); assert!(metrics.elapsed_compute().unwrap() > 0); assert_eq!(metrics.output_rows().unwrap(), 8); diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs index 234d17df2ecde..15c16c4d80c68 100644 --- a/datafusion/physical-plan/src/sorts/sort.rs +++ b/datafusion/physical-plan/src/sorts/sort.rs @@ -55,6 +55,7 @@ use datafusion_execution::runtime_env::RuntimeEnv; use datafusion_execution::TaskContext; use datafusion_physical_expr::LexOrdering; +use datafusion_common::utils::evaluate_partition_ranges; use futures::{StreamExt, TryStreamExt}; use log::{debug, error, trace}; use tokio::sync::mpsc::Sender; @@ -309,6 +310,66 @@ impl ExternalSorter { Ok(()) } + fn get_slice_point( + &self, + common_prefix_len: usize, + batch: &RecordBatch, + ) -> Result> { + let common_prefix_sort_keys = (0..common_prefix_len) + .map(|idx| self.expr[idx].evaluate_to_sort_column(batch)) + .collect::>>()?; + let partition_points = + evaluate_partition_ranges(batch.num_rows(), &common_prefix_sort_keys)?; + // If partition points are [0..100], [100..200], [200..300] + // we should return 200, which is the safest and furthest partition boundary + // Please note that we shouldn't return 300 (which is number of rows in the batch), + // because this boundary may change with new data. + if partition_points.len() >= 2 { + Ok(Some(partition_points[partition_points.len() - 2].end)) + } else { + Ok(None) + } + } + pub(crate) async fn insert_batch_with_prefix( + &mut self, + input: RecordBatch, + prefix: usize, + ) -> Result<()> { + if input.num_rows() == 0 { + return Ok(()); + } + self.reserve_memory_for_merge()?; + + let size = input.get_array_memory_size(); + if self.reservation.try_grow(size).is_err() { + let before = self.reservation.size(); + self.in_mem_sort().await?; + // Sorting may have freed memory, especially if fetch is `Some` + // + // As such we check again, and if the memory usage has dropped by + // a factor of 2, and we can allocate the necessary capacity, + // we don't spill + // + // The factor of 2 aims to avoid a degenerate case where the + // memory required for `fetch` is just under the memory available, + // causing repeated re-sorting of data + if self.reservation.size() > before / 2 + || self.reservation.try_grow(size).is_err() + { + self.spill().await?; + self.reservation.try_grow(size)? + } + } + if let Some(slice_point) = self.get_slice_point(prefix, &input)? { + self.in_mem_batches.push(input.slice(0, slice_point)); + self.in_mem_batches + .push(input.slice(slice_point, input.num_rows() - slice_point)); + } else { + self.in_mem_batches.push(input); + } + self.in_mem_batches_sorted = false; + Ok(()) + } fn spilled_before(&self) -> bool { !self.spills.is_empty() } From 7ed2bfae040633295e1f6d7d80bd32490c29fbe3 Mon Sep 17 00:00:00 2001 From: Junhao Liu Date: Tue, 5 Mar 2024 11:04:57 -0600 Subject: [PATCH 4/4] generally applicable partial sort --- datafusion/core/src/physical_optimizer/enforce_sorting.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/datafusion/core/src/physical_optimizer/enforce_sorting.rs b/datafusion/core/src/physical_optimizer/enforce_sorting.rs index 5fac1397e023d..1994d6dc25058 100644 --- a/datafusion/core/src/physical_optimizer/enforce_sorting.rs +++ b/datafusion/core/src/physical_optimizer/enforce_sorting.rs @@ -208,9 +208,6 @@ fn replace_with_partial_sort( let plan_any = plan.as_any(); if let Some(sort_plan) = plan_any.downcast_ref::() { let child = sort_plan.children()[0].clone(); - if !child.execution_mode().is_unbounded() { - return Ok(plan); - } // here we're trying to find the common prefix for sorted columns that is required for the // sort and already satisfied by the given ordering