Skip to main content
Skills/Data & Analytics/sql-query-optimizer

SQL Query Optimizer Skill

Reviews and rewrites SQL queries for performance, correctness, and maintainability.

A reusable skill package for Claude Code and Cowork.

When to use this skill

  • Diagnosing slow or expensive SQL queries
  • Rewriting queries for better performance and readability
  • Adding proper indexing strategies to a schema
  • Reviewing queries for correctness and edge cases

What this skill does

Analyzes SQL queries for performance anti-patterns (N+1, missing indexes, full table scans, unnecessary joins), rewrites them with explanations, and recommends indexing strategies. Produces before/after comparisons with estimated query cost reduction.

How it works

  1. 1Parse the query and identify performance anti-patterns and correctness issues
  2. 2Analyze execution plan indicators: full table scans, missing indexes, subquery misuse
  3. 3Rewrite with optimized joins, CTEs, or windowing functions as appropriate
  4. 4Recommend index strategy and present before/after comparison with explanations

Full Skill Definition

---
name: sql-query-optimizer
description: "Reviews and rewrites SQL queries for performance, correctness, and maintainability."
---

# Sql Query Optimizer

## Overview

You are a data analyst specializing in exploratory data analysis, statistical testing, and insight extraction.

## Purpose

Help users explore datasets, identify patterns, and derive actionable insights with statistical confidence.

## When to Use

When a user has a dataset and needs to understand it, find trends, or answer specific business questions with data.

## Analysis Workflow

## Step 1: Frame Questions & Profile the Data

Start by clarifying the business question or objective the analysis should answer. Then profile the data: examine shape, column types, missing values, distributions, and outliers. Review the data dictionary or provenance documentation to understand what each field means and how it was collected. Summarize key statistics.

## Step 2: Clean & Transform

Handle missing values, normalize formats, remove duplicates, and create derived features relevant to the analysis question.

## Step 3: Analyze & Test

Run appropriate statistical tests, compute correlations, segment by key dimensions, and test hypotheses. Use confidence intervals.

## Step 4: Present Findings & Iterate

Summarize insights in plain language with supporting visualizations. Distinguish correlation from causation. State limitations clearly. Identify follow-up questions surfaced by the analysis and recommend next iterations or deeper dives where warranted.

## Error Handling

## Small Sample Sizes

Warn when sample size is too small for reliable conclusions. State minimum n for the chosen statistical test.

## Data Quality Issues

Document all cleaning decisions and their impact on results. Flag when data quality may invalidate conclusions.

## Reproducibility

Ensure all analysis steps are documented and reproducible. Include the exact queries, transformations, and parameters used so results can be verified and replicated.

Summary

Reviews and rewrites SQL queries for performance, correctness, and maintainability. Install this skill by placing the package in ~/.claude/skills/sql-query-optimizer/ for personal use, or .claude/skills/sql-query-optimizer/ for project-specific use.

FAQs

What databases does it support?

PostgreSQL, MySQL, BigQuery, Snowflake, Redshift, SQLite, and most ANSI SQL-compatible systems.

Does it analyze query execution plans?

It reviews EXPLAIN output when provided, and infers execution patterns from query structure when plans are unavailable.

Can it help with ORM-generated queries?

Yes. Paste the generated SQL and it will identify and fix inefficient ORM patterns like N+1 selects.

Download & install

Install paths

Claude Code — personal (all projects)

~/.claude/skills/sql-query-optimizer/SKILL.md

Claude Code — project-specific

.claude/skills/sql-query-optimizer/SKILL.md

Cowork — skill plugin

Upload .skill.zip via Cowork plugin manager

Compatible with Claude Code, Cowork, and any SKILL.md-compatible agent platform.

Skills in the registry are community starter templates provided as-is. skill.design and Designless do not guarantee accuracy, completeness, or fitness for any purpose. Always review, customize, and validate skills for your specific use case before deploying to production. You are responsible for the behavior of skills you install and use.