mz-query-perf
БесплатноБез исполняемых скриптовНе проверенAnalyze and optimize a Console/catalog SQL query in user space — diagnose its plan on real relations, then measure candidate rewrites with a faithful…
от MaterializeInc★ 6 417 звёзд на GitHubОб этом скилле
Console query performance analysis
A repeatable method for finding and validating performance improvements to a SQL
query that reads system catalog / introspection relations (the kind the Console
runs against mz_catalog_server). Developed on the cluster-utilization queries.
The method has two phases. Phase 1 (plan diagnosis) is cheap, exact, and needs no
data. Phase 2 (latency sweep) is only for candidates that Phase 1 flags, and its
fidelity depends entirely on one thing: the shadow tables must carry the same
indexes the real relations have on mz_catalog_server.
Phase 1 — diagnose the plan on the REAL relations (cheap, do this first)
The query reads real builtin relations that already exist on a local
environmentd, on mz_catalog_server, with their real indexes and view
definitions. So EXPLAIN the actual query there. No synthetic data is needed to
read a plan's shape, and this is strictly more faithful than any shadow.
- Take the query file. Fill in any parameters with literals (cluster ids like
's2', timestamps, bucket sizes). Fix template artifacts (e.g.LIMIT '1}'from Handlebars becomesLIMIT 1). - Run it through
EXPLAINonmz_catalog_server:
(Usepsql "postgres://materialize@localhost:6875/materialize" -c \ "SET cluster = mz_catalog_server; EXPLAIN <filled query>;"SET cluster = mz_catalog_serverso the maintained builtin indexes are in scope. The default cluster will not have them and gives a misleading plan.) - Read the plan for these anti-patterns (each is a known win):
- Filter applied after a Top-1 / Reduce, over the whole fleet. A per-entity
query (one cluster, one replica) whose
WHERE entity = ?only appears at the end, aboveMonotonic Top1/Reduce/ a multi-way join that ran over every entity. The optimizer will not push a top-level predicate into a CTE shared by multiple consumers. Fix: push the filter to where the entity column is first introduced (the source read), so the heavy operators are scoped. *** full scan ***/ unfilteredReadof a large history relation where a key lookup is possible. Often caused by the predicate not reaching the indexed column.- Redundant self-join of a relation already implied upstream (e.g. joining
replica_historyagain afterreplica_metrics_historywas derived from it). Drop it; it adds an operator and can fan out. - Missing temporal filter on an append-with-retention history relation
(
*_history). WithoutWHERE occurred_at + INTERVAL '...' >= mz_now()the query materializes unbounded history. - Fleet-wide aggregation for a single-entity view (e.g.
max(occurred_at) GROUP BY clusteracross all clusters when only one is shown).
- Filter applied after a Top-1 / Reduce, over the whole fleet. A per-entity
query (one cluster, one replica) whose
- Write down the plan finding + a concrete rewrite hypothesis. If there is no anti-pattern, record that the query is already well-shaped and stop.
EXPLAIN OPTIMIZED PLAN AS TEXT FOR ... gives the operator tree; the Source ... pushdown=(...) / filter=(...) footer lines tell you what reached the storage
read. Grep the plan for the entity column (cluster_id, replica_id) to see
where the filter landed.
Phase 2 — measure magnitude with a FAITHFUL synthetic sweep (only for candidates)
Plan diagnosis tells you whether a rewrite helps; the sweep tells you how much. The real builtin sources can't be populated by hand (the controller writes them), so shadow them with user tables. The single most important rule:
Replicate the production indexes.
mz_catalog_servermaintains indexes on these relations (seesrc/catalog/src/builtin/*.rs,BuiltinIndex). E.g.mz_cluster_replica_metrics_history (replica_id),mz_cluster_replica_status_history (replica_id),mz_cluster_replica_name_history (id),mz_cluster_replica_history (dropped_at). A sweep on unindexed shadows measures a regime that does not exist in production — both old and new full-scan, so the result is wrong in both directions. Create the same indexes on the shadow tables, on the bench cluster, before measuring.
Setup:
- Dedicated bench cluster
SIZE = 'scale=1,workers=1,mem=32GiB'— one worker, matchingmz_catalog_server; big memory so you measure cost, not OOM. Never pass--resettoenvironmentd(it wipes local state). - Shadow tables with the same columns as the real relations, plus the
matching
CREATE INDEXes on the bench cluster. - Synthetic fleet sized to a realistic scrape (replica metrics at 1/min; 14-day retention = 20160 samples/replica). Sweep fleet size (e.g. 25 / 100 / 200 clusters, 2 replicas each).
- Run both the OLD and the rewritten query as ad-hoc peeks for a random entity, N concurrent clients, fixed duration. Measure p50/p95 and qps.
- Use the actual query text (or, for a Kysely builder, the
.compile()d SQL), not a hand-paraphrase. Hand-rewrites drift from what ships.
Valid
Установить mz-query-perf в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mz-query-perf?
Analyze and optimize a Console/catalog SQL query in user space — diagnose its plan on real relations, then measure candidate rewrites with a faithful synthetic-fleet sweep. Use when asked to find performance improvements for a query that reads mz_catalog / mz_internal relations.
Как установить скилл mz-query-perf?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mz-query-perf запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic