
목적
공식 홈페이지

Query billions of rows in milliseconds
ClickHouse is the fastest and most resource efficient open-source database for real-time apps and analytics.
Fast Open-Source OLAP DBMS
OLAP, OLTP 차이점

언제 써야 좋을까?
clickhouse intro
Distinctive Features of ClickHouse
tutorial
CREATE DATABASE IF NOT EXISTS helloworldCREATE TABLE helloworld.my_first_table
(
user_id UInt32,
message String,
timestamp DateTime,
metric Float32
)
ENGINE = MergeTree()
PRIMARY KEY (user_id, timestamp)
INSERT INTO helloworld.my_first_table (user_id, message, timestamp, metric) VALUES
(101, 'Hello, ClickHouse!', now(), -1.0 ),
(102, 'Insert a lot of rows per batch', yesterday(), 1.41421 ),
(102, 'Sort your data based on your commonly-used queries', today(), 2.718 ),
(101, 'Granules are the smallest chunks of data read', now() + 5, 3.14159 )
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
FORMAT TabSeparated
alter table update
https://clickhouse.com/docs/en/sql-reference/statements/alter/update
note
The
ALTER TABLEprefix makes this syntax different from most other systems supporting SQL. It is intended to signify that unlike similar queries in OLTP databases this is a heavy operation not designed for frequent use.
It is not possible to update columns that are part of the primary or sorting key.
alter table delete
https://clickhouse.com/docs/en/sql-reference/statements/alter/delete
The
ALTER TABLEprefix makes this syntax different from most other systems supporting SQL. It is intended to signify that unlike similar queries in OLTP databases this is a heavy operation not designed for frequent use.ALTER TABLEis considered a heavyweight operation that requires the underlying data to be merged before it is deleted. For MergeTree tables, consider using theDELETE FROMquery, which performs a lightweight delete and can be considerably faster.
Lightweight delete
CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv
TO analytics.monthly_aggregated_data
AS
SELECT
toDate(toStartOfMonth(event_time)) AS month,
domain_name,
sumState(count_views) AS sumCountViews
FROM analytics.hourly_data
GROUP BY
domain_name,
month
CREATE TABLE example1 (
timestamp DateTime,
x UInt32 TTL now() + INTERVAL 1 MONTH,
y String TTL timestamp + INTERVAL 1 DAY,
z String
)
ENGINE = MergeTree
ORDER BY tuple()
ClickHouse is built for speed when it comes to data insertion. The storage files are immutable and ClickHouse does not check for an existing primary key before inserting a row-so deduplication involves a bit more effort. This also means that deduplication is not immediate-it is eventual, which has a few side effects:
At any moment in time your table can still have duplicates (rows with the same sorting key)
The actual removal of duplicate rows occurs during the merging of parts
Your queries need to allow for the possibility of duplicates
table engine
ENGINE = MergeTreeReplacingMergeTreeCollapsingMergeTree1 and -1 values, 1 is a “state” row, -1 is a “cancel” row.VersionedCollapsingMergeTreeDictionaries
Lightweight Update
note
Lightweight update is only available on ClickHouse Cloud.
Lightweight Delete
DELETE does not delete data from storage immediatelyTransactional (ACID) support
영환ES
RDBMS → b-tree
ClickHosue → spares index
인덱스 추가는 중간에 할 수 없다
기존 생성 테이블에, 칼럼이 늘어나는 경우(?)
메모리가 부족하면, 에러 발생
skip index
Best Practices
자 그러면 rdb
experimental 옵션은 프러덕션에 사용하지 말아라