---
title: "Optimizing ClickHouse with Schemas and Codecs"
description: "Tightening a ClickHouse schema with strict types cuts a 1B-row NOAA weather dataset from 131.58 GiB to 71.38 GiB uncompressed."
url: "https://swe.quest/articles/optimizing-clickhouse-with-schemas-and-codecs-795411feff5942b1"
canonical: "https://clickhouse.com/blog/optimize-clickhouse-codecs-compression-schema"
source: "ClickHouse"
published: "2022-12-14"
difficulty: "medium"
kind: "How-to"
reading_minutes: 23
tags: ["analytics","storage-engines","performance","sql"]
---

# Optimizing ClickHouse with Schemas and Codecs

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-12-14, 23 min read, How-to. Original: [https://clickhouse.com/blog/optimize-clickhouse-codecs-compression-schema](https://clickhouse.com/blog/optimize-clickhouse-codecs-compression-schema)

## Summary

Tightening a ClickHouse schema with strict types cuts a 1B-row NOAA weather dataset from 131.58 GiB to 71.38 GiB uncompressed. The changes are right-sized integers instead of Int64, Int16 elevation, an Enum8 for weather type, LowCardinality for ~100k-value strings, and Float32 lat/lon in place of a Point. Compressed size moves less, from 4.07 GiB to 3.83 GiB, but smaller uncompressed data lowers RAM use and improves CPU cache efficiency at query time. Each step is checked against per-column system.columns stats and a benchmark query, before moving on to tuning column codecs for the largest columns such as date and temperatures.

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)
- [Storage engines](https://swe.quest/tags/storage-engines.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

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

## Keywords

ClickHouse, MergeTree, LowCardinality, ZSTD, ClickHouse Cloud, NOAA

## Related posts

- [ClickHouse Release 23.9](https://swe.quest/articles/clickhouse-release-23-9-73e8083c92226065.md): ClickHouse · 2023-10-24 · Medium · 12 min read · Analytics & OLAP, Databases, Storage engines, Identity & auth
  ClickHouse 23.9 ships 20 new features, 19 performance optimisations and 55 bug fixes, highlighted by JSON schema type inference, a GCD compression codec and SSH key authentication.
- [Compressing nginx logs 170x with column storage](https://swe.quest/articles/compressing-nginx-logs-170x-with-column-storage-f7055f56d674ca49.md): ClickHouse · 2025-10-23 · Medium · 14 min read · Analytics & OLAP, Observability, Storage engines, Cost optimization
  Parsing nginx access logs into typed columns in ClickHouse and tuning storage raises compression from roughly 38x (ZSTD on the raw file) to about 178x on a 66.7M-line, 20 GB dataset.
- [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.
- [AI doesn’t always generate perfect ClickHouse schemas (yet)](https://swe.quest/articles/ai-doesn-t-always-generate-perfect-clickhouse-schemas-yet-fd8dcf025b9d0fa8.md): ClickHouse · 2026-03-13 · Medium · 10 min read · Analytics & OLAP, Databases, LLMs, Performance engineering
  LLM-generated ClickHouse schemas tend to over-optimize from day one with custom partitioning, per-column codecs, projections and materialized views that can hurt at production scale.
- [ClickHouse Release 24.6](https://swe.quest/articles/clickhouse-release-24-6-003c18b45227c882.md): ClickHouse · 2024-07-11 · Medium · 15 min read · Analytics & OLAP, Storage engines, Python, Performance engineering
  ClickHouse 24.6 adds an optimize\_row\_order setting for plain MergeTree tables.

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)
