database-query-profiling

Analyze and optimize SQL queries with N+1 detection, index recommendations, and EXPLAIN plan review.

1|Updated Feb 10, 2026
One-click install
npx skills add https://github.com/stefanfaur/roach-marketplace --skill database-query-profiling-stefanfaur
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: database-query-profiling
Source: https://github.com/stefanfaur/roach-marketplace/tree/main/database-query-profiler/skills/database-query-profiling
Command: npx skills add https://github.com/stefanfaur/roach-marketplace --skill database-query-profiling-stefanfaur

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? Slow database queries, hidden N+1 patterns, and missing indexes degrade application performance, but finding and fixing them manually across a large codebase is tedious and error-prone. ## Core Features & Use Cases - N+1 Query Detection: Scans codebases for ORM lazy-loading patterns in Django, SQLAlchemy, ActiveRecord, Prisma, TypeORM, and Sequelize that trigger per-iteration queries. - Index Analysis: Identifies columns used in WHERE, JOIN, ORDER BY, and GROUP BY clauses and generates CREATE INDEX statements for missing composite indexes. - Query Optimization: Reviews EXPLAIN plans for PostgreSQL, MySQL/MariaDB, and SQLite, rewriting subqueries as joins and eliminating SELECT * patterns. - Use Case: Point the skill at a Django project with slow API endpoints; it inventories all queries, flags N+1 loops missing select_related, and outputs before/after query rewrites with index recommendations. ## Quick Start Ask the assistant to profile the queries in this project and find N+1 problems and missing indexes.

Frequently Asked Questions about database-query-profiling

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

FAQPage Schema
How do I find N+1 queries in my codebase?▼

Search for queries executed inside loops or list iterations and check for missing eager-loading calls such as select_related in Django, joinedload in SQLAlchemy, includes in ActiveRecord, or include in Prisma. Each missing call causes one extra query per iterated row.

How to identify missing database indexes from slow queries?▼

Examine columns used in WHERE, JOIN ON, ORDER BY, and GROUP BY clauses, then compare them against existing indexes. Run EXPLAIN or EXPLAIN ANALYZE to confirm sequential scans, and create composite indexes matching multi-column filter patterns.

Does query profiling work without database access?▼

Yes, queries can be analyzed statically from source code, including N+1 detection and index recommendations based on query patterns. However, EXPLAIN plan analysis and actual performance measurement require a live database connection.

Which databases and ORMs are supported for query optimization?▼

PostgreSQL, MySQL/MariaDB, and SQLite are supported for EXPLAIN analysis. ORM coverage includes Django, SQLAlchemy, ActiveRecord, Prisma, TypeORM, and Sequelize for tracing generated SQL and eager-loading fixes.

Why is my subquery slower than a JOIN?▼

Subqueries in IN clauses can prevent the optimizer from using efficient join strategies and indexes. Rewriting them as INNER JOINs with DISTINCT typically produces better execution plans, which you can verify by comparing EXPLAIN output before and after.