2 · MERGETREE · INSERT
run
Inserting in bundles: how many pieces
What can be seen in the lab
How to Insert
-- 10 INSERT по строке без слияний -> 10 частей
-- + один INSERT на 10 000 строк -> 11
-- в базе уже выполнен OPTIMIZE ... FINAL:
SELECT count() FROM system.parts
WHERE database = currentDatabase()
AND table = 'small_inserts' AND active; -- 1
-- пачка 10 000–100 000 строк,
-- порядка 1 INSERT в секунду
INSERT INTO events VALUES (...), (...), ...;
-- много мелких клиентов: буфер сервера
SET async_insert = 1; -- по умолчанию с 26.3
SET wait_for_async_insert = 1;
PACK
BUFFER
LIMIT
Save with the service
async_insert
Too many parts
By size or by time: 10,000–100,000 rows, about 1 INSERT per second.
The server collects small updates from many clients and sends them in a single batch.
With 1,000 active parts in a partition, the INSERT operation slows down; with 3,000, it fails.
INSERTing one row at a time from a loop is a mistake. Either batch the insert in the service (by size or by time) or enable `async_insert` and wait for confirmation.