Databases 7 min read

How ClickHouse Cut MySQL Query Time 200× – A Practical Migration Guide

This article introduces ClickHouse, compares column‑ and row‑oriented storage, explains a real‑world migration from MySQL to ClickHouse that reduced a 3‑minute query to under one second, details installation, migration methods, performance results, synchronization options, and common pitfalls.

ITPUB
ITPUB
ITPUB
How ClickHouse Cut MySQL Query Time 200× – A Practical Migration Guide

What is ClickHouse?

ClickHouse is a column‑oriented DBMS designed for online analytical processing (OLAP).

It was open‑sourced by Yandex and can process billions of rows per second, far faster than traditional row‑based databases.

ClickHouse overview
ClickHouse overview

Business Problem

Our application stored a 50 million‑row table plus two auxiliary tables in MySQL. A single join query took over 3 minutes. After indexing, sharding, and logical optimizations the performance was still unsatisfactory, so we migrated to ClickHouse.

After migration the query time dropped to under 1 second, a 200‑fold improvement.

ClickHouse Practice

1. Installing ClickHouse on macOS

We used the Docker image for quick setup; building from source is also possible.

2. Data migration from MySQL to ClickHouse

ClickHouse supports most MySQL syntax, and five migration approaches are available:

create table engine mysql – keep data in MySQL

insert‑into‑select – create table first, then import

create‑table‑as‑select – create and import in one step

offline CSV import

streamsets – real‑time sync via binlog

We chose the third method (CREATE TABLE AS SELECT) and executed the following statement:

CREATE TABLE [IF NOT EXISTS] [db.]table_name ENGINE = Mergetree AS SELECT * FROM mysql('host:port','db','database','user','password')

3. Performance comparison

On a 50 million‑row dataset (≈10 GB in MySQL, 600 MB in ClickHouse) the MySQL query took 205 seconds, while ClickHouse returned the result in less than one second.

Row‑oriented storage diagram
Row‑oriented storage diagram
Column‑oriented storage diagram
Column‑oriented storage diagram

4. Data synchronization strategies

1) Temporary table

Load the full MySQL dataset into a temporary ClickHouse table, then swap it with the production table. Suitable for moderate data volumes and frequent incremental changes.

Temporary table sync diagram
Temporary table sync diagram

2) synch

Use the open‑source synch tool, which reads MySQL binlog events, converts them to SQL, and pushes them to ClickHouse via a message queue.

Synch architecture diagram
Synch architecture diagram

5. Why ClickHouse is fast

Only the columns required for a query are read, reducing I/O.

Columnar storage enables high compression (up to ten‑fold), further lowering I/O.

Specialized storage engines apply adaptive indexing and search algorithms.

Pitfalls

1. Data type differences

Some MySQL queries fail in ClickHouse; casting to unsigned integers (e.g., toUInt32) resolves the issue.

Data type error screenshot
Data type error screenshot

2. Asynchronous deletes/updates

ClickHouse’s MergeTree engine guarantees eventual consistency; for strict consistency a full data reload is recommended.

MergeTree consistency diagram
MergeTree consistency diagram

Conclusion

By migrating the heavy‑query workload to ClickHouse we eliminated the MySQL bottleneck: queries on sub‑billion‑row tables now finish within one second, and the system can be scaled out with ClickHouse clusters for larger volumes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Data MigrationPerformance OptimizationClickHousemysqlOLAPColumnar Database
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.