PostgreSQL Code Review
Quick Reference
| Issue Type | Reference |
|---|
| Missing indexes, wrong index type, query performance | references/indexes.md |
| JSONB queries, operators, GIN indexes |
references/jsonb.md |
| Connection leaks, pool configuration, timeouts |
references/connections.md |
| Isolation levels, deadlocks, advisory locks |
references/transactions.md |
Review Checklist
- - [ ] WHERE/JOIN columns have appropriate indexes
- [ ] Composite indexes match query patterns (column order matters)
- [ ] JSONB columns use GIN indexes when queried
- [ ] Using proper JSONB operators (
->, ->>, @>, ?) - [ ] Connection pool configured with appropriate limits
- [ ] Connections properly released (context managers, try/finally)
- [ ] Appropriate transaction isolation level for use case
- [ ] No long-running transactions holding locks
- [ ] Advisory locks used for application-level coordination
- [ ] Queries use parameterized statements (no SQL injection)
When to Load References
- - Reviewing SELECT queries with WHERE/JOIN → indexes.md
- Reviewing JSONB columns or JSON operations → jsonb.md
- Reviewing database connection code → connections.md
- Reviewing BEGIN/COMMIT or concurrent updates → transactions.md
Review Questions
- 1. Will this query use an index or perform a sequential scan?
- Are JSONB operations using appropriate operators and indexes?
- Are database connections properly managed and released?
- Is the transaction isolation level appropriate for this operation?
- Could this cause deadlocks or long-running locks?
PostgreSQL 代码审查
快速参考
references/jsonb.md |
| 连接泄漏、连接池配置、超时设置 |
references/connections.md |
| 隔离级别、死锁、咨询锁 |
references/transactions.md |
审查清单
- - [ ] WHERE/JOIN列已建立适当的索引
- [ ] 复合索引匹配查询模式(列顺序很重要)
- [ ] 查询JSONB列时使用GIN索引
- [ ] 使用正确的JSONB操作符(->、->>、@>、?)
- [ ] 连接池配置了适当的限制
- [ ] 连接已正确释放(使用上下文管理器、try/finally)
- [ ] 针对使用场景选择适当的事务隔离级别
- [ ] 没有持有锁的长时间运行事务
- [ ] 使用咨询锁进行应用级协调
- [ ] 查询使用参数化语句(防止SQL注入)
何时加载参考文档
- - 审查包含WHERE/JOIN的SELECT查询 → indexes.md
- 审查JSONB列或JSON操作 → jsonb.md
- 审查数据库连接代码 → connections.md
- 审查BEGIN/COMMIT或并发更新 → transactions.md
审查问题
- 1. 此查询将使用索引还是执行顺序扫描?
- JSONB操作是否使用了适当的操作符和索引?
- 数据库连接是否得到正确管理和释放?
- 事务隔离级别是否适合此操作?
- 是否可能导致死锁或长时间持有锁?