Skip to content

Commit eebba16

Browse files
cool9850311claude
andcommitted
fix: add stacked windows' lookaheads instead of taking the max
`grow_limit` folded each window's lookahead into the chain's with `max_lookahead`, but a window reads ahead of every row the windows above it need, so the lookaheads of stacked windows add. Taking the max leaves the sort below short of the rows the inner window needs, and the last rows of the result are computed over a truncated frame. Expressions within one window do share a lookahead, and `WindowLookahead` has already taken the maximum over those. `window_limits.slt` gets a case for each of the two shapes this reaches. SELECT empno, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2 FROM (SELECT empno, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees) ORDER BY empno LIMIT 3; Two windows on one chain above a single sort. The sort needs 3 + 1 + 2 rows and got 3 + max(1, 2), so the third row's `s2` came back 11103612124 instead of 15119054465. `main` gets this shape wrong as well: its early stop kept the walk out of the subtree below a sort it had already given a fetch to, never out of a second window on the same chain. The other shape puts an `ORDER BY ... LIMIT` between the two levels, so the outer limit is spent on a sort and the walk starts a new chain at the inner limit. That one is reachable only once applying a fetch stops ending the walk, which is `fix: push a limit past every window in a plan, not just the first` in this series. @jayzhan211 found it in review; the fix here is their patch. Five `EXPLAIN`s in `window.slt` raise their fetch by 1 to 5 rows. Adding is a safe upper bound but an over-estimate when the outer window does not read the inner window's output, and all five are that shape: both windows in each of them read `c9`. Telling the two apart needs the columns each window reads traced through the projections between them, which is a separate change. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 2039643 commit eebba16

3 files changed

Lines changed: 143 additions & 11 deletions

File tree

‎datafusion/physical-optimizer/src/limit_pushdown_past_window.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ impl TraverseState {
5252
self.lookahead = 0;
5353
self.phase = Phase::FindOrGrow;
5454
}
55-
56-
pub fn max_lookahead(&mut self, new_val: usize) {
57-
self.lookahead = self.lookahead.max(new_val);
58-
}
5955
}
6056

6157
impl PhysicalOptimizerRule for LimitPushPastWindows {
@@ -145,11 +141,17 @@ fn grow_limit(lookahead: Option<WindowLookahead>, ctx: &mut TraverseState) -> bo
145141
if let (Some(min_rows), Some(cur)) = (lookahead.min_rows, ctx.limit) {
146142
ctx.limit = Some(cur.max(min_rows));
147143
}
148-
ctx.max_lookahead(lookahead.frame_end);
144+
// A window reads ahead of every row the windows above it need, so stacked
145+
// windows add their lookaheads. Expressions within one window share theirs,
146+
// which `WindowLookahead` has already taken the maximum over.
147+
//
149148
// Frame bounds come straight from the query and can be as large as
150149
// `u64::MAX`, so saturate instead of overflowing. A saturated lookahead
151150
// makes the `checked_add` in `apply_limit` fail, which skips the pushdown.
152-
ctx.max_lookahead(ctx.lookahead.saturating_add(lookahead.relative));
151+
ctx.lookahead = ctx
152+
.lookahead
153+
.saturating_add(lookahead.frame_end)
154+
.saturating_add(lookahead.relative);
153155
true
154156
}
155157

‎datafusion/sqllogictest/test_files/window.slt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ physical_plan
13311331
02)--GlobalLimitExec: skip=0, fetch=5
13321332
03)----BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 5 PRECEDING AND 1 FOLLOWING], mode=[Sorted]
13331333
04)------BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING], mode=[Sorted]
1334-
05)--------SortExec: TopK(fetch=10), expr=[c9@0 DESC], preserve_partitioning=[false]
1334+
05)--------SortExec: TopK(fetch=11), expr=[c9@0 DESC], preserve_partitioning=[false]
13351335
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c9], file_type=csv, has_header=true
13361336

13371337
query III
@@ -1374,7 +1374,7 @@ physical_plan
13741374
02)--GlobalLimitExec: skip=0, fetch=5
13751375
03)----BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 5 PRECEDING AND 1 FOLLOWING], mode=[Sorted]
13761376
04)------BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING], mode=[Sorted]
1377-
05)--------SortExec: TopK(fetch=10), expr=[c9@0 DESC], preserve_partitioning=[false]
1377+
05)--------SortExec: TopK(fetch=11), expr=[c9@0 DESC], preserve_partitioning=[false]
13781378
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c9], file_type=csv, has_header=true
13791379

13801380
# ensure limit pushdown can handle bigger preceding instead of following
@@ -1434,7 +1434,7 @@ physical_plan
14341434
02)--GlobalLimitExec: skip=5, fetch=5
14351435
03)----BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 5 PRECEDING AND 1 FOLLOWING], mode=[Sorted]
14361436
04)------BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING], mode=[Sorted]
1437-
05)--------SortExec: TopK(fetch=15), expr=[c9@0 DESC], preserve_partitioning=[false]
1437+
05)--------SortExec: TopK(fetch=16), expr=[c9@0 DESC], preserve_partitioning=[false]
14381438
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c9], file_type=csv, has_header=true
14391439

14401440
query III
@@ -1729,7 +1729,7 @@ physical_plan
17291729
02)--GlobalLimitExec: skip=0, fetch=5
17301730
03)----BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) PARTITION BY [aggregate_test_100.c1] ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) PARTITION BY [aggregate_test_100.c1] ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING], mode=[Sorted]
17311731
04)------BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING], mode=[Sorted]
1732-
05)--------SortExec: TopK(fetch=10), expr=[c1@0 ASC NULLS LAST, c9@1 DESC], preserve_partitioning=[false]
1732+
05)--------SortExec: TopK(fetch=15), expr=[c1@0 ASC NULLS LAST, c9@1 DESC], preserve_partitioning=[false]
17331733
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1, c9], file_type=csv, has_header=true
17341734

17351735

@@ -1773,7 +1773,7 @@ physical_plan
17731773
02)--GlobalLimitExec: skip=0, fetch=5
17741774
03)----BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) PARTITION BY [aggregate_test_100.c1] ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) PARTITION BY [aggregate_test_100.c1] ORDER BY [aggregate_test_100.c9 ASC NULLS LAST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 5 PRECEDING AND 1 FOLLOWING], mode=[Sorted]
17751775
04)------BoundedWindowAggExec: wdw=[sum(aggregate_test_100.c9) PARTITION BY [aggregate_test_100.c1] ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING: Field { "sum(aggregate_test_100.c9) PARTITION BY [aggregate_test_100.c1] ORDER BY [aggregate_test_100.c9 DESC NULLS FIRST] ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN 1 PRECEDING AND 5 FOLLOWING], mode=[Sorted]
1776-
05)--------SortExec: TopK(fetch=10), expr=[c1@0 ASC NULLS LAST, c9@1 DESC], preserve_partitioning=[false]
1776+
05)--------SortExec: TopK(fetch=11), expr=[c1@0 ASC NULLS LAST, c9@1 DESC], preserve_partitioning=[false]
17771777
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1, c9], file_type=csv, has_header=true
17781778

17791779
query III

‎datafusion/sqllogictest/test_files/window_limits.slt‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,3 +1178,133 @@ physical_plan
11781178
06)----------BoundedWindowAggExec: wdw=[sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": nullable UInt64 }, frame: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]
11791179
07)------------SortExec: TopK(fetch=5), expr=[empno@0 ASC NULLS LAST], preserve_partitioning=[false]
11801180
08)--------------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100_with_dates.csv]]}, projection=[empno, salary], file_type=csv, has_header=true
1181+
1182+
# Stacked windows add their lookaheads, they do not take the max. An outer window
1183+
# reads the inner window's output column, so every row the outer window reads
1184+
# ahead is a row the inner window must have computed correctly -- which needs the
1185+
# inner window's own lookahead on top. Taking the max leaves the inner sort a row
1186+
# short and the last row of the result is computed over a truncated frame.
1187+
#
1188+
# The outer `LIMIT 3` here is spent on the SortExec that orders by `salary`, and
1189+
# the walk then starts a new chain at the inner `LIMIT 3`. That makes this shape
1190+
# reachable only once applying a fetch stops ending the walk, which is the first
1191+
# commit in this PR. Three properties are load-bearing: `s2` must read `s1`, or
1192+
# the max is enough and the case does not fail; the two frames must end at
1193+
# different offsets (1 and 2), or the max and the sum agree; and the outer
1194+
# window's frame must end at the current row so it adds no lookahead of its own.
1195+
1196+
statement ok
1197+
set datafusion.optimizer.enable_window_limits = false;
1198+
1199+
query IIII
1200+
SELECT empno, salary, s2, sum(empno) OVER (ORDER BY salary ROWS UNBOUNDED PRECEDING) AS s3
1201+
FROM (
1202+
SELECT empno, salary, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2
1203+
FROM (SELECT empno, salary, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees)
1204+
ORDER BY empno LIMIT 3
1205+
)
1206+
ORDER BY salary LIMIT 3;
1207+
----
1208+
299 28774375 8936059064 299
1209+
363 1865307672 15119054465 662
1210+
102 3276123488 7621804701 764
1211+
1212+
statement ok
1213+
set datafusion.optimizer.enable_window_limits = true;
1214+
1215+
query IIII
1216+
SELECT empno, salary, s2, sum(empno) OVER (ORDER BY salary ROWS UNBOUNDED PRECEDING) AS s3
1217+
FROM (
1218+
SELECT empno, salary, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2
1219+
FROM (SELECT empno, salary, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees)
1220+
ORDER BY empno LIMIT 3
1221+
)
1222+
ORDER BY salary LIMIT 3;
1223+
----
1224+
299 28774375 8936059064 299
1225+
363 1865307672 15119054465 662
1226+
102 3276123488 7621804701 764
1227+
1228+
query TT
1229+
EXPLAIN
1230+
SELECT empno, salary, s2, sum(empno) OVER (ORDER BY salary ROWS UNBOUNDED PRECEDING) AS s3
1231+
FROM (
1232+
SELECT empno, salary, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2
1233+
FROM (SELECT empno, salary, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees)
1234+
ORDER BY empno LIMIT 3
1235+
)
1236+
ORDER BY salary LIMIT 3;
1237+
----
1238+
logical_plan
1239+
01)Sort: employees.salary ASC NULLS LAST, fetch=3
1240+
02)--Projection: employees.empno, employees.salary, s2, sum(employees.empno) ORDER BY [employees.salary ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW AS s3
1241+
03)----WindowAggr: windowExpr=[[sum(CAST(employees.empno AS Int64)) ORDER BY [employees.salary ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]]
1242+
04)------Sort: employees.empno ASC NULLS LAST, fetch=3
1243+
05)--------Projection: employees.empno, employees.salary, sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING AS s2
1244+
06)----------WindowAggr: windowExpr=[[sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING]]
1245+
07)------------Projection: employees.empno, employees.salary, sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING AS s1
1246+
08)--------------WindowAggr: windowExpr=[[sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING]]
1247+
09)----------------TableScan: employees projection=[empno, salary]
1248+
physical_plan
1249+
01)ProjectionExec: expr=[empno@0 as empno, salary@1 as salary, s2@2 as s2, sum(employees.empno) ORDER BY [employees.salary ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@3 as s3]
1250+
02)--GlobalLimitExec: skip=0, fetch=3
1251+
03)----BoundedWindowAggExec: wdw=[sum(employees.empno) ORDER BY [employees.salary ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "sum(employees.empno) ORDER BY [employees.salary ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": nullable Int64 }, frame: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]
1252+
04)------SortExec: TopK(fetch=3), expr=[salary@1 ASC NULLS LAST], preserve_partitioning=[false]
1253+
05)--------ProjectionExec: expr=[empno@0 as empno, salary@1 as salary, sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING@3 as s2]
1254+
06)----------GlobalLimitExec: skip=0, fetch=3
1255+
07)------------BoundedWindowAggExec: wdw=[sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING: Field { "sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING], mode=[Sorted]
1256+
08)--------------ProjectionExec: expr=[empno@0 as empno, salary@1 as salary, sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING@2 as s1]
1257+
09)----------------BoundedWindowAggExec: wdw=[sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING: Field { "sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING], mode=[Sorted]
1258+
10)------------------SortExec: TopK(fetch=6), expr=[empno@0 ASC NULLS LAST], preserve_partitioning=[false]
1259+
11)--------------------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100_with_dates.csv]]}, projection=[empno, salary], file_type=csv, has_header=true
1260+
1261+
# The same arithmetic with nothing in between: both windows sit on one chain
1262+
# above a single sort. `main` already gets this shape wrong, because its early
1263+
# stop only kept the walk out of the subtree below a sort it had given a fetch
1264+
# to -- it never stopped the walk from passing two windows in a row.
1265+
1266+
statement ok
1267+
set datafusion.optimizer.enable_window_limits = false;
1268+
1269+
query II
1270+
SELECT empno, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2
1271+
FROM (SELECT empno, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees)
1272+
ORDER BY empno LIMIT 3;
1273+
----
1274+
102 7621804701
1275+
299 8936059064
1276+
363 15119054465
1277+
1278+
statement ok
1279+
set datafusion.optimizer.enable_window_limits = true;
1280+
1281+
query II
1282+
SELECT empno, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2
1283+
FROM (SELECT empno, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees)
1284+
ORDER BY empno LIMIT 3;
1285+
----
1286+
102 7621804701
1287+
299 8936059064
1288+
363 15119054465
1289+
1290+
query TT
1291+
EXPLAIN
1292+
SELECT empno, sum(s1) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s2
1293+
FROM (SELECT empno, sum(salary) OVER (ORDER BY empno ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) AS s1 FROM employees)
1294+
ORDER BY empno LIMIT 3;
1295+
----
1296+
logical_plan
1297+
01)Sort: employees.empno ASC NULLS LAST, fetch=3
1298+
02)--Projection: employees.empno, sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING AS s2
1299+
03)----WindowAggr: windowExpr=[[sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING]]
1300+
04)------Projection: employees.empno, sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING AS s1
1301+
05)--------WindowAggr: windowExpr=[[sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING]]
1302+
06)----------TableScan: employees projection=[empno, salary]
1303+
physical_plan
1304+
01)ProjectionExec: expr=[empno@0 as empno, sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING@2 as s2]
1305+
02)--GlobalLimitExec: skip=0, fetch=3
1306+
03)----BoundedWindowAggExec: wdw=[sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING: Field { "sum(s1) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING], mode=[Sorted]
1307+
04)------ProjectionExec: expr=[empno@0 as empno, sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING@2 as s1]
1308+
05)--------BoundedWindowAggExec: wdw=[sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING: Field { "sum(employees.salary) ORDER BY [employees.empno ASC NULLS LAST] ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING": nullable UInt64 }, frame: ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING], mode=[Sorted]
1309+
06)----------SortExec: TopK(fetch=6), expr=[empno@0 ASC NULLS LAST], preserve_partitioning=[false]
1310+
07)------------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100_with_dates.csv]]}, projection=[empno, salary], file_type=csv, has_header=true

0 commit comments

Comments
 (0)