AI assisted · Free
SQL query explainer
Paste any SQL query — a complex JOIN, a CTE, a subquery, or a window function — and get a plain-English breakdown of every clause, plus notes on potential performance issues.
Frequently asked questions
Which SQL dialects does the explainer support?
The explainer works with standard SQL and handles the most common dialect-specific features from PostgreSQL, MySQL, and SQL Server — including PostgreSQL-specific functions like array_agg and json_build_object, MySQL's GROUP_CONCAT, and SQL Server's TOP clause. For highly dialect-specific syntax, the explanation notes which database the feature is specific to.
What are the most common SQL performance issues the tool flags?
The most frequently flagged issues are SELECT * on large tables (forces a full column scan instead of using a covering index), correlated subqueries in the WHERE clause (which run once per outer row), missing LIMIT on queries that could return millions of rows, and N+1 query patterns visible in subqueries. Each flag includes a specific explanation of why the pattern can be slow.
How do CTEs (WITH clauses) affect query performance?
It depends on the database. In PostgreSQL, CTEs before version 12 are always materialised — the database runs the CTE once and stores the result, even if the outer query never uses it or uses it only partially. In PostgreSQL 12 and later, CTEs may be inlined. In most databases, CTEs improve readability but do not guarantee better performance. The explainer notes when a CTE might be affecting execution plans.
Can I paste queries from ORMs like Prisma or Sequelize?
Yes. Paste the raw SQL that the ORM generates (most ORMs have a logging option to print queries). The explainer works on the SQL itself, not the ORM syntax. This is particularly useful for understanding whether an ORM is producing efficient joins or falling back to N+1 queries.
Reading SQL like a DBA
The fastest way to understand an unfamiliar SQL query is to read it inside-out: start with the innermost subquery or CTE, understand what it produces, then work outward to see how the outer query uses that result set.
Common query patterns:
- JOINs combine rows from two tables. INNER JOIN returns only matching rows. LEFT JOIN returns all rows from the left table, with NULLs for unmatched rows on the right.
- CTEs (WITH clauses) are named temporary result sets that can be referenced like tables. They improve readability but do not always improve performance.
- Window functions (LAG, LEAD, ROW_NUMBER, RANK) compute values across a set of rows related to the current row, without collapsing them into a single group like GROUP BY does.
- Subqueries in WHERE filter rows based on a derived set. Correlated subqueries (that reference the outer query) run once per outer row and can be very slow on large tables.
Need help designing a database schema or optimising slow queries?
Talk to Codalyst about data architecture