Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(query): partition sort spill #16987

Merged
merged 30 commits into from
Dec 12, 2024

Conversation

forsaken628
Copy link
Collaborator

@forsaken628 forsaken628 commented Dec 3, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Implemente TransformStreamSortSpill.

  1. In the previous implementation, the spill phase would immediately spill to storage when it received a data block, but in this PR, it is changed to buffer a batch, sort it first, and then spill to storage.
  2. The spill phase samples the data blocks proportionally and determines the partition boundaries from them.
  3. The restore phase restores and sorts according to the partition order, avoiding unnecessary IO as much as possible.
  4. Unimplemented optimization: lazy spill, i.e., delaying the timing of the spill to fully utilize all available memory and avoid unnecessary IO.
  5. Unimplemented optimization: sort row rebuild, i.e., discard sort row columns during spill and rebuild them during restore to reduce IO.
  6. Unimplemented optimization: memory centralization, centralized memory is better for reducing IO than scattered memory.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
x
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
x
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Dec 3, 2024
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
Signed-off-by: coldWater <[email protected]>
@forsaken628 forsaken628 added the ci-cloud Build docker image for cloud test label Dec 5, 2024
@wubx wubx mentioned this pull request Dec 5, 2024
3 tasks
Copy link
Contributor

github-actions bot commented Dec 5, 2024

Docker Image for PR

  • tag: pr-16987-e723c92-1733388924

note: this image tag is only available for internal use,
please check the internal doc for more details.

@forsaken628
Copy link
Collaborator Author

forsaken628 commented Dec 5, 2024

benchmark:

data set
tpch_sf_100

sql

EXPLAIN ANALYZE SELECT * FROM customer ORDER BY c_custkey,c_nationkey ignore_result;

settings

set max_threads = 3;
set sort_spilling_bytes_threshold_per_proc = 1024*1024*500;

this pr
version: pr-16987-e723c92-1733388924
size: XSmall
total execution time: 75.3s
estimated rows: 15000000.00
cpu time: 26.781757575s
wait time: 94.645316229s
output rows: 15 million
output bytes: 3.05 GiB
numbers remote spilled by write: 443
bytes remote spilled by write: 1.32 GiB
remote spilled time by write: 74.059s
numbers remote spilled by read: 443
bytes remote spilled by read: 1.32 GiB
remote spilled time by read: 37.55s

main
version: Databend Query v1.2.668-nightly-35c1c24742(rust-1.81.0-nightly-2024-12-02T06:44:39.368245594Z)
size: XSmall
total execution time: 124.6s
estimated rows: 15000000.00
cpu time: 51.686441524s
wait time: 201.063679221s
output rows: 15 million
output bytes: 3.04 GiB
numbers remote spilled by write: 965
bytes remote spilled by write: 2.90 GiB
remote spilled time by write: 154.229s
numbers remote spilled by read: 965
bytes remote spilled by read: 2.90 GiB
remote spilled time by read: 84.61s


lazy spill
version: pr-16987-aa68ff9-1733728820
size: XSmall
total execution time: 60.2s
estimated rows: 15000000.00
cpu time: 25.603120611s
wait time: 67.799707406s
output rows: 15 million
output bytes: 3.09 GiB
numbers remote spilled by write: 411
bytes remote spilled by write: 1.21 GiB
remote spilled time by write: 53.808s
numbers remote spilled by read: 411
bytes remote spilled by read: 1.21 GiB
remote spilled time by read: 29.813s

@forsaken628 forsaken628 requested review from sundy-li and Dousir9 and removed request for sundy-li December 6, 2024 02:22
@forsaken628 forsaken628 marked this pull request as ready for review December 6, 2024 02:22
remove sort_desc parameter from various sorting functions and implementations.
Adjusted implementations of `Rows` and `SortAlgorithm` traits to eliminate unnecessary `Send` bounds.
sort_row_offset.
@forsaken628 forsaken628 added ci-cloud Build docker image for cloud test and removed ci-cloud Build docker image for cloud test labels Dec 7, 2024
Copy link
Contributor

github-actions bot commented Dec 7, 2024

Docker Image for PR

  • tag: pr-16987-c00c0cd-1733579081

note: this image tag is only available for internal use,
please check the internal doc for more details.

@forsaken628 forsaken628 added ci-cloud Build docker image for cloud test and removed ci-cloud Build docker image for cloud test labels Dec 9, 2024
Copy link
Contributor

github-actions bot commented Dec 9, 2024

Docker Image for PR

  • tag: pr-16987-aa68ff9-1733728820

note: this image tag is only available for internal use,
please check the internal doc for more details.

@sundy-li sundy-li self-requested a review December 11, 2024 01:46
@forsaken628 forsaken628 added the ci-benchmark Benchmark: run all test label Dec 11, 2024
Copy link
Contributor

Docker Image for PR

  • tag: pr-16987-e55e2c0-1733890235

note: this image tag is only available for internal use,
please check the internal doc for more details.

@forsaken628 forsaken628 removed the ci-benchmark Benchmark: run all test label Dec 11, 2024
@sundy-li sundy-li added this pull request to the merge queue Dec 12, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request Dec 12, 2024
@BohuTANG BohuTANG merged commit 236fcc4 into databendlabs:main Dec 12, 2024
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-cloud Build docker image for cloud test pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants