---
title: "Using Dictionaries to Accelerate Queries"
description: "ClickHouse dictionaries, in-memory key-value structures, can replace JOINs against small lookup tables."
url: "https://swe.quest/articles/using-dictionaries-to-accelerate-queries-fcf5f4fb14453a0d"
canonical: "https://clickhouse.com/blog/faster-queries-dictionaries-clickhouse"
source: "ClickHouse"
published: "2022-12-07"
difficulty: "medium"
kind: "How-to"
reading_minutes: 17
tags: ["query-engines","analytics","sql","performance"]
---

# Using Dictionaries to Accelerate Queries

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-12-07, 17 min read, How-to. Original: [https://clickhouse.com/blog/faster-queries-dictionaries-clickhouse](https://clickhouse.com/blog/faster-queries-dictionaries-clickhouse)

## Summary

ClickHouse dictionaries, in-memory key-value structures, can replace JOINs against small lookup tables. Using the NOAA weather dataset, a normalized INNER JOIN against a stations table forces a full scan of 1.08 billion rows because ClickHouse runs joins before WHERE filtering. Swapping in dictGet lookups alongside a primary-key-friendly subquery brings that query back to millisecond latency. The post walks through creating a dictionary, choosing a layout (flat, hashed, hashed\_array, complex\_key variants, sparse), setting LIFETIME and invalidate\_query for refreshes, and loading data, recommending hashed\_array or complex\_key\_hashed\_array for most cases.

Written by swe.quest, not by the author.

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

## Topics

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

## Prerequisites

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

## Keywords

ClickHouse, ClickHouse Cloud, dictGet, NOAA GHCN, MergeTree

## Related posts

- [Join me if you can: ClickHouse vs. Databricks vs. Snowflake - Part 2](https://swe.quest/articles/join-me-if-you-can-clickhouse-vs-databricks-vs-snowflake-part-2-66aede87450dc5eb.md): ClickHouse · 2025-06-25 · Medium · 8 min read · Analytics & OLAP, Performance engineering, Query engines, SQL
  Replacing fact-to-dimension joins with in-memory dictionaries in ClickHouse Cloud sped up a 17-query join benchmark over 1.4 billion rows by 1.9–3.5× in total runtime, up to 6.6× on individual queries, and cut cost by up to 60%.
- [ClickHouse Joins Under the Hood - Direct Join](https://swe.quest/articles/clickhouse-joins-under-the-hood-direct-join-4c5bfc57b28f012b.md): ClickHouse · 2023-06-07 · Medium · 15 min read · Query engines, Analytics & OLAP, Performance engineering, SQL
  ClickHouse's direct join is its fastest join algorithm. It applies when the right-hand table sits on storage that supports low-latency key-value lookups: the Join engine, EmbeddedRocksDB or a Dictionary.
- [ClickHouse Cloud: Fast, Updatable Lookups with the Join Table Engine](https://swe.quest/articles/clickhouse-cloud-fast-updatable-lookups-with-the-join-table-engine-b50f6e80ec781fcd.md): ClickHouse · 2026-05-12 · Medium · 6 min read · Analytics & OLAP, Databases, SQL, Cloud platforms
  ClickHouse's Join table engine keeps a precomputed in-memory hash map for a fixed join strictness, type and key.
- [DENIC Improves Query Times By 10x with ClickHouse](https://swe.quest/articles/denic-improves-query-times-by-10x-with-clickhouse-060ef54871f5e907.md): ClickHouse · 2022-05-10 · Medium · 9 min read · Analytics & OLAP, Query engines, SQL, Performance engineering, Databases
  DENIC, the .de registry, built its data science platform on ClickHouse after rejecting Hadoop and Spark as too costly to administer and cloud services for privacy reasons.
- [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.

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)
