mz-query-perf

Diagnose and benchmark SQL query rewrites against Materialize catalog relations.

6.4k|512|Updated Feb 22, 2019
One-click install
npx skills add https://github.com/MaterializeInc/materialize --skill mz-query-perf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mz-query-perf
Source: https://github.com/MaterializeInc/materialize/tree/main/.agents/skills/mz-query-perf
Command: npx skills add https://github.com/MaterializeInc/materialize --skill mz-query-perf

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Console and catalog queries that read Materialize system relations (mz_catalog / mz_internal) can be slow, but it is hard to know whether a rewrite actually helps without a faithful way to measure it. This Skill provides a repeatable two-phase method: diagnose the query plan on the real relations, then measure candidate rewrites with a synthetic-fleet latency sweep.

Core Features & Use Cases

  • Plan diagnosis with EXPLAIN: Run the query on mz_catalog_server and detect known anti-patterns such as filters applied after Top-1/Reduce, full scans of history relations, redundant self-joins, missing temporal filters, and fleet-wide aggregations for single-entity views.
  • Faithful synthetic benchmarking: Build shadow tables that replicate production indexes, generate a synthetic fleet at realistic scale, and compare old vs. rewritten queries with concurrent peek drivers measuring p50/p95 and qps.
  • Validation guardrails: Verify output equivalence between variants, confirm plan differences reproduce on the bench cluster, and avoid pitfalls like unindexed shadows or cross-run compaction noise.
  • Use Case: A Console cluster-utilization query scans all replicas before filtering to one. Use this Skill to EXPLAIN the plan, push the filter to the source read, and prove the latency win with a 200-cluster synthetic sweep.

Quick Start

Analyze this Console SQL query that reads mz_catalog relations, diagnose its plan on mz_catalog_server, and benchmark my proposed rewrite with a synthetic fleet sweep.

Frequently Asked Questions about mz-query-perf

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find performance problems in a Materialize catalog query?

Run EXPLAIN on the query with SET cluster = mz_catalog_server so the maintained builtin indexes are in scope. Then look for anti-patterns like filters applied after Top-1 or Reduce operators, full scans of history relations, redundant self-joins, and missing temporal filters on occurred_at columns.

How do I benchmark a SQL query rewrite in Materialize?

Create shadow tables matching the real relations' columns, replicate the production indexes from src/catalog/src/builtin/*.rs on a dedicated bench cluster, and generate a synthetic fleet at realistic scale. Then run old and new queries as concurrent peeks, measuring p50/p95 latency and qps across fleet sizes.

Why does EXPLAIN give a different plan on the default cluster?

The default cluster does not have the maintained builtin indexes that mz_catalog_server has, so the optimizer produces a misleading plan. Always EXPLAIN on the cluster where the query actually runs, using SET cluster = mz_catalog_server for catalog queries.

Why are my synthetic benchmark results misleading?

The most common cause is unindexed shadow tables, which measure a regime that does not exist in production since both old and new queries full-scan. Create the same indexes on the shadow tables that mz_catalog_server maintains on the real relations before measuring.

How do I verify a query rewrite is correct before shipping?

Diff the old and new query outputs for the same entity at small scale to confirm row equivalence. Also EXPLAIN both variants on the bench cluster to confirm the shadow setup reproduces the same plan difference seen on the real relations.