Skip to content

Commit 19dd479

Browse files
authored
Merge branch 'main' into add_group_benchmarks_count_distinct
2 parents 0617a7b + 936db37 commit 19dd479

14 files changed

Lines changed: 1941 additions & 2 deletions

File tree

benchmarks/queries/h2o/window.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ SELECT
109109
id3,
110110
v2,
111111
sum(v2) OVER (PARTITION BY id2 ORDER BY v2 RANGE BETWEEN 3 PRECEDING AND CURRENT ROW) AS my_range_between_by_id2
112-
FROM large;
112+
FROM large;
113+
114+
-- Window Top-N (ROW_NUMBER top-2 per partition)
115+
SELECT id2, largest2_v2 FROM (
116+
SELECT id2, v2 AS largest2_v2,
117+
ROW_NUMBER() OVER (PARTITION BY id2 ORDER BY v2 DESC) AS order_v2
118+
FROM large WHERE v2 IS NOT NULL
119+
) sub_query WHERE order_v2 <= 2;

datafusion/common/src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,15 @@ config_namespace! {
10871087
/// past window functions, if possible
10881088
pub enable_window_limits: bool, default = true
10891089

1090+
/// When set to true, the optimizer will replace
1091+
/// Filter(rn<=K) → Window(ROW_NUMBER) → Sort patterns with a
1092+
/// PartitionedTopKExec that maintains per-partition heaps, avoiding
1093+
/// a full sort of the input.
1094+
/// When the window partition key has low cardinality, enabling this optimization
1095+
/// can improve performance. However, for high cardinality keys, it may
1096+
/// cause regressions in both memory usage and runtime.
1097+
pub enable_window_topn: bool, default = false
1098+
10901099
/// When set to true, the optimizer will push TopK (Sort with fetch)
10911100
/// below hash repartition when the partition key is a prefix of the
10921101
/// sort key, reducing data volume before the shuffle.

datafusion/core/tests/physical_optimizer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ mod sanity_checker;
3737
#[expect(clippy::needless_pass_by_value)]
3838
mod test_utils;
3939
mod window_optimize;
40+
mod window_topn;
4041

4142
mod pushdown_utils;

0 commit comments

Comments
 (0)