ClickHouse Will Let You Be Wrong at Scale
- ID: 7340c066
- 原文链接: https://matduggan.com/clickhouse-will-let-you-be-wrong-at-scale/
- 作者 / 日期: Mat Duggan | 2026-10-20
- 分类: infra
- 来源类型: article
- 标签: clickhouse, olap, observability, grafana, query-performance
- 质量评分: 4/5
- 抓取时间: 2026-10-21T15:51:49.496237+00:00
中文导读
Mat Duggan 把每天约 20 亿行混合厂商防火墙 syslog 灌进 ClickHouse(14 天 TTL、2 分片×3 副本、Grafana 25 个面板)的踩坑复盘。防御式 WHERE 写法让同一台机器读取行数从 305 万涨到 2.5764 亿、耗时 115ms→1134ms,答案一样多读 84 倍行;改用 Grafana ad-hoc filter 后回到 467 万行,因为它把过滤条件下发为 additional_table_filters 查询设置、在规划阶段生效。排序键前缀决定主索引裁剪:低基数 observer 列前置让 tail-logs 面板读 2.918 亿行/158GiB/18.9s,重排后 2310 万行/936ms,而 MODIFY ORDER BY 只能在同次 ALTER 里追加列、不能重排,回填代价每分片约 520GiB。projection 路由不做等价推理:toStartOfHour(Timestamp)>=X 能路由到 2022 行,数值相同的 toStartOfInterval 写法静默回落读 1237 万行。他自测 10.8 倍提速后才发现是旧表 88% 分区已分层到 S3 造成的假对照;system.query_log 是这套系统里唯一会告诉你出错的地方。
为什么值得关注
OLAP 的错误模式是「不报错只变慢」,这篇把资源护栏、验证习惯与 query_log 定位写成可抄清单。
关键信息
- 护栏:max_rows_to_read 10 亿、max_bytes_to_read 100GB、max_execution_time 60s
- 防御式 WHERE:305 万行→2.5764 亿行(115ms→1134ms);ad-hoc filter 回到 467 万行
- 排序键重排:2.918 亿行/158GiB/18.9s → 2310 万行/936ms;回填约 520GiB/分片
- projection 路由不做等价推理;10.8 倍「提速」来自 S3 分层差异
English Summary
Mat Duggan's war story feeding ~2 billion rows/day of firewall syslog into ClickHouse (14-day TTL, 2 shards x 3 replicas, 25 Grafana dashboards): a defensive WHERE clause read 257.64M rows instead of 3.05M (115ms to 1134ms) for the same answer; Grafana ad-hoc filters push predicates down as additional_table_filters at planning time. Sort-key prefix mistakes cost 291.8M rows/158GiB/18.9s until reordered (MODIFY ORDER BY can only append within one ALTER; backfill ~520GiB per shard). Projection routing does no equivalence reasoning, and his celebrated 10.8x speedup turned out to be an S3-tiering artifact. system.query_log is the only place that tells you something is wrong.
Obsidian Notes
- Vault 摘要源:AK-RSS-Digest 2026-10-21 第 2 条 + Gracker的Rss订阅/_bodies/2026-10-21-gracker/2026-10-21-matduggan-com-ClickHouse-Will-Let-You-Be-Wrong-at-Scale.md(本地全文)。
- 本页由 daily-intake-evening 任务于 2026-10-21T15:51:49.496237+00:00 生成,摘要锚定上述 vault 摘要源与已核对元数据,未添加来源之外的事实。