database-optimization
Skill2.7k starsChanged 10 months agoApache-2.0View on GitHub
Query optimization, indexing strategies, and database performance tuning for PostgreSQL and MySQL
3 other projects use a version of this.
Trending
Less talk lately.thin dataabout the whole repository
Most recently taken up by
- komluk/scaffoldingtheir own version, first seen Sep 28, 2026
- valentinesamuel/claude-skillsword for word, first seen Apr 19, 2026
- kienbui1995/magic-powerstheir own version, first seen Apr 10, 2026
Who's talking about rohitg00/awesome-claude-code-toolkit
- sudosubin/agents.nix“agent-skills.github.rohitg00.awesome-claude-code-toolkit: init at 0.5.0”GitHub · Oct 1, 2026
- uizze/uizze“docs: track Claude Code Toolkit distribution PR”GitHub · Aug 18, 2026
- hslee16/Archy“chore(distribution): submit archy to awesome-mcp-servers and awesome-claude-code-toolkit”GitHub · Jul 25, 2026
- Nexcyfr/nexcy-site“Vague 1D : workflows et templates internes Claude Code core”GitHub · Jun 11, 2026
- taeyeon-Kim/claude-starter-kit“감사 리포트 2026-04-14 (2차): Warning 0건, Info 4건 — Phase 3.8 첫 실행”GitHub · Apr 14, 2026
The biggest 5 of 7 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 7
Talked about on GitHub (7 times).
On GitHub · 7
- Oct 1, 2026agent-skills.github.rohitg00.awesome-claude-code-toolkit: init at 0.5.0 — sudosubin/agents.nix0 reactions
- Aug 18, 2026docs: track Claude Code Toolkit distribution PR — uizze/uizze0 reactions
- Jul 25, 2026chore(distribution): submit archy to awesome-mcp-servers and awesome-claude-code-toolkit — hslee16/Archy0 reactions · 4 comments
- Jun 11, 2026Vague 1D : workflows et templates internes Claude Code core — Nexcyfr/nexcy-site0 reactions · 1 comment
- Apr 14, 2026감사 리포트 2026-04-14 (2차): Warning 0건, Info 4건 — Phase 3.8 첫 실행 — taeyeon-Kim/claude-starter-kit0 reactions
2 more on GitHub
- Apr 13, 2026Audit candidate: rohitg00/awesome-claude-code-toolkit — xiaolai/nlpm0 reactions · 5 comments
- Apr 6, 2026Audit candidate: rohitg00/awesome-claude-code-toolkit — xiaolai/nlpm0 reactions · 2 comments
Other versions3 projects use a version of this.
Word for word · 1
- valentinesamuel/claude-skills★ 1100% same
Edited · 0
None found.
Wrote their own version · 2
- komluk/scaffolding★ 15same name
- kienbui1995/magic-powers★ 0same name
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 repository40 other files it gives its agents.
- rules/agents.mdAGENTS.md
- accessibility-wcagSkill
- agentkit-seoSkill
- api-design-patternsSkill
- authentication-patternsSkill
- aws-cloud-patternsSkill
- ci-cd-pipelinesSkill
- claude-memory-kitSkill
- continuous-learningSkill
- data-engineeringSkill
- deep-diveSkill
- devops-automationSkill
- django-patternsSkill
- docker-best-practicesSkill
- frontend-excellenceSkill
- git-advancedSkill
- golang-idiomsSkill
- graphql-designSkill
- kubernetes-operationsSkill
- llm-integrationSkill
- manage-skillsSkill
- mcp-developmentSkill
- microservices-designSkill
- mobile-developmentSkill
- monitoring-observabilitySkill
- nextjs-masterySkill
- performance-optimizationSkill
- postgres-optimizationSkill
- prompt-engineeringSkill
- python-best-practicesSkill
- react-patternsSkill
- redis-patternsSkill
- rust-systemsSkill
- security-hardeningSkill
- springboot-patternsSkill
- styleseedSkill
- tdd-masterySkill
- testing-strategiesSkill
- typescript-advancedSkill
- websocket-realtimeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 8 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Always run EXPLAIN ANALYZE before optimizing.
- Distinctive: line 33
Use for: equality, range queries, sorting.
- Distinctive: line 40
Use when queries always filter on a specific condition.
- Distinctive: line 98
Use PgBouncer in transaction mode for serverless/high-connection scenarios
- Distinctive: line 104
Use ProxySQL for connection multiplexing
- Distinctive: line 112
Never read-after-write from a replica.
- Distinctive: line 113
Use connection-level routing, not query-level
- Very specific: line 156
Run EXPLAIN ANALYZE and read the plan
- Distinctive: line 157
Check for sequential scans on tables with >10K rows
- Very specific: line 158
Verify index usage (check idx_scan in pg_stat_user_indexes)
- Distinctive: line 159
Look for implicit type casts that prevent index use
- Very specific: line 161
Add LIMIT to queries that only need a subset
- Very specific: line 162
Use EXISTS instead of COUNT(*) > 0
- Very specific: line 164
Avoid functions on indexed columns in WHERE clauses
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Optimization
EXPLAIN Analysis
Always run EXPLAIN ANALYZE before optimizing. Read the output bottom-up.
-- PostgreSQL
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;
-- MySQL
EXPLAIN ANALYZE SELECT ...;Key metrics to watch:
- Seq Scan on large tables = missing index
- Nested Loop with high row count = consider hash/merge join
- Sort without index = add index on sort column
- Rows estimated vs actual divergence = stale statistics, run
ANALYZE
Index Strategies
B-tree (default, most cases)
CREATE INDEX idx_users_email ON users (email);
CREATE INDEX idx_orders_user_date ON orders (user_id, created_at DESC);Use for: equality, range queries, sorting. Column order matters in composite indexes: put equality columns first, then range/sort columns.
Partial Index (PostgreSQL)
CREATE INDEX idx_orders_pending ON orders (created_at)
WHERE status = 'pending';Use when queries always filter on a specific condition. Dramatically smaller than full indexes.
GIN (PostgreSQL - arrays, JSONB, full-text)
CREATE INDEX idx_products_tags ON products USING GIN (tags);
CREATE INDEX idx_docs_search ON documents USING GIN (to_tsvector('english', content));GiST (PostgreSQL - spatial, range types)
CREATE INDEX idx_locations_point ON locations USING GiST (coordinates);
CREATE INDEX idx_events_period ON events USING GiST (tsrange(start_at, end_at));Covering Index (index-only scans)
-- PostgreSQL
CREATE INDEX idx_users_email_name ON users (email) INCLUDE (name);
-- MySQL
CREATE INDEX idx_users_email_name ON users (email, name);N+1 Query Detection
Symptom: 1 query to fetch parent + N queries for each child.
# BAD: N+1
users = db.query(User).all()
for user in users:
print(user.orders) # triggers query per user
# GOOD: eager load
users = db.query(User).options(joinedload(User.orders)).all()// BAD: N+1
const users = await User.findAll();
for (const user of users) {
const orders = await Order.findAll({ where: { userId: user.id } });
}
// GOOD: batch load
const users = await User.findAll({ include: [Order] });Detection: enable query logging, count queries per request. More than 10 queries for a single endpoint is a red flag.
Connection Pooling
Rule of thumb: pool_size = (core_count * 2) + disk_count
Typical web app: 10-20 connections per app instancePostgreSQL:
- Use PgBouncer in transaction mode for serverless/high-connection scenarios
- Set
idle_in_transaction_session_timeout = '30s' - Monitor with
pg_stat_activity
MySQL:
- Set
max_connectionsbased on available RAM (each connection uses ~10MB) - Use ProxySQL for connection multiplexing
- Monitor with
SHOW PROCESSLIST
Read Replicas
- Route all
SELECTqueries to replicas - Route all writes to primary
- Account for replication lag (typically 10-100ms)
- Never read-after-write from a replica; use primary for consistency-critical reads
- Use connection-level routing, not query-level
# SQLAlchemy read replica routing
class RoutingSession(Session):
def get_bind(self, mapper=None, clause=None):
if self._flushing or self.is_modified():
return engines["primary"]
return engines["replica"]Partition Strategies
Range Partitioning (time-series data)
-- PostgreSQL
CREATE TABLE events (
id bigint GENERATED ALWAYS AS IDENTITY,
created_at timestamptz NOT NULL,
data jsonb
) PARTITION BY RANGE (created_at);
CREATE TABLE events_2025_q1 PARTITION OF events
FOR VALUES FROM ('2025-01-01') TO ('2025-04-01');
CREATE TABLE events_2025_q2 PARTITION OF events
FOR VALUES FROM ('2025-04-01') TO ('2025-07-01');Hash Partitioning (even distribution)
CREATE TABLE sessions (
id uuid PRIMARY KEY,
user_id bigint NOT NULL
) PARTITION BY HASH (user_id);
CREATE TABLE sessions_0 PARTITION OF sessions FOR VALUES WITH (MODULUS 4, REMAINDER 0);
CREATE TABLE sessions_1 PARTITION OF sessions FOR VALUES WITH (MODULUS 4, REMAINDER 1);Partition when tables exceed 50-100GB or when you need to drop old data quickly.
Query Optimization Checklist
- Run
EXPLAIN ANALYZEand read the plan - Check for sequential scans on tables with >10K rows
- Verify index usage (check
idx_scaninpg_stat_user_indexes) - Look for implicit type casts that prevent index use
- Replace
SELECT *with specific columns - Add
LIMITto queries that only need a subset - Use
EXISTSinstead ofCOUNT(*) > 0 - Batch
INSERT/UPDATEoperations (500-1000 rows per batch) - Avoid functions on indexed columns in
WHEREclauses - Monitor slow query log (pg:
log_min_duration_statement = 100)
Dangerous Patterns
LIKE '%term%'on unindexed columns (use full-text search instead)ORDER BY RANDOM()(useTABLESAMPLEor application-level randomization)SELECT DISTINCTmasking a join problem- Missing
WHEREonUPDATE/DELETE(always verify withSELECTfirst) - Long-running transactions holding locks
- Using
OFFSETfor deep pagination (use keyset/cursor pagination instead)
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.

