Search terms: query optimization, PREWHERE, JOIN, dictionary, EXPLAIN, performance, slow query, memory limit, timeout, full table scan, dictGet, query cache, DELETE, UPDATE, mutation, aggregation, GROUP BY, COUNT DISTINCT, uniq, querylog
The ORDER BY clause in table definition determines query performance. ClickHouse stores data sorted by these columns and uses a sparse primary index to skip irrelevant data.
Key insight: Always filter on the leftmost ORDER BY columns first for best performance.
20+ правил оптимизации запросов ClickHouse. Загружайте при написании запросов, отладке медленных запросов, исправлении ошибок памяти или оптимизации JOIN. Выполнение запросов в 10–100 раз быстрее, использование памяти на 90 % меньше. Источник: obsessiondb/clickhouse-skills.