{"success":true,"name":"run-explain-before-trusting-a-slow-sql-query-fix","description":"A SQL query is slow and you're about to optimize it.","category":"ai-brimind","path":"ai-brimind/run-explain-before-trusting-a-slow-sql-query-fix/SKILL.md","file":"SKILL.md","content":"---\nname: run-explain-before-trusting-a-slow-sql-query-fix\ndescription: \"A SQL query is slow and you're about to optimize it.\"\n---\n\n# Run EXPLAIN Before Trusting a Slow SQL Query Fix\n\n## When to use\nProject uses SQL, and a query is slow, and you are about to add an index, rewrite it, or add caching without having read its execution plan.\n\n## Example request\nAdding an index by gut feeling → the planner never uses it; EXPLAIN would have shown the real scan. Rewriting the query 'more efficiently' → the JOIN order was fine, the missing index wasn't; the fix targeted the wrong thing. Adding a cache in front → the query stays slow for every cache miss; caching hides root causes. Fast in dev, slow in production → dev has 100 rows, production has a million; plans depend on data size.\n\n## Instructions\nAct like a performance investigator who refuses to optimize what hasn't been measured. Before changing anything: run EXPLAIN (or EXPLAIN ANALYZE) on the slow query against realistic data volume, and name the actual bottleneck — full table scan, missing index, bad join order, sorting on disk, fetching too many rows. State your hypothesis, then verify the plan confirms it. Prefer the database's own remedies (an index, a query rewrite the planner can use, updated statistics) before adding external layers like caching. If the plan is confusing, investigate further instead of guessing. Only apply the fix once the plan explains the slowness, and re-run EXPLAIN afterward to prove the plan actually changed.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1028\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}