query-performance-analysis
БесплатноБез исполняемых скриптовНе проверенDetect N+1 queries, analyze slow queries with EXPLAIN, identify missing indexes, and ensure safe online index migrations for MySQL/MariaDB. Use when…
от VilnaCRM-Org★ 16 звёзд на GitHubОб этом скилле
Query Performance Analysis & Index Management
Context (Input)
Use this skill when:
- New or modified endpoints are slow
- Profiler shows many database queries for single operation
- Need to detect N+1 query problems
- Query execution time is high
- Slow query warnings in MySQL logs
- Performance regression after code changes
- Planning safe index migrations for production
- Need to verify index effectiveness
Task (Function)
Analyze query performance, detect N+1 issues, identify missing indexes, and create safe online index migrations with verification steps.
Success Criteria:
- N+1 queries detected and fixed
- Slow queries identified with EXPLAIN analysis
- Missing indexes detected and added
- Query performance meets acceptable thresholds (<100ms for reads, <500ms for writes)
- Index migrations are safe for production (minimal downtime)
- Performance regression tests added
TL;DR - Quick Performance Checklist
Before Merging Code:
- Run endpoint with profiler - check query count
- No N+1 queries (queries in loops)
- Slow queries (<100ms) analyzed with EXPLAIN
- Missing indexes identified and added
- Eager loading used where appropriate
- Query count reasonable for operation (<10 queries ideal)
- Performance test added to prevent regression
When Adding Indexes:
- Index covers actual query patterns
- Composite index field order correct
- Index creation uses ALGORITHM=INPLACE when possible
- Verification steps included
- Index usage confirmed with EXPLAIN
Quick Start: 5-Step Performance Analysis
Step 1: Enable MySQL Slow Query Log
docker compose exec database mariadb -u root -proot
-- Enable slow query log
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 0.1; -- Log queries slower than 100ms
SET GLOBAL log_queries_not_using_indexes = 'ON';
-- Verify settings
SHOW VARIABLES LIKE 'slow_query%';
SHOW VARIABLES LIKE 'long_query_time';
Step 2: Run Your Endpoint
curl https://localhost/api/users
Step 3: Analyze Query Patterns
-- View recent slow queries (MariaDB)
SELECT * FROM mysql.slow_log ORDER BY start_time DESC LIMIT 10;
-- Or use Symfony Profiler for detailed query analysis
-- Open: https://localhost/_profiler
Step 4: Check for Performance Issues
N+1 Problem Symptoms:
- Same query executed many times
- Query count grows with data size
- Queries inside
foreachloops
Slow Query Symptoms:
- Execution time >100ms
- EXPLAIN shows
type: ALL(full table scan) - High
rowsvs actual returned rows
Step 5: Disable Slow Query Log (Production)
SET GLOBAL slow_query_log = 'OFF';
Common Performance Issues
Issue 1: N+1 Queries
Detection: 100+ queries for 100 records
Fix: Use eager loading with Doctrine
// ❌ BAD: N+1 problem
$users = $repository->findAll(); // 1 query
foreach ($users as $user) {
$token = $user->getConfirmationToken(); // N queries if lazy loaded!
}
// ✅ GOOD: Eager loading with QueryBuilder
$qb = $this->createQueryBuilder('u');
$qb->leftJoin('u.confirmationToken', 't')
->addSelect('t'); // Eager load tokens
$users = $qb->getQuery()->getResult();
See: examples/n-plus-one-detection.md for complete guide
Issue 2: Slow Queries (No Index)
Detection: EXPLAIN shows type: ALL, execution time >100ms
Fix: Add index
-- Check query performance
EXPLAIN SELECT * FROM users WHERE email = '[email protected]';
-- If type: ALL → add index
Add index in Doctrine migration:
// migrations/VersionXXX.php
public function up(Schema $schema): void
{
$this->addSql('CREATE INDEX idx_users_email ON users (email)');
}
Or in XML mapping:
<!-- config/doctrine/User.orm.xml -->
<indexes>
<index name="idx_email" columns="email"/>
</indexes>
See: examples/slow-query-analysis.md for EXPLAIN interpretation
Issue 3: Missing Indexes on Filtered Fields
Detection: Queries filter/sort on fields without indexes
Common patterns needing indexes:
- WHERE clause fields:
email = ?,status = ? - ORDER BY fields:
created_at DESC - Composite filters:
status = ? AND type = ? - Foreign keys:
user_id,token_id
Cursor pagination + UUID index strategy (this repo):
This service uses cursor pagination on id (UUID). For pagination with filters, use a composite index:
<indexes>
<index name="idx_status_id" columns="status,id"/>
</indexes>
See: reference/index-strategies.md for index selection guide
Performance Thresholds
| Operation | Target | Max Acceptable |
|---|---|---|
| GET single | <50ms | 100ms |
| GET collection (100 items) | <200ms | 500ms |
| P |
Установить query-performance-analysis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл query-performance-analysis?
Detect N+1 queries, analyze slow queries with EXPLAIN, identify missing indexes, and ensure safe online index migrations for MySQL/MariaDB. Use when optimizing query performance, preventing performance regressions, or debugging slow endpoints. Complements database-migrations skill which covers index creation syntax.
Как установить скилл query-performance-analysis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл query-performance-analysis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic