---
title: "A simple guide to ClickHouse query optimization: part 1"
description: "Slow ClickHouse queries can be diagnosed with system.query_log (duration, rows read, memory, CPU, cache metrics) and the EXPLAIN statement, illustrated on the NYC Taxi dataset in the ClickHouse Playground."
url: "https://swe.quest/articles/a-simple-guide-to-clickhouse-query-optimization-part-1-007f8d8516577455"
canonical: "https://clickhouse.com/blog/a-simple-guide-to-clickhouse-query-optimization-part-1"
source: "ClickHouse"
published: "2024-12-11"
difficulty: "medium"
kind: "How-to"
reading_minutes: 20
tags: ["analytics","performance","sql","query-engines"]
---

# A simple guide to ClickHouse query optimization: part 1

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2024-12-11, 20 min read, How-to. Original: [https://clickhouse.com/blog/a-simple-guide-to-clickhouse-query-optimization-part-1](https://clickhouse.com/blog/a-simple-guide-to-clickhouse-query-optimization-part-1)

## Summary

Slow ClickHouse queries can be diagnosed with system.query\_log (duration, rows read, memory, CPU, cache metrics) and the EXPLAIN statement, illustrated on the NYC Taxi dataset in the ClickHouse Playground. A table created with an inferred schema (all Nullable columns, empty ORDER BY) forces every example query into a full scan of 329 million rows taking over a second and roughly 400–550 MiB of memory. Turning off the filesystem cache makes timings reproducible. The first part of the series then moves to basic optimizations and choosing primary keys so ClickHouse can skip data instead of scanning it.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)

## Prerequisites

- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- OLAP database concepts ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, system.query\_log, EXPLAIN, MergeTree, ClickHouse Cloud, NYC Taxi dataset

## Related posts

- [Top 10 best practices tips for ClickHouse](https://swe.quest/articles/top-10-best-practices-tips-for-clickhouse-4df5699bf7bd75dd.md): ClickHouse · 2026-03-26 · Medium · 21 min read · Analytics & OLAP, Performance engineering, Databases, SQL
  Ten practices for getting performance and storage efficiency out of ClickHouse, each measured on a 150M-row Amazon reviews dataset.
- [ClickHouse Newsletter May 2022: Explain Statement – Query Optimization](https://swe.quest/articles/clickhouse-newsletter-may-2022-explain-statement-query-optimization-a636e0c953208fbf.md): ClickHouse · 2022-05-09 · Medium · 8 min read · Query engines, Analytics & OLAP, Performance engineering, SQL
  ClickHouse's May 2022 newsletter centers on using EXPLAIN for query optimization.
- [Super charging your ClickHouse queries](https://swe.quest/articles/super-charging-your-clickhouse-queries-55ad4f3a6c2fa875.md): ClickHouse · 2022-12-15 · Medium · 15 min read · Analytics & OLAP, Performance engineering, Query engines, SQL
  ClickHouse query speed comes mainly from reading less data: a sparse primary index stores one entry per 8192-row granule and lets binary search skip blocks that can't match the WHERE clause.
- [Introducing the ClickHouse Query Cache](https://swe.quest/articles/introducing-the-clickhouse-query-cache-4c8e8c32056d93c8.md): ClickHouse · 2023-02-09 · Medium · 9 min read · Caching, Analytics & OLAP, Databases, Performance engineering
  ClickHouse v23.1 adds an experimental query cache that stores results of expensive SELECT queries for a configurable TTL (60 s by default), cutting a 9-second aggregation over 3.1 billion GitHub events to 0.04 s on repeat runs.
- [How we made ClickStack 5x faster for ClickHouse observability](https://swe.quest/articles/how-we-made-clickstack-5x-faster-for-clickhouse-observability-ed934241e77977aa.md): ClickHouse · 2026-07-02 · Hard · 22 min read · Observability, Analytics & OLAP, Performance engineering, Query engines, Storage engines
  ClickStack's OpenTelemetry logs schema, inherited from the ClickHouse exporter for the OTel Collector, was reworked through a benchmark-driven process.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
