Skip to main content

SQL Query Plan Visualizer

Understand how your query executes and get optimization tips

SQL Query

SQL8 lines
1
2
3
4
5
6
7
8
📋 Formatted Query
SELECT
  u.email,
  u.name,
  COUNT(p.id) as post_count
FROM
  users u
  LEFT JOIN posts p ON p.author_id = u.id
WHERE
  u.role_id = 1
  AND p.published = true
GROUP BY
  u.email,
  u.name
HAVING
  COUNT(p.id) > 5
ORDER BY
  post_count DESC
LIMIT
  20;

Execution Plan & Analysis

Execution Steps (logical order)
1
✅ Index Scan on userslow

Index lookup on "users". ✅ Uses index for efficient access.

2
🔄 Sorthigh

Sorts the result set by the specified column(s). Consider adding an index on the ORDER BY columns to avoid in-memory sort.

3
📊 Aggregate (HashAggregate) on grouped columnsmedium

Groups rows and computes aggregates (COUNT, SUM, etc.). Ensure grouping columns are indexed for large datasets.

4
🔍 Filter (HAVING) on aggregated resultslow

Filters groups after aggregation. Cannot use indexes — applied in-memory.

5
🔗 LEFT JOIN → posts on postshigh

LEFT join with "posts". Ensure join columns have indexes. Outer joins may scan unmatched rows.

6
🔍 Filter (WHERE) on scanlow

Filters rows: u.role_id = 1 AND p.published = true.... Use indexes on filter columns. Avoid leading wildcards in LIKE.

7
📤 Project (SELECT)low

Selects requested columns for the final output. Only selecting needed columns reduces memory usage.

8
✂️ Limitlow

Restricts the number of output rows. Helps reduce data transfer.

Optimization Tips

💡COUNT with GROUP BY requires scanning all matching rows. Consider materialized views for frequent aggregations.
💡Ensure JOIN columns have indexes. Composite indexes covering JOIN + WHERE columns are most effective.

About the SQL Query Plan Visualizer

Visualize SQL execution plans step by step. Understand table scans, joins, sorts, and aggregates.

Paste an EXPLAIN plan output to get a visual breakdown of each step. Includes cost estimates and optimization tips.

How to use

  1. Paste your EXPLAIN output.
  2. The plan renders as a visual tree.
  3. Review each step for optimization.