sql-optimization-patterns
Skill0 starsChanged 10 months agoMITView on GitHub
Specialist in SQL query optimization—index strategies, EXPLAIN analysis, query tuning. Transforms slow queries into fast ones through systematic diagnosis and targeted optimization.
16 other projects use a version of this.
Adopted by
Most recently taken up by
- KumailQazi/krmaazha-binance-mcptheir own version, first seen Oct 17, 2026
- kitloomlk-stack/nextjs-supabase-kittheir own version, first seen Oct 15, 2026
- xfstudio/skillstheir own version, first seen Oct 13, 2026
- ramybarsoum/claude-skillstheir own version, first seen Oct 13, 2026
- Samueladewole/claude-skillstheir own version, first seen Oct 13, 2026
- Tgoldi/claude-skillstheir own version, first seen Oct 13, 2026
Used with
Projects with it also use similarity-search-patterns, team-composition-analysis and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
xfstudioSkillsimilarity-search-patterns
Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.
Also in 5 projects that use this
xfstudioSkillteam-composition-analysis
This skill should be used when the user asks to "plan team
Also in 4 projects that use this
- +10 more from xfstudio
Other versions16 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 16
- tranhieutt/software_development_department★ 71same name
- kumaran-is/claude-code-onboarding★ 35same name
- xfstudio/skills★ 9same name
- AJBcoding/claude-skill-eval★ 4same name
- KumailQazi/krmaazha-binance-mcp★ 4same name
- scops/sql-optimization-patterns★ 4same name
- ai4brands-design/claude-skills★ 2same name
- CodeWithBehnam/cc-docs★ 2same name
- Ghosteken/agent-harness★ 2same name
- roshankodi/agent-skills★ 2same name
6 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository33 other files it gives its agents.
- architectSkill
- brainstormingSkill
- concise-planningSkill
- context-engineerSkill
- data-deprecation-analysisSkill
- data-modelerSkill
- data-pipeline-engineerSkill
- data-quality-frameworksSkill
- dbt-transformation-patternsSkill
- github-workflow-automationSkill
- guardianSkill
- implementerSkill
- json-to-pydanticSkill
- llm-app-patternsSkill
- navigatorSkill
- ops-managerSkill
- orchestratorSkill
- principal-data-engineerSkill
- product-manager-toolkitSkill
- proj-memorySkill
- prompt-librarySkill
- qa-testerSkill
- researcherSkill
- senior-data-engineerSkill
- software-architectureSkill
- spark-optimizationSkill
- state-managerSkill
- subagent-driven-developmentSkill
- thinkerSkill
- top-web-vulnerabilitiesSkill
- verification-before-completionSkill
- web-design-guidelinesSkill
- workflow-managerSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 36
Query Plan Analysis: - Read EXPLAIN output to identify bottlenecks
- Distinctive: line 120
Check for missing indexes on filter/join columns
- Distinctive: line 126
Add indexes (B-tree, hash, GIN, BRIN as appropriate)
- Distinctive: line 128
Consider denormalization or materialized views
- Distinctive: line 133
Test optimization with production data volume
- Distinctive: line 135
Document solution and performance improvement
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQL Optimization Patterns
Specialist in diagnosing and fixing SQL performance bottlenecks through query plan analysis and indexing strategies.
When to Use This Skill
Use when:
- SQL queries exceed SLA or performance requirements
- Need to diagnose slow queries using EXPLAIN analysis
- Designing database schemas and indexing strategies for analytics workloads
- Reducing database costs through query efficiency
- Optimizing joins, aggregations, or complex analytical queries
- Investigating full table scans and expensive operations
- Implementing index strategies for high-performance reads
- Performance debugging when queries are slow in production
Core Capabilities
- Query Plan Analysis - Read EXPLAIN output to identify bottlenecks
- Indexing Strategies - Design B-tree, hash, GIN, BRIN indexes for query patterns
- Join Optimization - Choose strategies (nested loop, hash, merge) based on data size
- Schema Design - Denormalization, partitioning, materialized views for analytics
- Query Refactoring - Rewrite slow queries using window functions, CTEs, batch operations
- Cost Reduction - Improve query efficiency to reduce compute costs and resource usage
Reference Guides
For detailed implementation guidance, see:
EXPLAIN & Query Plans
Use when: Analyzing slow query performance
Covers:
- Understanding EXPLAIN output across PostgreSQL, MySQL, Snowflake, BigQuery
- Key metrics (Seq Scan, Index Scan, cost, rows, execution time)
- Reading execution plans from bottom-up
- Identifying bottlenecks and cardinality issues
Indexing Strategies
Use when: Designing indexes for analytics workloads
Covers:
- Index types (B-tree, hash, GIN, BRIN, covering, partial)
- Selectivity and composite index design
- Partial and expression indexes
- Avoiding over-indexing and unused indexes
- Index maintenance (ANALYZE, VACUUM, reindex)
Query Optimization Patterns
Use when: Rewriting queries for better performance
Covers:
- Eliminating N+1 query problems
- Cursor-based pagination (vs OFFSET)
- Optimizing COUNT and GROUP BY
- Transforming correlated subqueries
- Using CTEs and window functions
- Batch processing patterns
Advanced Techniques
Use when: Using advanced database features
Covers:
- Materialized views for pre-computation
- Table partitioning for large tables
- Query hints and optimization control
- Performance monitoring and statistics
- Connection pooling and tuning
Quick Decision Guide
| Problem | Reference |
| Query is slow | EXPLAIN & Query Plans |
| Need to add indexes | Indexing Strategies |
| Rewrite query efficiently | Query Optimization Patterns |
| Advanced optimization | Advanced Techniques |
Optimization Workflow
Phase 1: Diagnosis
- Capture slow query with
EXPLAIN ANALYZE - Identify bottleneck: sequential scan, expensive join, high cost estimate
- Understand data volumes and selectivity
Phase 2: Root Cause Analysis
- Check for missing indexes on filter/join columns
- Review join strategy (nested loop vs hash vs merge)
- Analyze cardinality estimates vs actual rows
Phase 3: Optimization
- Add indexes (B-tree, hash, GIN, BRIN as appropriate)
- Rewrite query to reduce complexity (CTEs, window functions)
- Consider denormalization or materialized views
- Measure impact: runtime, cost, resource usage
Phase 4: Validation
- Test optimization with production data volume
- Monitor side effects (index maintenance overhead, storage)
- Document solution and performance improvement
Best Practices
Performance Analysis
- ✅ Establish Baseline: Measure query runtime, cost, resource usage before optimization
- ✅ Use EXPLAIN ANALYZE: Always run with ANALYZE; never guess at performance
- ✅ Understand Costs: Lower query cost estimate usually correlates with faster execution
- ✅ Check Selectivity: Filters with poor selectivity waste I/O; indexes on selective columns help most
Indexing Strategy
- ✅ Index Selective Columns: Indexes help when filtering/joining on high-cardinality columns
- ✅ Avoid Over-Indexing: Every index slows writes; add only indexes that measurably help
- ✅ Composite Indexes: Order by selectivity (most selective first) and join key order
- ✅ Partial Indexes: Index only relevant subset (e.g., WHERE active = true)
Query Optimization
- ✅ Filter Early: Push WHERE clauses down before joins
- ✅ Minimize Shuffles: Avoid sorting/aggregating large result sets; use indexes for ordering
- ✅ Use Window Functions: More efficient than self-joins for ranking, running totals
- ✅ Denormalize Strategically: Trade write complexity for read speed when appropriate
Common Pitfalls
| Pitfall | Root Cause | Fix |
| Missing index | Obvious filter on non-indexed column | Add index on frequently filtered columns |
| Unused index | Index added but never used | Use EXPLAIN; verify index is selected by planner |
| Indexing without EXPLAIN | Adding indexes blindly | Run EXPLAIN ANALYZE before/after; confirm improvement |
| Bad join order | Joining large table first | Filter before joins; use EXPLAIN to understand order |
| Over-indexing | Every column indexed | Remove unused indexes; focus on high-value queries |
| Stale statistics | Query plan based on old stats | Run VACUUM ANALYZE regularly |
Dependencies
- senior-data-engineer - For schema design and performance mentorship
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

