SQL Query Explainer
Explain a SQL query in plain English and flag performance and correctness risks.
What it does
Loads as a prompt for the InTouch AI assistant and turns it into a senior database engineer. Given a SQL statement, it restates what the query does, walks the logic in execution order (FROM/JOIN → WHERE → GROUP BY → HAVING → windows → SELECT → ORDER BY → LIMIT), and then audits the query for two classes of problems:
- Correctness risks — silent
LEFT JOIN-to-inner-join filters,NULLcomparison traps,NOT INwith nullable columns, aggregates mixed with non-grouped columns,DISTINCThiding a fan-out duplication, integer division, non-deterministicORDER BY ... LIMIT, and unscopedUPDATE/DELETE. - Performance risks — non-sargable predicates (functions on indexed columns,
leading-wildcard
LIKE, implicit casts),SELECT *, correlated subqueries that should be joins,ORblocking index use, cartesian explosions, and unbounded result sets.
Each finding is rated [HIGH] / [MEDIUM] / [LOW], and HIGH/MEDIUM findings come
with a concrete fix (rewrite, index, or predicate change).
What to feed it
- Required: the SQL query as plain text (any statement type — SELECT, INSERT, UPDATE, DELETE, MERGE, DDL).
- Optional: the SQL dialect (
postgres,mysql,oracle,sqlserver,derby, …), the relevant table/index DDL, and the author's intended goal. Supplying these sharpens the analysis; without them the skill reasons from query structure and states its assumptions.
What it returns
A Markdown report with these sections: Summary, Plain-English Walkthrough, Correctness Risks, Performance Risks, an optional Suggested Rewrite, and Assumptions. When a category has no issues, it says so explicitly rather than inventing findings, and it never fabricates index names, row counts, or schema details.