Fix excessive number of files (leads to excessive memory usage) for external ORDER BY#80777
Merged
azat merged 6 commits intoClickHouse:masterfrom May 28, 2025
Merged
Fix excessive number of files (leads to excessive memory usage) for external ORDER BY#80777azat merged 6 commits intoClickHouse:masterfrom
azat merged 6 commits intoClickHouse:masterfrom
Conversation
…xternal ORDER BY In ClickHouse#72598 the behavior of `max_bytes_before_external_sort` has been changed, it has been switched to rely on the total memory usage of the query instead of the size of a sorting data. But, the problem with this approach is that you can have a lot of memory used outside of sorting (FINAL, aggregation), and spilling sorting blocks to disk will not help reduce memory usage obviously, but it will make things even worse, because it will create lots of small files, that will require a lot of memory to merge them. So this patch reverts the behavior of `max_bytes_before_external_sort` back, now it will rely on the sorting block size.
Contributor
Set max_bytes_before_external_sort=min_external_sort_block_bytes=100Mi
The problem is that now both conditions should be met: - max_bytes_ratio_before_external_sort - max_bytes_before_external_sort So it is not possible to use max_bytes_ratio_before_external_sort=0.9, this will lead to MEMORY_LIMIT_EXCEEDED errors
Michicosun
reviewed
May 27, 2025
Michicosun
approved these changes
May 28, 2025
This was referenced May 28, 2025
robot-clickhouse-ci-1
added a commit
that referenced
this pull request
May 28, 2025
Cherry pick #80777 to 25.5: Fix excessive number of files (leads to excessive memory usage) for external ORDER BY
robot-clickhouse
added a commit
that referenced
this pull request
May 28, 2025
…ssive memory usage) for external ORDER BY
azat
added a commit
that referenced
this pull request
May 28, 2025
Backport #80777 to 25.5: Fix excessive number of files (leads to excessive memory usage) for external ORDER BY
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
May 28, 2025
Cherry pick #80777 to 25.3: Fix excessive number of files (leads to excessive memory usage) for external ORDER BY
robot-clickhouse
added a commit
that referenced
this pull request
May 28, 2025
…ssive memory usage) for external ORDER BY
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
May 28, 2025
Cherry pick #80777 to 25.4: Fix excessive number of files (leads to excessive memory usage) for external ORDER BY
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 9, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 10, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 11, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 12, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 13, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 13, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 14, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 15, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 16, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 17, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 18, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 19, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 20, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 21, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 22, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 23, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 24, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 26, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 27, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 28, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 29, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jun 29, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 3, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 4, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 5, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 6, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
baibaichen
added a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 7, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 7, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
kyligence-git
pushed a commit
to Kyligence/ClickHouse
that referenced
this pull request
Jul 8, 2025
Fix rebase issue: - 20250529 ClickHouse#80777 - 20250326 ClickHouse#77729 - 20250308 ClickHouse#77269
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix excessive number of files (leads to excessive memory usage) for external ORDER BY
In #72598 the behavior of
max_bytes_before_external_sorthas been changed, it has been switched to rely on the total memory usage of the query instead of the size of a sorting data.But, the problem with this approach is that you can have a lot of memory used outside of sorting (FINAL, aggregation), and spilling sorting blocks to disk will not help reduce memory usage obviously, but it will make things even worse, because it will create lots of small files, that will require a lot of memory to merge them.
So this patch reverts the behavior of
max_bytes_before_external_sortback, now it will rely on the sorting block size.Fixes: #72598 (cc @alexey-milovidov )