{"success":true,"name":"verify-sql-foreign-keys-have-indexes-before-blaming-the-data","description":"SQL JOINs or deletes on related tables feel mysteriously slow.","category":"ai-brimind","path":"ai-brimind/verify-sql-foreign-keys-have-indexes-before-blaming-the-data/SKILL.md","file":"SKILL.md","content":"---\nname: verify-sql-foreign-keys-have-indexes-before-blaming-the-data\ndescription: \"SQL JOINs or deletes on related tables feel mysteriously slow.\"\n---\n\n# Verify SQL Foreign Keys Have Indexes Before Blaming the Database\n\n## When to use\nProject uses SQL with related tables, and JOINs, lookups by parent id, or deletes with cascades are slow and nobody has listed the table's indexes.\n\n## Example request\nDeleting one parent row takes seconds → the child table's FK has no index, so the cascade check scans everything; classic and invisible. JOIN on order.customer_id is slow → the FK constraint exists but many databases don't auto-index it; constraint and index are separate things. 'The database is just slow' → the index list was never actually read; blame came before evidence. Same schema fast in MySQL, slow in PostgreSQL → MySQL auto-indexes FKs, PostgreSQL doesn't; engine defaults differ.\n\n## Instructions\nAct like a mechanic who opens the hood before declaring the engine bad. When relational operations are slow: first list the actual indexes on the involved tables (\\d in psql, SHOW INDEX in MySQL, or the schema tool) and check every foreign key column against that list — knowing that a FK constraint does not imply an index in most engines. Confirm the suspicion with EXPLAIN showing a scan on the child table. The fix is usually one CREATE INDEX on the FK column; verify with EXPLAIN again that the plan changed. Only conclude anything about database performance after reading the real index list, and explain which missing index caused which slow operation.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1039\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}