postgresql-query-opt
3
总安装量
3
周安装量
#57517
全站排名
安装命令
npx skills add https://github.com/sraloff/gravityboots --skill postgresql-query-opt
Agent 安装分布
gemini-cli
3
github-copilot
3
codex
3
kimi-cli
3
cursor
3
amp
3
Skill 文档
PostgreSQL Query & Optimization
When to use this skill
- Debugging slow queries.
- Designing indexes for new schemas.
- Analyzing
EXPLAINoutput. - Writing complex CTEs or recursive queries.
1. Indexing Strategy
- B-Tree: Default. Good for equality and range (
<,<=,=, etc.). - GIN: Essential for
jsonb,array, and full-text search (tsvector). - Partial Indexes: Use
WHEREclause in index definition to save space (e.g.,WHERE is_active = true). - Covering Indexes: Use
INCLUDEto store extra payload columns in the index leaf nodes (avoids heap lookup).
2. Query Patterns
- CTEs: Use Common Table Expressions (
WITH) for readability. Note: Postgres >= 12 optimizes them well (materialization boundary is smarter). - EXPLAIN: Always run
EXPLAIN (ANALYZE, BUFFERS)to see actual execution times and I/O costs. - Nulls: Be aware of
NOT IN (...)with nulls (can yield unexpected results); preferNOT EXISTS.
3. Performance Pitfalls
- Seq Scans: Acceptable for small tables; bad for large ones.
- N+1: Detecting N+1 queries in application layers.
- Functions in WHERE: Avoid
WHERE function(column) = val; this kills index usage. Use expression indexes if needed.