sql-optimization-patterns
Skill71 starsChanged 7 months agoMITView on GitHub
Provides SQL optimization patterns for query performance, indexing strategies, schema design, and database tuning. Use when optimizing slow queries, designing indexes, or tuning database performance.
23 other projects use a version of this.
Adopted by
Most recently taken up by
- Rain-kl/OpenFlaretheir own version, first seen Nov 30, 2026
- gromov0737/skillstheir own version, first seen Nov 29, 2026
- aakash1552005/universal-agent-skillstheir own version, first seen Nov 29, 2026
- alexj11324/Mikkatheir own version, first seen Nov 29, 2026
- aspectly-labs/Mikkatheir own version, first seen Nov 22, 2026
- AtilaMedeiros/skillstheir own version, first seen Nov 16, 2026
Used with
Projects with it also use team-composition-analysis, similarity-search-patterns 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.
xfstudioSkillteam-composition-analysis
This skill should be used when the user asks to "plan team
Also in 6 projects that use this
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 7 projects that use this
- +10 more from xfstudio
Other versions23 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 23
- Rain-kl/OpenFlare★ 305same name
- alexj11324/Mikka★ 90same name
- aspectly-labs/Mikka★ 90same name
- kumaran-is/claude-code-onboarding★ 35same name
- xfstudio/skills★ 9same name
- aakash1552005/universal-agent-skills★ 4same 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
13 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 repository117 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-healthSkill
- agent-styleSkill
- angular-best-practicesSkill
- annotateSkill
- api-designSkill
- architecture-decision-recordsSkill
- aws-serverlessSkill
- backend-architectSkill
- backend-patternsSkill
- brainstormSkill
- bug-reportSkill
- changelogSkill
- claude-apiSkill
- cloud-architectSkill
- cloud-run-puppeteerSkill
- code-review-checklistSkill
- code-reviewSkill
- code-simplificationSkill
- codex-sddSkill
- commitSkill
- context-engineeringSkill
- database-architectSkill
- db-reviewSkill
- deep-interviewSkill
- design-reviewSkill
- design-systemSkill
- devops-deploySkill
- diagnoseSkill
- django-patternsSkill
- docker-patternsSkill
- dotnet-backend-patternsSkill
- dreamSkill
- drizzle-orm-expertSkill
- estimateSkill
- event-sourcing-architectSkill
- fastapi-proSkill
- fork-joinSkill
- freezeSkill
- frontend-designSkill
- frontend-patternsSkill
- frontend-ui-dark-tsSkill
- gate-checkSkill
- gemini-api-integrationSkill
- gitlab-ci-patternsSkill
- guardSkill
- handoffSkill
- hotfixSkill
- hybrid-cloud-architectSkill
- kubernetes-architectSkill
- laravel-patternsSkill
- launch-checklistSkill
- learnerSkill
- llm-app-patternsSkill
- localizeSkill
- map-systemsSkill
- map-workflowSkill
- markdown-injection-scannerSkill
- microservices-patternsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 22 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
CREATE INDEX idx_orders_user_id ON orders(user_id).
- Distinctive: line 24
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at DESC).
- Very specific: line 27
CREATE INDEX idx_orders_covering ON orders(user_id, status) INCLUDE (total, created_at).
- Distinctive: line 33
Write-heavy tables with rare reads
“Common” is measured: kept by at least 6 in 10 of the 22 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
Query optimization, indexing, and performance tuning for PostgreSQL, MySQL, and SQLite.
Index Strategy
When to Create Index
```sql -- High selectivity columns (many unique values) CREATE INDEX idx_orders_user_id ON orders(user_id);
-- Composite index: order matters (equality first, then range) CREATE INDEX idx_orders_user_date ON orders(user_id, created_at DESC);
-- Covering index (includes all needed columns) CREATE INDEX idx_orders_covering ON orders(user_id, status) INCLUDE (total, created_at); ```
When NOT to Index
- Low cardinality columns (boolean, status with few values)
- Small tables (< 1000 rows)
- Write-heavy tables with rare reads
Query Patterns
Avoid SELECT *
```sql -- Bad SELECT * FROM orders WHERE user_id = 1;
-- Good (select only needed columns) SELECT id, total, status FROM orders WHERE user_id = 1; ```
Avoid N+1 (use JOIN or subquery)
```sql -- Bad: N+1 queries from application -- Good: Single query with JOIN SELECT o.id, o.total, u.name FROM orders o JOIN users u ON o.user_id = u.id WHERE o.status = 'pending'; ```
Pagination (keyset, not OFFSET)
```sql -- Bad: OFFSET scans all skipped rows SELECT * FROM orders ORDER BY id LIMIT 20 OFFSET 10000;
-- Good: Keyset pagination SELECT * FROM orders WHERE id > 10000 ORDER BY id LIMIT 20; ```
EXPLAIN ANALYZE
```sql EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 1 AND status = 'pending'; ```
Read output:
- Seq Scan = missing index
- Index Scan = good
- Nested Loop with high row count = check join strategy
Schema Anti-Patterns
| Anti-Pattern | Problem | Fix |
| EAV (Entity-Attribute-Value) | No type safety, slow queries | Use JSONB or proper columns |
| God table | Too many columns | Normalize into related tables |
| No constraints | Data integrity issues | Add CHECK, FK, UNIQUE constraints |
| String dates | Sorting/filtering issues | Use TIMESTAMP type |
Connection Pooling
``` App → Pool (min: 5, max: 20) → PostgreSQL ```
Tools: PgBouncer (PostgreSQL), ProxySQL (MySQL).
Related Skills
database-architect— schema designpostgres-patterns— PostgreSQL specificsnosql-expert— NoSQL alternativesdb-review— database code review
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.

