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

[Enhancement] optimize the performace for topn with large offset (backport #55886) #56369

Closed
wants to merge 1 commit into from

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Feb 27, 2025

Why I'm doing:

SSB100G dop=4 1BE

select lo_shipmode from lineorder order by lo_shipmode limit 50000000, 400

baseline:1m42s patched:28s339ms

The reasons why baseline performance is too low are:
1.The merge operation is too frequent and needs to be done every 256 chunks. But the total input data is too large. This results in too many merge operations.

This PR adds max_buffer_size, which depends on offset + limit /chunk_size, to reduce the frequency of merge operations. But it may result in using more memory.
This PR additionally optimizes memory for merge chunks. It can reduce the peak memory of merge.

What I'm doing:

  1. change the max_buffered_size to chunk_size/4096 when limit greater than 65535
  2. Avoid large permutations that take up too much memory.
  3. reduce memory when merge large chunks

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

)

1. change the max_buffered_size to chunk_size/4096 when limit greater than 65535
2. Avoid large permutations that take up too much memory.
3. Reduce memory when merging large chunks

SSB100G dop=4 1BE
```
select lo_shipmode from lineorder order by lo_shipmode limit 50000000, 400
```
baseline:1m42s patched:28s339ms

The reasons why baseline performance is too low are:
1.The merge operation is too frequent and needs to be done every 256 chunks. But the total input data is too large. This results in too many merge operations.

This PR adds max_buffer_size, which depends on offset + limit /chunk_size, to reduce the frequency of merge operations. But it may result in using more memory.
This PR additionally optimizes memory for merge chunks. It can reduce the peak memory of merge.

Signed-off-by: stdpain <[email protected]>
(cherry picked from commit 11b98b0)

# Conflicts:
#	be/src/exec/chunks_sorter.cpp
#	be/src/exec/chunks_sorter.h
#	be/src/exec/chunks_sorter_topn.h
#	be/src/exec/pipeline/sort/local_partition_topn_context.cpp
#	be/src/exec/sorting/merge.h
@mergify mergify bot added the conflicts label Feb 27, 2025
Copy link
Contributor Author

mergify bot commented Feb 27, 2025

Cherry-pick of 11b98b0 has failed:

On branch mergify/bp/branch-3.3/pr-55886
Your branch is up to date with 'origin/branch-3.3'.

You are currently cherry-picking commit 11b98b0e2c.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   be/src/bench/chunks_sorter_bench.cpp
	modified:   be/src/exec/CMakeLists.txt
	modified:   be/src/exec/chunks_sorter_heap_sort.h
	modified:   be/src/exec/chunks_sorter_topn.cpp
	modified:   be/src/exec/pipeline/sort/partition_sort_sink_operator.cpp
	new file:   be/src/exec/sorting/merge.cpp
	modified:   be/src/exec/sorting/merge_cascade.cpp
	modified:   be/src/exec/sorting/merge_column.cpp
	modified:   be/src/exec/topn_node.cpp
	modified:   be/test/exec/chunks_sorter_test.cpp
	modified:   be/test/runtime/merge_cascade_test.cpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   be/src/exec/chunks_sorter.cpp
	both modified:   be/src/exec/chunks_sorter.h
	both modified:   be/src/exec/chunks_sorter_topn.h
	both modified:   be/src/exec/pipeline/sort/local_partition_topn_context.cpp
	both modified:   be/src/exec/sorting/merge.h

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Copy link
Contributor Author

mergify bot commented Feb 27, 2025

@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant