clickhouse-autoresearch-campaign
它能做什么
这项技能指导智能体有条理地尝试加快 ClickHouse 中的一条数据库查询。适合希望安全地测试许多查询修改、并沿途记录结果的工程师。
适用场景
- ✓当你希望通过反复的、可衡量的尝试让一条 ClickHouse 查询变快的时候。
- ✓当你希望每个查询实验都保存在自己的 git 分支上的时候。
- ✓当你希望记录查询修改的基准耗时和正确性检查的时候。
技能链接
https://github.com/PostHog/posthog/blob/master/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们的 ClickHouse 仪表板查询太慢了。你能在独立分支上进行优化,并记录每次尝试吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会建立专用分支和工作区,测量起始基准,并一次尝试一种不同的思路。它会检查结果是否保持正确,并审阅那些不再改进的尝试记录。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
ClickHouse Autoresearch Campaign
This skill packages the orchestration for optimizing one ClickHouse query on one git branch.
Required reads
Before taking action, read orchestration.md (sibling of this file) completely. Treat it as the operating contract.
Preconditions
This skill assumes:
pi-autoresearchis installed and its tools are available- the current directory is a git repository
- you have a target query or enough context to identify one
- the operator will provide or help configure
.clickhouse-autoresearch/adapter.json
Branch rule
One campaign = one git branch.
If the current branch is not a dedicated campaign branch yet, create one before initializing the workspace.
Workspace rule
Use a single workspace at:
.clickhouse-autoresearch/
The branch is the campaign boundary. The workspace is just the artifact layout.
If autoresearch.config.json exists in the current working directory, read its workingDir field and use that path as the workspace instead of the default above. Automated orchestrators (for example PostHog's run_campaign.py) initialize the workspace at /tmp/autoresearch-campaign/ and write the config alongside it.
Pre-initialized workspace detection
Before doing anything in the Setup sequence, check whether the workspace has already been prepared by an external orchestrator. If the resolved workspace contains all of:
adapter.jsonbaseline/metrics.jsonquery/original.sql
…then the workspace is pre-initialized. In that case:
- Skip the entire Setup sequence (steps 1–6). Do not ask the operator for a target query, connection details, or anything else — the orchestrator has already supplied them.
- Jump directly to step 7 of the Setup sequence (read the baseline and seed the first lanes and hypotheses), then continue with steps 8–9 and the normal campaign loop.
- Operate headlessly: at no point prompt the operator for input. If a decision requires judgment, apply the skill's default guidance and record the choice in
state.json/autoresearch.md.
Only fall back to the interactive Setup sequence below when the workspace is empty or partially initialized.
Adapter capabilities (what you can and cannot run)
Campaign queries flow through the adapter configured in adapter.json. Every campaign script (ch_capture_baseline.py, ch_run_candidate.py, any ad-hoc probe) ultimately submits SQL through this adapter, and the adapter enforces what ClickHouse sees.
When adapter.json has type: "coordinator", your SQL is routed to whichever ClickHouse the host-side coordinator is pointed at — typically a read-only test cluster or a local dev ClickHouse. Either way the cluster runs SQL under a profile that pins readonly = 2, so writes (INSERT, ALTER, CREATE, OPTIMIZE, SYSTEM, TRUNCATE, DROP, ATTACH, DETACH) will fail with a ClickHouse error. Read GET /v1/info (or check autoresearch.md — the coordinator's prompt addendum is prepended there) before issuing any predicate that depends on a specific team_id: the prompt addendum tells you which team_id the target cluster has data for, and you must rewrite team_id predicates to match it. For experiments treat every read-only statement form as available:
SELECT …— arbitrary subqueries, CTEs, joinsWITH … SELECT …EXPLAIN …— every variant ClickHouse supports. Use them before proposing rewrites:EXPLAIN SELECT …(default: PLAN)EXPLAIN AST SELECT …EXPLAIN SYNTAX SELECT …EXPLAIN QUERY TREE SELECT …(post-analyzer logical tree; invaluable on modern ClickHouse)EXPLAIN PIPELINE SELECT …— processor-level pipeline, headers, expressionsEXPLAIN ESTIMATE SELECT …— per-part row/mark estimates before executionEXPLAIN PLAN indexes = 1, actions = 1, json = 1 SELECT …— primary-key and skip-index use, JSON for machine parsingEXPLAIN TABLE OVERRIDE …
SHOW …—SHOW CREATE TABLE events,SHOW COLUMNS FROM events,SHOW INDEX FROM events,SHOW SETTINGS ILIKE '%mark_cache%', etc.DESCRIBE/DESC …
Timeout: every submission is wrapped with SETTINGS max_execution_time = 60. Keep ad-hoc probes short. If the target query itself routinely exceeds 60s, use range narrowing (see Setup step 6) and only then start the campaign.
Cluster scoping: depends on the coordinator's target. The prompt addendum prepended to autoresearch.md tells you which team_id the target cluster has data for and ask
常见问题
它需要自己的 git 分支吗?
需要。每个活动都在一个专用的 git 分支上进行,这是工作的边界。
它会检查查询结果是否保持正确吗?
会。正确性检查与计时测试同时进行,因此更快的查询仍必须返回正确的答案。
它依赖哪些工具?
它依赖已安装的 pi-autoresearch 工具,以及目标适配器的配置文件。
详情
作者的原始描述
Run a ClickHouse query optimization campaign on one git branch using pi-autoresearch, dynamic lanes and hypotheses, baseline result capture, correctness checks, and stagnation-aware lane/campaign review.
repo: PostHog/posthog
热度
- GitHub 星标
- 41k
- 排名
- #6984
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
depot-ci
41k帮你的智能体设置并运行 Depot CI 工作流(GitHub Actions 的替代方案),包括迁移现有工作流和读取运行日志。
depot-container-builds
41k帮你的智能体在 Depot 的远程构建器上构建 Docker 镜像,包括多平台镜像、推送到镜像仓库,以及修复构建失败。
depot-github-runners
41k帮你的智能体把 GitHub Actions 任务迁移到 Depot 托管的运行器上,选择运行器规格和标签,并排查运行器设置问题。
editing-agents-md
41k帮你的智能体判断某条规则应写入 AGENTS.md 还是 CLAUDE.md,并以不会让文件臃肿的方式写下,确保规则真正生效。