Skip to content

AI Query Explanation

Explain a SQL script section by section in a dedicated dialog with a clear query preview, readable markdown output, and a separately configurable explain model.

How the current flow works

The current explain flow no longer depends on the old “highlight text and right-click” behavior. Instead, from the SQL workspace you open the `Query Explanation` dialog, the app takes the current SQL, renders a line-numbered preview, and asks the AI for a markdown explanation.
The important detail is that this dialog is dedicated to explanation work: it has loading, error, and fallback states, plus a separate explanation surface instead of stuffing everything into the editor.

What does the dialog show?

The Query panel

Shows the exact SQL being explained with line numbers so you can track each section. This makes the explanation much easier to verify than reading one long blob of text.

The Explanation panel

Shows formatted markdown for readability. This is where the AI explains the purpose of each section, the overall logic, and any important caveats.

Example query to explain

WITH monthly_revenue AS (

SELECT DATE_TRUNC('month', o.created_at) AS month,

u.id AS user_id,

SUM(o.total_amount) AS revenue

FROM orders o

JOIN users u ON o.user_id = u.id

WHERE o.status = 'completed'

GROUP BY 1, 2

)

SELECT user_id, month, revenue FROM monthly_revenue;

Which model is used for explanations?

The explanation dialog uses the `Explain` role from `Configure AI`. You can let this role inherit the Assistant model, or split it to a different model when you want explanations to be longer, more accurate, or cheaper.

Share the Assistant model

This is the simplest option when you want a minimal configuration and do not need a quality split between chat and explain.

Use a dedicated Explain model

Great when you want query explanations to use a model specialized for step-by-step analysis, clearer prose, or lower cost than the main assistant.

When should you use it?

Read legacy queries

Useful when revisiting old scripts, stored procedures, or teammate queries without tracing every line manually.

Understand logic before editing

Helps you understand intent before optimizing, splitting steps, or rewriting the statement so you do not edit blindly.

Faster onboarding

New team members can understand complex queries faster without searching every syntax form or window function by hand.

AI Query Explanation is a natural-language explanation layer, not the database engine’s real `EXPLAIN` / `EXPLAIN ANALYZE` output. If you need an actual execution plan for performance debugging, use the workspace plan/analyze tooling.

Ready to explore data?

Join the community on GitHub to contribute to the smartest local database IDE.

Launch App