sql-performance

Reviews and optimizes PostgreSQL, MySQL, and SQLite queries using engine-version-aware performance catalogs.

Updated Jul 4, 2023
One-click install
npx skills add https://github.com/kohdice/dotfiles --skill sql-performance-kohdice
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sql-performance
Source: https://github.com/kohdice/dotfiles/tree/main/config/agents/skills/sql-performance
Command: npx skills add https://github.com/kohdice/dotfiles --skill sql-performance-kohdice

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Slow SQL queries and subtle correctness bugs (like NULL-trap NOT IN or unordered LIMIT pagination) are hard to catch in code review, and generic advice often ignores which database engine and version a project actually runs. This Skill grounds every recommendation in the official PostgreSQL, MySQL, and SQLite manuals, gated to the resolved engine version. ## Core Features & Use Cases - Engine baseline resolution: Detects the database engine and version from build manifests, migration tooling, connection strings, and SQL dialect markers before making any recommendation. - Cost-ordered finding catalog: Flags N+1 queries, non-SARGable predicates, over-fetching, sort and pagination costs, write batching issues, and index problems, tagged as [wrong-result], [cost], [measure], or [engine-gated]. - Safe measurement guidance: Distinguishes plain EXPLAIN from EXPLAIN ANALYZE and identifies statements that write data, so measurement never runs against production. - Use Case: While reviewing a Rust service using sqlx with PostgreSQL 17, the Skill spots a per-request correlated subquery and a deep OFFSET pagination endpoint, then recommends a LATERAL join and keyset pagination with manual citations. ## Quick Start Ask the AI to review the SQL queries and migrations in this repository for performance problems and report findings by engine and version.

Frequently Asked Questions about sql-performance

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

FAQPage Schema
How do I find slow SQL queries in my application code?▼

Grep for SELECT, INSERT, UPDATE, DELETE, WITH, and CREATE INDEX across source files, then read each call site to judge hotness. Statements issued per request, per item, or inside loops are hot and get full catalog analysis; one-off migrations are cold.

How to fix N+1 query problems in SQL?▼

Replace the per-element queries with a single JOIN, a WHERE key IN (...) batch, or an = ANY($1) array parameter on PostgreSQL. Removing a query from a loop routinely beats any predicate tuning inside it.

Does this SQL review work with MySQL and SQLite or only PostgreSQL?▼

It supports PostgreSQL 18, MySQL 8.4 LTS / 9.7, and SQLite 3.53, with engine-specific catalogs for each. The engine and version are resolved from drivers, migration tooling, and connection strings before any recommendation is made.

Why is NOT IN with a subquery dangerous in SQL?▼

If the subquery column is nullable and yields a NULL, NOT IN returns null rather than true, producing wrong results on every engine. Rewrite it as NOT EXISTS, which on MySQL also enables the antijoin optimization.

Is it safe to run EXPLAIN ANALYZE on a production database?▼

No. EXPLAIN ANALYZE executes the statement, including writes inside WITH clauses or multi-table UPDATE/DELETE on MySQL. Run plain EXPLAIN only, and only against a target confirmed to not be production.

What SQL performance issues are out of scope for query review?▼

Schema design (keys, constraints, data types, normalization) and application-code costs (allocations, connection pooling, serialization) are excluded. The review covers statement cost, result correctness, and the index definitions serving the queries.