← ClaudeAtlas

postgres-query-reviewlisted

Review PostgreSQL queries (SQL) from performance and correctness angles. Inspect execution-plan interpretation, index usability, join method/order, sort/aggregate cost, pagination, parameter binding, and anti-patterns. Use when writing/modifying SQL or diagnosing slow queries. Applies the principles of "Friendly SQL Tuning", verified against the official PostgreSQL documentation.
ch4570/vulpora · ★ 1 · API & Backend · score 67
Install: claude install-skill ch4570/vulpora
# PostgreSQL Query Review Official PostgreSQL `Performance Tips`/`Indexes` docs + query-tuning insights. For the underlying principles, see `reference/principles.md`. ## Review order (proceed exactly like this) 1. **Understand what the query is asking** (result set, cardinality, frequency: OLTP vs batch). 2. **Look at the execution plan.** `EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)` — for detailed interpretation see `reference/kb/execution-plan.md`. 3. **Inspect index usability** — `reference/kb/index-tuning.md`. 4. **Inspect join method/order** — `reference/kb/join-tuning.md`. 5. **Scan for anti-patterns** — `reference/kb/sql-antipatterns.md`. 6. Present a **fix + re-measurement method** together with severity. ## Quick checklist (HIGH-and-above candidates) - [ ] **Is there an index on the WHERE/JOIN/ORDER BY columns?** If not, full scan. - [ ] **Is the leading column not transformed?** `WHERE lower(col)=`, `WHERE col::text=`, `WHERE date(ts)=`, `WHERE col + 0 =` → disables the index. Use an expression index or transform the constant side. - [ ] **Do the types match?** Column/parameter type mismatch → casting bypasses the index. - [ ] **Is `SELECT *` not overused?** Only needed columns → covering-index / Index-Only Scan opportunity. - [ ] **Is there an unnecessary `DISTINCT`/`ORDER BY`/`UNION`?** `UNION`→`UNION ALL` (when no duplicates). - [ ] **Is pagination using a large `OFFSET`?** → consider keyset (cursor) pagination. - [ ] **Correlated subquery / N+1**: is