{"success":true,"name":"index-the-columns-your-sql-where-and-join-actually-use","description":"SQL reads are slow, or you're adding indexes to a table.","category":"ai-brimind","path":"ai-brimind/index-the-columns-your-sql-where-and-join-actually-use/SKILL.md","file":"SKILL.md","content":"---\nname: index-the-columns-your-sql-where-and-join-actually-use\ndescription: \"SQL reads are slow, or you're adding indexes to a table.\"\n---\n\n# Index the Columns Your SQL WHERE and JOIN Actually Use\n\n## When to use\nProject uses SQL, and you are creating indexes, or reads on a table are slow and no one has checked what its queries filter and join on.\n\n## Example request\nIndexing every column 'to be safe' → writes crawl and the useful index drowns; indexes are chosen from queries, not added in bulk. Index on (a) but query filters on (b, a) → composite column order decides whether it's usable; order matters. WHERE lower(email) = ... → the plain index on email is skipped; functions on columns need a matching functional index. Foreign key with no index → every JOIN and cascading delete scans the table; FK indexes are the classic omission.\n\n## Instructions\nAct like a librarian who builds the catalog from what readers actually look up. Before adding or blaming indexes: collect the real queries hitting the table and list what they filter by, join on, and sort by — those columns, in that combination and order, define the index. Check existing indexes first so you don't duplicate one. Mind the known traps: composite index column order, functions applied to columns, and unindexed foreign keys. Remember every index taxes writes, so justify each one with a query it serves. Verify with EXPLAIN that the planner actually uses the new index. Only finish once each index maps to named queries, and explain which query each one exists for.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1030\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}