DEV Community

Alex Spinov
Alex Spinov

Posted on

ClickHouse Has a Free Column-Oriented Database — Query Billions of Rows in Milliseconds

ClickHouse Queries Billions of Rows in Milliseconds

PostgreSQL chokes on analytical queries over 100M rows. ClickHouse handles billions — and returns results in milliseconds. Thats not a typo.

What Makes ClickHouse Fast

ClickHouse is a column-oriented OLAP database:

  • Columnar storage — reads only the columns you query
  • Vectorized execution — processes data in batches using SIMD
  • Compression — 10-40x compression ratios on real data
  • Parallel processing — uses all CPU cores for every query
  • Materialized views — pre-aggregate data on insert
  • SQL compatible — standard SQL with extensions

Quick Start

# Docker
docker run -d --name clickhouse \
  -p 8123:8123 -p 9000:9000 \
  clickhouse/clickhouse-server

# Connect
docker exec -it clickhouse clickhouse-client

# Create table
CREATE TABLE events (
  timestamp DateTime,
  user_id UInt64,
  event_type LowCardinality(String),
  properties String
) ENGINE = MergeTree()
ORDER BY (event_type, timestamp);

# Insert 1M rows in seconds
INSERT INTO events SELECT
  now() - randUniform(0, 86400*30),
  rand64() % 100000,
  arrayElement(['click,\view\,\\purchase\,\signup], rand() % 4 + 1),
  {}\
FROM numbers(1000000);

# Query — milliseconds on 1M rows
SELECT event_type, count(), uniq(user_id)
FROM events
WHERE timestamp > now() - INTERVAL 7 DAY
GROUP BY event_type;
Enter fullscreen mode Exit fullscreen mode

ClickHouse vs PostgreSQL for Analytics

Metric ClickHouse PostgreSQL
1B row aggregation ~1 second Minutes/timeout
Storage (1TB data) ~100GB ~800GB
Insert speed 1M+ rows/sec ~50K rows/sec
Concurrent analytics Locks tables
OLTP (transactions)

Free Options

  • Self-hosted: completely free, unlimited
  • ClickHouse Cloud: free tier with 10GB storage
  • chDB: embedded ClickHouse in Python (pip install chdb)

When to Use ClickHouse

✅ Analytics dashboards, log analysis, time-series data
✅ Data warehousing, BI queries, metrics aggregation
❌ OLTP workloads (use PostgreSQL)
❌ Small datasets under 1M rows (overkill)


Need fast analytics? I help teams set up ClickHouse for real-time dashboards and log analysis.

📧 spinov001@gmail.com — Analytics infrastructure consulting

Follow for more database deep dives.

Top comments (0)