---
title: "Super charging your ClickHouse queries"
description: "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."
url: "https://swe.quest/articles/super-charging-your-clickhouse-queries-55ad4f3a6c2fa875"
canonical: "https://clickhouse.com/blog/clickhouse-faster-queries-with-projections-and-primary-indexes"
source: "ClickHouse"
published: "2022-12-15"
difficulty: "medium"
kind: "How-to"
reading_minutes: 15
tags: ["analytics","performance","query-engines","sql"]
---

# Super charging your ClickHouse queries

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-12-15, 15 min read, How-to. Original: [https://clickhouse.com/blog/clickhouse-faster-queries-with-projections-and-primary-indexes](https://clickhouse.com/blog/clickhouse-faster-queries-with-projections-and-primary-indexes)

## Summary

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. On the 27.6M-row UK property dataset, re-sorting a copy of the table by (town, price) cuts a full scan to 81.92 thousand rows, and optimize\_read\_in\_order removes the in-memory sort and stops early under LIMIT. Projections do the same job automatically, as hidden tables kept in sync with the main table that can use a different sort order or pre-computed aggregates (backed by AggregatingMergeTree). ClickHouse picks the cheapest projection at query time. Raising query-engine parallelism is the third tuning knob.

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)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

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

## Keywords

ClickHouse, MergeTree, Projections, AggregatingMergeTree, optimize\_read\_in\_order, Materialized Views

## Related posts

- [ClickHouse projections now behave like true secondary indexes](https://swe.quest/articles/clickhouse-projections-now-behave-like-true-secondary-indexes-0baa9f93cd285ce3.md): ClickHouse · 2026-01-13 · Medium · 6 min read · Analytics & OLAP, Query engines, Storage engines, Performance engineering
  ClickHouse lightweight projections, which store only a sorting key plus a \_part\_offset pointer into the base table, now act as true secondary indexes with granule-level pruning instead of only pruning whole parts.
- [Index-based pruning in ClickHouse](https://swe.quest/articles/index-based-pruning-in-clickhouse-5952b67ba993450d.md): ClickHouse · 2026-04-15 · Medium · 21 min read · Analytics & OLAP, Query engines, Storage engines, Performance engineering
  ClickHouse offers three index-based ways to skip data: the sparse primary index (one entry per 8,192-row granule), lightweight projections that store only a sort key plus a \_part\_offset pointer into the base table, and skip indexes such as minmax that keep per-granule min/max values.
- [ClickHouse Release 25.12](https://swe.quest/articles/clickhouse-release-25-12-e571148b4347f1f0.md): ClickHouse · 2026-01-14 · Hard · 18 min read · Query engines, Analytics & OLAP, Performance engineering, Databases
  ClickHouse 25.12 ships 26 features, 31 performance optimizations and 129 bug fixes, led by three query-engine speedups.
- [ClickHouse gets lazier (and faster): Introducing lazy materialization](https://swe.quest/articles/clickhouse-gets-lazier-and-faster-introducing-lazy-materialization-c876250ed7371b97.md): ClickHouse · 2025-04-22 · Medium · 18 min read · Query engines, Analytics & OLAP, Performance engineering, Storage engines
  ClickHouse 25.4 adds lazy materialization, which defers reading column data until the query plan actually needs it.
- [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.

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)
