Apache DataFusion SQL Query Engine
fix: WindowTopN resolves the filter column through intermediate proje… (#26417)
Subham Singhal36f393559620
diff --git a/datafusion/core/tests/physical_optimizer/window_topn.rs b/datafusion/core/tests/physical_optimizer/window_topn.rsindex d6f258246c..4a4f32fdc3 100644--- a/datafusion/core/tests/physical_optimizer/window_topn.rs+++ b/datafusion/core/tests/physical_optimizer/window_topn.rs@@ -46,10 +46,13 @@ use datafusion_physical_plan::filter::FilterExec;use datafusion_physical_plan::metrics::MetricValue;use datafusion_physical_plan::placeholder_row::PlaceholderRowExec;use datafusion_physical_plan::projection::ProjectionExec;-use datafusion_physical_plan::sorts::partitioned_topk::PartitionedTopKExec;+use datafusion_physical_plan::repartition::RepartitionExec;+use datafusion_physical_plan::sorts::partitioned_topk::{+ PartitionedTopKExec, WindowFnKind,+};use datafusion_physical_plan::sorts::sort::SortExec;use datafusion_physical_plan::windows::{BoundedWindowAggExec, create_udwf_window_expr};-use datafusion_physical_plan::{ExecutionPlan, InputOrderMode};+use datafusion_physical_plan::{ExecutionPlan, InputOrderMode, Partitioning};use insta::assert_snapshot;fn schema() -> Arc<Schema> {@@ -458,6 +461,149 @@ fn two_window_exprs_keep_the_window_node() -> Result<()> {Ok(())}+/// `ROW_NUMBER() AS rn, RANK() AS rk` over `PARTITION BY pk ORDER BY val`.+/// Output: `[pk@0, val@1, rn@2, rk@3]`.+fn build_rn_rk_window() -> Result<Arc<dyn ExecutionPlan>> {+ let s = schema();+ let input: Arc<dyn ExecutionPlan> = Arc::new(PlaceholderRowExec::new(Arc::clone(&s)));+ let partition_by = vec![col("pk", &s)?];+ let order_by = vec![PhysicalSortExpr::new_default(col("val", &s)?).asc()];+ let window_expr = |udwf: Arc<datafusion_expr::WindowUDF>, name: &str| {+ Ok::<_, datafusion_common::DataFusionError>(Arc::new(StandardWindowExpr::new(+ create_udwf_window_expr(&udwf, &[], &s, name.to_string(), false)?,+ &partition_by,+ &order_by,+ Arc::new(WindowFrame::new_bounds(+ WindowFrameUnits::Rows,+ WindowFrameBound::Preceding(ScalarValue::UInt64(None)),+ WindowFrameBound::CurrentRow,+ )),+ )))+ };+ Ok(Arc::new(BoundedWindowAggExec::try_new(+ vec![+ window_expr(row_number_udwf(), "rn")?,+ window_expr(rank_udwf(), "rk")?,+ ],+ input,+ InputOrderMode::Sorted,+ true,+ )?))+}++/// A `ProjectionExec` passing through `input`'s columns at `indices`.+fn project(+ input: Arc<dyn ExecutionPlan>,+ indices: &[usize],+) -> Result<Arc<dyn ExecutionPlan>> {+ let schema = input.schema();+ let exprs: Vec<(Arc<dyn datafusion_physical_expr::PhysicalExpr>, String)> = indices+ .iter()+ .map(|&i| {+ let name = schema.field(i).name();+ (+ Arc::new(Column::new(name, i))+ as Arc<dyn datafusion_physical_expr::PhysicalExpr>,+ name.to_string(),+ )+ })+ .collect();+ Ok(Arc::new(ProjectionExec::try_new(exprs, input)?))+}++/// `FilterExec(<column idx of input> <= 3)`, with the literal in the column's type.+fn filter_lteq_3(+ input: Arc<dyn ExecutionPlan>,+ idx: usize,+) -> Result<Arc<dyn ExecutionPlan>> {+ let schema = input.schema();+ let field = schema.field(idx);+ let predicate = Arc::new(BinaryExpr::new(+ Arc::new(Column::new(field.name(), idx)),+ Operator::LtEq,+ lit(ScalarValue::UInt64(Some(3)).cast_to(field.data_type())?),+ ));+ Ok(Arc::new(FilterExec::try_new(predicate, input)?))+}++/// The ranking function the rewrite chose, or `None` if it did not fire.+fn rewritten_fn(plan: Arc<dyn ExecutionPlan>) -> Result<Option<WindowFnKind>> {+ let optimized = optimize(plan)?;+ Ok(find_partitioned_topk(&optimized).map(|p| {+ p.downcast_ref::<PartitionedTopKExec>()+ .expect("find_partitioned_topk returns a PartitionedTopKExec")+ .fn_kind()+ }))+}++/// Stacked projections are resolved top-down: each one maps an index into its+/// output to one into its input. Bottom-up, `rk@0` would follow `pk@0` and then+/// `rk@2` to `rn` in the window's output.+#[test]+fn stacked_projections_resolve_top_down() -> Result<()> {+ let lower = project(build_rn_rk_window()?, &[0, 2, 3])?; // [pk, rn, rk]+ let upper = project(lower, &[2, 0])?; // [rk, pk]+ assert_eq!(+ rewritten_fn(filter_lteq_3(upper, 0)?)?,+ Some(WindowFnKind::Rank)+ );+ Ok(())+}++/// A `RepartitionExec` keeps its input's schema, so the index passes through it.+#[test]+fn repartition_between_passes_the_index_through() -> Result<()> {+ let repartition: Arc<dyn ExecutionPlan> = Arc::new(RepartitionExec::try_new(+ build_rn_rk_window()?,+ Partitioning::RoundRobinBatch(4),+ )?);+ let projection = project(repartition, &[0, 3])?; // [pk, rk]+ assert_eq!(+ rewritten_fn(filter_lteq_3(projection, 1)?)?,+ Some(WindowFnKind::Rank)+ );+ Ok(())+}++/// A projection that reorders the window's columns: the filter's `pk@2` maps+/// back to `pk@0`, an input column, so the rule leaves the plan alone. Read as+/// an index into the window's output, it would be `rn`.+#[test]+fn reordered_projection_input_column_no_change() -> Result<()> {+ let projection = project(build_rn_rk_window()?, &[2, 3, 0])?; // [rn, rk, pk]+ let plan = filter_lteq_3(projection, 2)?;+ let before = plan_str(plan.as_ref());+ assert_eq!(plan_str(optimize(plan)?.as_ref()), before);+ Ok(())+}++/// A column the projection computes has no single window column behind it,+/// so the rule leaves the plan alone. `x` sits at index 2 so that treating it+/// as a pass-through would land on `rn` rather than be rejected as an input+/// column.+#[test]+fn computed_projection_column_no_change() -> Result<()> {+ let window = build_rn_rk_window()?;+ let rk_plus_one: Arc<dyn datafusion_physical_expr::PhysicalExpr> =+ Arc::new(BinaryExpr::new(+ Arc::new(Column::new("rk", 3)),+ Operator::Plus,+ lit(ScalarValue::UInt64(Some(1))),+ ));+ let projection: Arc<dyn ExecutionPlan> = Arc::new(ProjectionExec::try_new(+ vec![+ (Arc::new(Column::new("pk", 0)) as _, "pk".to_string()),+ (Arc::new(Column::new("val", 1)) as _, "val".to_string()),+ (rk_plus_one, "x".to_string()),+ ],+ window,+ )?);+ let plan = filter_lteq_3(projection, 2)?;+ let before = plan_str(plan.as_ref());+ assert_eq!(plan_str(optimize(plan)?.as_ref()), before);+ Ok(())+}+// ----------------------------------------------------------------------// RANK rule tests// ----------------------------------------------------------------------diff --git a/datafusion/physical-optimizer/src/window_topn.rs b/datafusion/physical-optimizer/src/window_topn.rsindex 8fa22a38e8..ecdea24403 100644--- a/datafusion/physical-optimizer/src/window_topn.rs+++ b/datafusion/physical-optimizer/src/window_topn.rs@@ -122,6 +122,9 @@ use datafusion_physical_plan::windows::{BoundedWindowAggExec, WindowUDFExpr};/// All of the following must be true:/// - Config flag `enable_window_topn` is `true`/// - The plan matches `FilterExec → [ProjectionExec] → BoundedWindowAggExec`+/// - Every `ProjectionExec` between the filter and the window passes the+/// filtered column through as a bare column, possibly at another position+/// (as when a column the query no longer needs is dropped)/// - The window function is `ROW_NUMBER`, `RANK`, or `DENSE_RANK`/// - Every window expression in the `BoundedWindowAggExec` is `ROW_NUMBER`,/// `RANK`, or `DENSE_RANK` over the same `PARTITION BY` / `ORDER BY`. A@@ -193,7 +196,10 @@ impl WindowTopN {let child = filter.input();let (window_exec, intermediates) = find_window_below(child)?;- // Step 4: Verify col_idx references a supported window function output column+ // Step 4: Verify col_idx references a supported window function output column.+ // `col_idx` indexes the filter's input; resolve it to the window's output+ // first, since a projection in between can drop or reorder columns.+ let col_idx = column_index_below(col_idx, &intermediates)?;let window_exec_typed = window_exec.downcast_ref::<BoundedWindowAggExec>()?;let input_field_count = window_exec_typed.input().schema().fields().len();if col_idx < input_field_count {@@ -455,8 +461,10 @@ type PlanAndIntermediates = (Arc<dyn ExecutionPlan>, Vec<Arc<dyn ExecutionPlan>>////// Handles sequences of `ProjectionExec` and `RepartitionExec`./// This is safe because `PartitionedTopKExec` can be pushed below them:-/// projections only provide aliases, and pushing the limit below repartitions-/// is safe because the limit is computed per-partition.+/// projections only rename, drop, reorder or compute over the window's+/// columns (the filter's column is mapped back through them by+/// [`column_index_below`]), and pushing the limit below repartitions is safe+/// because the limit is computed per-partition.////// Returns the window exec and a list of intermediate nodes to rebuild,/// or `None` if no `BoundedWindowAggExec` is found.@@ -478,3 +486,28 @@ fn find_window_below(plan: &Arc<dyn ExecutionPlan>) -> Option<PlanAndIntermediat}}}++/// Maps `col_idx`, an index into the output of `intermediates[0]` (the+/// filter's input), to the index of the same column in the output of the+/// node below the last intermediate (the window).+///+/// `intermediates` is top-down, as [`find_window_below`] returns it, so each+/// step reads an index into the node's output and yields one into its input.+/// A `RepartitionExec` keeps its input's schema. A `ProjectionExec` must pass+/// the column through as a bare [`Column`]: one it computes (e.g. `rn + 1`)+/// has no single input column to follow, so this returns `None`.+fn column_index_below(+ col_idx: usize,+ intermediates: &[Arc<dyn ExecutionPlan>],+) -> Option<usize> {+ intermediates.iter().try_fold(col_idx, |idx, node| {+ if let Some(projection) = node.downcast_ref::<ProjectionExec>() {+ let expr = &projection.expr().get(idx)?.expr;+ Some(expr.downcast_ref::<Column>()?.index())+ } else if node.downcast_ref::<RepartitionExec>().is_some() {+ Some(idx)+ } else {+ None+ }+ })+}diff --git a/datafusion/sqllogictest/test_files/window_topn.slt b/datafusion/sqllogictest/test_files/window_topn.sltindex 637b6029c7..da2bcb9660 100644--- a/datafusion/sqllogictest/test_files/window_topn.slt+++ b/datafusion/sqllogictest/test_files/window_topn.slt@@ -1541,3 +1541,165 @@ set datafusion.execution.batch_size = 8192;statement okset datafusion.optimizer.enable_window_topn = false;++# The filter's column index is resolved through the projection between the+# filter and the window. Here the outer query drops `v`, so the projection+# shifts every later column down by one; with two ranking functions, using the+# filter's index as if it were the window's picks the other function.+statement ok+CREATE TABLE window_topn_shift (pk INT, v INT, id INT) AS VALUES+ (1, 0, 1), (1, 0, 2), (1, 1, 3), (2, 0, 4), (2, 0, 5), (2, 1, 6);++statement ok+SET datafusion.optimizer.enable_window_topn = true;++statement ok+SET datafusion.explain.physical_plan_only = true;++# Filter on rank(): both tied rows per partition are kept. `ORDER BY v` leaves+# the row numbers of tied rows unspecified, so ids and row numbers are checked+# as sets rather than paired up.+query I??+SELECT pk, array_agg(id ORDER BY id), array_agg(rn ORDER BY rn) FROM (+ SELECT pk, id, rn, rk FROM (+ SELECT pk, v, id,+ row_number() OVER (PARTITION BY pk ORDER BY v) AS rn,+ rank() OVER (PARTITION BY pk ORDER BY v) AS rk+ FROM window_topn_shift+ ) WHERE rk <= 1+) GROUP BY pk ORDER BY pk;+----+1 [1, 2] [1, 2]+2 [4, 5] [1, 2]++query TT+EXPLAIN SELECT pk, id, rn, rk FROM (+ SELECT pk, v, id,+ row_number() OVER (PARTITION BY pk ORDER BY v) AS rn,+ rank() OVER (PARTITION BY pk ORDER BY v) AS rk+ FROM window_topn_shift+) WHERE rk <= 1;+----+physical_plan+01)ProjectionExec: expr=[pk@0 as pk, id@2 as id, row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@3 as rn, rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@4 as rk]+02)--BoundedWindowAggExec: wdw=[row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]+03)----RepartitionExec: partitioning=Hash([pk@0], 4), input_partitions=1, maintains_sort_order=true+04)------PartitionedTopKExec: fn=rank, fetch=1, partition=[pk@0], order=[v@1 ASC NULLS LAST]+05)--------DataSourceExec: partitions=1, partition_sizes=[1]++# Filter on row_number(), with the window computing rank() first: no row with+# rn = 2 comes back. Either tied row may be the one kept; ids 3 and 6 are the+# only rows with v = 1.+query IIIB+SELECT pk, rk, rn, id NOT IN (3, 6) FROM (+ SELECT pk, v, id,+ rank() OVER (PARTITION BY pk ORDER BY v) AS rk,+ row_number() OVER (PARTITION BY pk ORDER BY v) AS rn+ FROM window_topn_shift+) WHERE rn <= 1 ORDER BY pk;+----+1 1 1 true+2 1 1 true++query TT+EXPLAIN SELECT pk, id, rk, rn FROM (+ SELECT pk, v, id,+ rank() OVER (PARTITION BY pk ORDER BY v) AS rk,+ row_number() OVER (PARTITION BY pk ORDER BY v) AS rn+ FROM window_topn_shift+) WHERE rn <= 1;+----+physical_plan+01)ProjectionExec: expr=[pk@0 as pk, id@2 as id, rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@3 as rk, row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@4 as rn]+02)--BoundedWindowAggExec: wdw=[rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]+03)----RepartitionExec: partitioning=Hash([pk@0], 4), input_partitions=1, maintains_sort_order=true+04)------PartitionedTopKExec: fn=row_number, fetch=1, partition=[pk@0], order=[v@1 ASC NULLS LAST]+05)--------DataSourceExec: partitions=1, partition_sizes=[1]++# Filter on dense_rank(), behind row_number().+query I??+SELECT pk, array_agg(id ORDER BY id), array_agg(rn ORDER BY rn) FROM (+ SELECT pk, id, rn, dr FROM (+ SELECT pk, v, id,+ row_number() OVER (PARTITION BY pk ORDER BY v) AS rn,+ dense_rank() OVER (PARTITION BY pk ORDER BY v) AS dr+ FROM window_topn_shift+ ) WHERE dr <= 1+) GROUP BY pk ORDER BY pk;+----+1 [1, 2] [1, 2]+2 [4, 5] [1, 2]++query TT+EXPLAIN SELECT pk, id, rn, dr FROM (+ SELECT pk, v, id,+ row_number() OVER (PARTITION BY pk ORDER BY v) AS rn,+ dense_rank() OVER (PARTITION BY pk ORDER BY v) AS dr+ FROM window_topn_shift+) WHERE dr <= 1;+----+physical_plan+01)ProjectionExec: expr=[pk@0 as pk, id@2 as id, row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@3 as rn, dense_rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@4 as dr]+02)--BoundedWindowAggExec: wdw=[row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, dense_rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "dense_rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]+03)----RepartitionExec: partitioning=Hash([pk@0], 4), input_partitions=1, maintains_sort_order=true+04)------PartitionedTopKExec: fn=dense_rank, fetch=1, partition=[pk@0], order=[v@1 ASC NULLS LAST]+05)--------DataSourceExec: partitions=1, partition_sizes=[1]++# A single ranking function behind a projection that drops an ORDER BY key the+# query no longer needs: rewritten.+query III+SELECT pk, id, rn FROM (+ SELECT pk, v, id, row_number() OVER (PARTITION BY pk ORDER BY v, id) AS rn+ FROM window_topn_shift+) WHERE rn <= 1 ORDER BY pk, id;+----+1 1 1+2 4 1++query TT+EXPLAIN SELECT pk, id, rn FROM (+ SELECT pk, v, id, row_number() OVER (PARTITION BY pk ORDER BY v, id) AS rn+ FROM window_topn_shift+) WHERE rn <= 1;+----+physical_plan+01)ProjectionExec: expr=[pk@0 as pk, id@2 as id, row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST, window_topn_shift.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@3 as rn]+02)--PartitionedTopKExec: fn=row_number, fetch=1, partition=[pk@0], order=[v@1 ASC NULLS LAST, id@2 ASC NULLS LAST], emit=[row_number() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST, window_topn_shift.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]+03)----DataSourceExec: partitions=1, partition_sizes=[1]++# An expression over the ranking column is substituted into the predicate,+# which is not `column <= literal`: not rewritten.+query IIR+SELECT pk, id, x FROM (+ SELECT pk, id, rank() OVER (PARTITION BY pk ORDER BY v) + 1 AS x+ FROM window_topn_shift+) WHERE x <= 2 ORDER BY pk, id;+----+1 1 2+1 2 2+2 4 2+2 5 2++query TT+EXPLAIN SELECT pk, id, x FROM (+ SELECT pk, id, rank() OVER (PARTITION BY pk ORDER BY v) + 1 AS x+ FROM window_topn_shift+) WHERE x <= 2;+----+physical_plan+01)ProjectionExec: expr=[pk@0 as pk, id@1 as id, CAST(rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@2 AS Decimal128(20, 0)) + 1 as x]+02)--RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1, maintains_sort_order=true+03)----FilterExec: CAST(rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@2 AS Decimal128(20, 0)) + 1 <= 2+04)------ProjectionExec: expr=[pk@0 as pk, id@2 as id, rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@3 as rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]+05)--------BoundedWindowAggExec: wdw=[rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "rank() PARTITION BY [window_topn_shift.pk] ORDER BY [window_topn_shift.v ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]+06)----------SortExec: expr=[pk@0 ASC NULLS LAST, v@1 ASC NULLS LAST], preserve_partitioning=[false]+07)------------DataSourceExec: partitions=1, partition_sizes=[1]++statement ok+SET datafusion.explain.physical_plan_only = false;++statement ok+SET datafusion.optimizer.enable_window_topn = false;++statement ok+DROP TABLE window_topn_shift;\ No newline at end of file