
SQL Optimization Patterns
Data & Analyticsby wshobson
3/3 audits passMIT
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.
SQL Optimization Patterns, published by wshobson under the MIT licence, teaches the agent to diagnose slow queries from the execution plan. It shows how to run EXPLAIN, EXPLAIN ANALYZE and EXPLAIN with buffers in PostgreSQL and what to look for: sequential scans versus index and index-only scans, nested loop, hash and merge joins, estimated cost against actual time. It then covers index strategy across B-tree, hash, GIN, GiST and BRIN indexes, and query rewrites such as avoiding SELECT *, writing index-friendly WHERE clauses and tightening joins.
A reference file adds worked patterns: eliminating N+1 queries, faster pagination, efficient aggregation, subquery rewrites and batch operations, plus materialized views, partitioning and query hints. The best practices and pitfalls are concrete: over-indexing slows writes, implicit type conversion and functions in WHERE clauses block index use, leading-wildcard LIKE cannot use an index, and statistics need regular ANALYZE and VACUUM. It is written for developers and database engineers debugging performance or designing schemas; it is not a guide to analytical SQL or reporting.
This skill is mainly for coding agents such as Claude Code working in an application's database layer; it can be imported into BusinessMCP as a playbook, but it has little to do with business reporting.
What you can do with it
- Read an EXPLAIN ANALYZE plan to find a sequential scan
- Pick between B-tree, GIN and BRIN indexes for a workload
- Replace offset pagination on a large table
- Remove N+1 queries from an application's data layer
Run it on your business data
Imported into BusinessMCP, SQL Optimization Patterns becomes a playbook your AI business analyst applies to your web analytics, funnels and connected databases.
Use SQL Optimization Patterns in BusinessMCPInstall it in a coding agent
One command adds SQL Optimization Patterns to your project.
npx skills add https://github.com/wshobson/agents --skill sql-optimization-patternsHow we vetted it
- Source
- wshobson/agents at 4236bb9
- Licence
- MIT
- Security audits (skills.sh)
- Gen Agent Trust Hub: Pass · Socket: Pass · Snyk: Pass
- Bundled scripts
- None, instructions only
Checked 2026-09-25 against its skills.sh listing. How we vet skills
Related skills
All skillsPostgreSQL Table Design
Use this skill when designing or reviewing a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features
SQL Queries
Write correct, performant SQL across all major data warehouse dialects (Snowflake, BigQuery, Databricks, PostgreSQL, etc.).
Supabase Postgres Best Practices
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including…
Frequently asked questions
Which databases does SQL Optimization Patterns focus on?
Its examples are mainly PostgreSQL, including EXPLAIN options, index types and VACUUM and ANALYZE maintenance, though the query-rewrite principles apply more widely.
Is it about writing reports?
No. It targets query performance and schema design for developers. For analytical SQL patterns such as cohorts and funnels, a skill like SQL Queries is closer.
How do I install SQL Optimization Patterns?
Run `npx skills add wshobson/agents --skill sql-optimization-patterns`, or import it from the BusinessMCP dashboard as a playbook.
Keep exploring
Run SQL Optimization Patterns against your whole business
Free plan, no credit card.
Use SQL Optimization Patterns in BusinessMCP