(id Int64, amount Float) Engine = MergeTree order by id;
insert into sample select number % 45345345, rand()/10e12 from numbers(1000000000);
-- ограничиваем использовать только 5ГБ
set max_memory_usage=5000000000
select id,max(amount) from sample group by id format Null;
DB::Exception: Memory limit (for query) exceeded: would use 4.67 GiB
(attempt to allocate chunk of 33554464 bytes), maximum: 4.66 GiB.
-- включаем группировку через диск, если памяти надо больше 3ГБ
set max_bytes_before_external_group_by = 3000000000
select id,max(amount) from sample group by id format Null;
45345345 rows in set. Elapsed: 14.645 sec. Processed 1.00 billion rows, 12.00 GB (68.28 million rows/s., 819.41 MB/s.)
-- limit конечно никак тут не поможет
select id,max(amount) from sample group by id limit 1 format Null;
Memory limit (for query) exceeded: would use 4.67 GiB (attempt to allocate chunk of 37486624 bytes), maximum: 4.66 GiB.
-- дадим 50ГБ памяти
set max_memory_usage=50000000000
set max_bytes_before_external_group_by =0
45345345 rows in set. Elapsed: 10.812 sec. Processed 1.00 billion rows, 12.00 GB (92.49 million rows/s., 1.11 GB/s.)
set send_logs_level='debug'
select id,max(amount) from sample group by id limit 1 format Null;
<Debug> MemoryTracker: Peak memory usage (for query): 10.04 GiB.
а почему не "set send_logs_level='trace'"? там ещё кол-во строк выводит!
Обсуждают сегодня