Skip to content

perf: sort window rows in place#376

Merged
KKould merged 1 commit into
mainfrom
perf/window-inline-sort
Jul 13, 2026
Merged

perf: sort window rows in place#376
KKould merged 1 commit into
mainfrom
perf/window-inline-sort

Conversation

@KKould

@KKould KKould commented Jul 13, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Window execution currently depends on a separate Sort executor. Sort materializes the input before Window buffers it again, creating an unnecessary second materialization for window queries.

Issue link: N/A

What is changed and how it works?

  • Changes the shared tuple sorter to sort an existing row buffer in place.
  • Lets the Window executor collect, sort, partition, evaluate, and emit rows from the same buffer.
  • Stores partition and ordering fields once in WindowOperator, with the partition field count identifying the boundary.
  • Reports the ordering produced by Window directly in its physical sort option, so plans no longer contain standalone Sort nodes for window specifications.
  • Keeps separate Window operators for different window specifications, with each operator applying its own ordering.

Code changes

  • Has Rust code change
  • Has CI related scripts change

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

The coverage verifies in-place tuple ordering, Window executor partition and peer evaluation, ranking and aggregate window results, multiple window specifications, and Explain plans without standalone Sort nodes.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Note for reviewer

Window remains a blocking operator because it must order its input, but it now performs that ordering in its own row buffer instead of materializing rows in both Sort and Window.

@KKould KKould added the enhancement New feature or request label Jul 13, 2026
@KKould KKould self-assigned this Jul 13, 2026
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.11321% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.85%. Comparing base (c19209e) to head (52bda81).

Files with missing lines Patch % Lines
src/execution/dql/sort.rs 96.29% 2 Missing ⚠️
src/execution/dql/window.rs 97.56% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #376   +/-   ##
=======================================
  Coverage   92.84%   92.85%           
=======================================
  Files         249      249           
  Lines       41790    41844   +54     
=======================================
+ Hits        38802    38856   +54     
  Misses       2988     2988           
Flag Coverage Δ
rust 92.85% <98.11%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/binder/window.rs 95.89% <100.00%> (-0.22%) ⬇️
src/execution/dql/window/function.rs 97.22% <100.00%> (ø)
src/optimizer/heuristic/optimizer.rs 97.09% <100.00%> (ø)
src/optimizer/rule/implementation/dql/window.rs 100.00% <100.00%> (ø)
src/planner/operator/mod.rs 95.81% <100.00%> (ø)
src/planner/operator/visitor.rs 98.93% <100.00%> (+<0.01%) ⬆️
src/planner/operator/visitor_mut.rs 99.66% <100.00%> (ø)
src/planner/operator/window.rs 89.47% <100.00%> (+4.85%) ⬆️
src/execution/dql/window.rs 98.98% <97.56%> (-1.02%) ⬇️
src/execution/dql/sort.rs 87.83% <96.29%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KKould KKould merged commit 3f0df6f into main Jul 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant