All skills
simota avatar

/tuner

@e307415
by shingo imotasimota/agent-skills85 stars
15

Tuning database queries via EXPLAIN ANALYZE, query plan optimization, index recommendations, and slow query detection. Not for schema/migrations (Schema) or non-DB performance (Bolt).

Use this Skill: https://skilld.dev/gh/simota/agent-skills/tuner

This session only. Nothing lands on disk.

referencematerialized-views-partitioning.md

≈604 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Materialized Views & Table Partitioning

Purpose: Use this file when deciding whether to use materialized views, summary tables, or partitioning.

Contents:

  • materialized-view decision rules
  • PostgreSQL and MySQL patterns
  • partitioning thresholds
  • maintenance rules

Materialized Views

Decision Rules

Scenario Use MV? Reason
complex aggregation Yes avoids repeated computation
dashboard queries Yes predictable and cacheable
real-time data No staleness is unacceptable
infrequent queries No storage and refresh cost not justified
high-write tables Depends refresh cost may outweigh benefit

PostgreSQL

CREATE MATERIALIZED VIEW mv_daily_sales AS
SELECT DATE(created_at) AS sale_date, product_id, SUM(amount) AS total_amount
FROM orders
GROUP BY DATE(created_at), product_id
WITH DATA;

CREATE INDEX idx_mv_daily_sales_date ON mv_daily_sales(sale_date);
CREATE UNIQUE INDEX idx_mv_daily_sales_pk ON mv_daily_sales(sale_date, product_id);
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_daily_sales;

Rules:

  • use REFRESH CONCURRENTLY for zero-downtime refresh
  • CONCURRENTLY requires a unique index
  • validate refresh cadence against staleness tolerance

MySQL Alternative

MySQL has no native materialized views. Use a summary table plus scheduled refresh:

  • table for precomputed aggregates
  • refresh procedure or job
  • event scheduler or external orchestrator

Partitioning

Decision Matrix

Table Size Query Pattern Partition? Strategy
< 10M rows any No index tuning first
10M-100M time-based Yes range by date
10M-100M category-based Yes list by category
> 100M mixed patterns Yes composite strategy
any full table scans only No partitioning will not rescue bad access patterns

PostgreSQL Pattern

CREATE TABLE orders (
    id BIGSERIAL,
    created_at TIMESTAMP NOT NULL
) PARTITION BY RANGE (created_at);

Maintenance rules:

  • create future partitions before they are needed
  • verify partition pruning in EXPLAIN
  • archive or drop old partitions deliberately
  • prefer pg_partman when partition maintenance is recurring

MySQL Pattern

Use range partitions with the partition key included in the primary key and verify pruning with EXPLAIN.

Source: SKILL.md on GitHub

1 warning13d5 checks · Risk SAFE
  • Gen Agent Trust Hub13d

    The skill is a database tuning specialist designed to analyze query performance and recommend optimizations. No malicious code, exfiltration patterns, or obfuscation were detected. A low-severity finding for indirect prompt injection is noted due to the skill's primary function of ingesting and transforming potentially untrusted data like query plans and logs into actionable prompts for other agents.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW · No issues

  • Runlayer6mo

    4/13 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at e307415. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 2 weeks ago

README badge

README badge for simota/agent-skills/tuner