SQL Anti-Patterns
Goal
Detect SQL anti-patterns and return safe PostgreSQL-first remediations with verifiable migration plans.
Default Posture
- Preserve relational guarantees (types, keys, constraints).
- Prefer one logical model + physical optimization (indexes/partitioning), not schema cloning.
- Keep migrations reversible and fail-closed.
Workflow
- Classify mode:
design,review, ormigration. - Always read
references/review-checklist.md. - For migration/production DDL/backfill/cutover, also read
references/migration-playbook.md. - Load only symptom-relevant anti-pattern references.
- Prioritize integrity risk before operational risk.
Routing (symptom -> reference)
- CSV IDs / comma-separated IDs ->
references/jaywalking.md - Tree traversal pain / fixed-depth joins ->
references/naive-trees.md - Missing FKs / app-side integrity checks / orphans ->
references/keyless-entry.md - EAV core model ->
references/entity-attribute-value.md *_type + *_idpolymorphism ->references/polymorphic-associations.md- Repeating columns (
tag1,phone1, etc.) ->references/multicolumn-attributes.md - Table/column schema cloning by year/tenant ->
references/metadata-tribbles.md - Phased rollout/cutover template ->
references/migration-playbook.md
PostgreSQL Defaults
- Use FK-backed relationships and index referencing FK columns on write-heavy paths.
- Use recursive CTEs for hierarchies (
SEARCH/CYCLEon PG14+ when needed). - Validate partition pruning with
EXPLAIN (ANALYZE, BUFFERS). - For dynamic attributes, keep relational core + bounded
jsonbtail.
Response Contract
For each anti-pattern, provide:
SignalRiskPreferred designImplementation(concrete SQL)Migration(phased steps + validation + rollback trigger)Caveats(version/engine constraints)
References
references/review-checklist.mdreferences/migration-playbook.mdreferences/jaywalking.mdreferences/naive-trees.mdreferences/keyless-entry.mdreferences/entity-attribute-value.mdreferences/polymorphic-associations.mdreferences/multicolumn-attributes.mdreferences/metadata-tribbles.md