Improve primary keys of clickhouse tables

未关闭
#410 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
重构
描述清晰度
需要澄清
活跃度
冷清
技术栈
clickhouse, sql

调研方向

首先定位 issue 中所示的 obs_web 和 analysis_web_measurement 表的 ClickHouse 定义。检查它们当前的 PRIMARY KEY 和 ORDER BY 选择,然后为列出的过滤器确定替代键,并规划将数据复制到新表中。完成的标准是替代表已填充数据,并且常见的 measurement_start_time、probe_cc、probe_asn 和 domain 查询不再需要实际上接近全表扫描。

由索引模型根据 Issue 内容生成。

描述

Some of the DB tables could have their PRIMARY KEYs changed to improve query performance.

For example the PRIMARY KEY of the obs_web table is this:

ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_web_repl/{shard}', '{replica}')
PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2))
PRIMARY KEY (measurement_uid, observation_idx)

while the analysis table is this:

ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/analysis_web_measurement/{shard}', '{replica}')
PARTITION BY substring(measurement_uid, 1, 6)
PRIMARY KEY measurement_uid
ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain)

What this means is that it's triggering very large scans (effectively a full scan), when performing very common filtering operations over the measurement_start_time, probe_cc, probe_asn and domain.

Unfortunately it's not possible to change these with an ALTER query, so instead we are going to have to create the new table and copy the data over.

主要语言
HCL
星标
4
派生
16
平均合并
3 天 10 小时
30 天内合并 PR
11

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ooni/devops 的其他 Issue

查看 ooni/devops 的全部 Issue

相似的 Issue

更多 Databases Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。