1 1 2000 8 parts 100 1000 CREATE TABLE mt_{parts}_parts(id UInt32, val1 UInt32, val2 UInt32) ENGINE = MergeTree ORDER BY val1 PARTITION BY id % {parts} INSERT INTO mt_{parts}_parts SELECT number, rand() % 10000, rand() FROM numbers_mt(100000000) OPTIMIZE TABLE mt_{parts}_parts FINAL SELECT val2 FROM mt_{parts}_parts ORDER BY val1 LIMIT 10000 FORMAT Null SELECT val2 FROM mt_{parts}_parts ORDER BY val1 LIMIT 100000 FORMAT Null SELECT sum(val2) FROM mt_{parts}_parts GROUP BY val1 FORMAT Null DROP TABLE IF EXISTS mt_{parts}_parts