v.24.12Improvement

Automatic Disk-Based GROUP BY/ORDER BY Based on Memory Usage

Automatic GROUP BY/ORDER BY to disk based on the server/user memory usage. Controlled with max_bytes_ratio_before_external_group_by/max_bytes_ratio_before_external_sort query settings. #71406 (Azat Khuzhin).
Automatic spilling of GROUP BY and ORDER BY operations to disk based on server or user memory usage limits.

Why it matters

This feature addresses memory pressure issues by enabling ClickHouse to automatically offload GROUP BY and ORDER BY computations to disk when memory consumption approaches specified thresholds. It helps prevent query failures due to out-of-memory errors and improves query stability and reliability under heavy loads or large datasets.

How to use it

Users can control this automatic spilling behavior via the query settings max_bytes_ratio_before_external_group_by and max_bytes_ratio_before_external_sort. Adjust these values to set memory usage ratios at which GROUP BY and ORDER BY operations will start writing intermediate data to disk.