# Slow dbt query? Profile it in VS Code

> Profile a slow dbt query in one click. Altimate Code reviews the compiled SQL for correctness bugs, anti-patterns and cost, then ranks the fixes.

Source: https://altimate.ai/product-highlights/profile-a-slow-dbt-query-execution-plan

[.md](https://altimate.ai/product-highlights/profile-a-slow-dbt-query-execution-plan.md) 

Copy as MD

PowerUser Plugin for dbt

## Profile a dbt Query in One Click and Get Its Bugs, Anti-Patterns and Fixes Ranked

Profile a slow dbt query in one click. Altimate Code reviews the compiled SQL for correctness bugs, anti-patterns and cost, then ranks the fixes.

Atharva ShahJul 31, 2026Oct 16, 20264 min read

 Profile a dbt query in one click and get its bugs, anti-patterns and fixes ranked 

TL;DR

-   **What it is.** A Profile Query button in the Query Results panel. It sends your compiled SQL to Altimate Code with the prompt written. Altimate Code then runs its own SQL tools on it.
-   **Who it is for.** Analytics engineers with a slow dbt query, or a model they cannot fully trust. The model returns rows, but is it right in every case?
-   **What you get.** A report that leads with correctness bugs, lists the anti-patterns and ranks the fixes. You apply them in the same chat.

A slow dbt query is easy to notice. A wrong one is not. A model can return plausible rows for months and still hide a bug in one branch of a CASE expression. Reviewing it by hand means reading every CTE. Asking a chatbot means writing a prompt that names every check you care about. You only find the checks you thought to ask for. That gap grows as more of your SQL comes from an AI assistant.

## Click Profile Query Once the Query Returns Results

Run the query the way you already do, with Cmd+Enter on a Mac or Control+Enter elsewhere. Once results come back, a **Profile Query** button becomes available in the Query Results toolbar. It appears only when there is data to profile.

 The Query Results panel for customers.sql in the jaffle-shop-core-demo project, where you profile a slow dbt query. Badge 1 marks the Profile Query button next to Optimize Warehouse, and badge 2 marks the label query result 100 x 14. 

Clicking it opens an Altimate Code chat named after your file. The full prompt is already written. The SQL it sends is the compiled query, which is what your warehouse runs. It falls back to the raw text only when no compiled version exists.

The prompt asks for four things, in this order:

| Order | Check | Example finding |
| --- | --- | --- |
| 1 | Correctness | A NULL case that returns 0 |
| 2 | Performance | An aggregation before a join |
| 3 | Cost | A full scan the warehouse cannot prune |
| 4 | Best practice | `SELECT *` in the outer query |

## Read the Correctness Bug Before the Style Warnings

[Altimate Code](https://help.altimate.ai/dbt-power-user/teammates/altimate-code/) calls its analyze and rewrite tools, which add a deterministic check on top of the model's answer. The report puts correctness first. On the customers model it found that two columns handle the no-orders case differently.

 The Profile: customers.sql chat under the heading Correctness bug, the real finding, not just style. It explains that 38 of 100 customers never ordered, so 38% of customers show a return\_rate of 0%, and suggests else null. 

Of 100 customers, 38 never placed an order. The model reports a 0% return rate for all 38, when the right value is NULL. The sql\_analyze tool then lists three more findings:

-   `SELECT *` in the outer query.
-   A division by a column that can be zero.
-   An aggregation before a join.

 The sql\_analyze findings block: a warning for SELECT \* in the outer query, a warning for division by the column number\_of\_orders, an info note that DATEDIFF is dialect-specific, and an error flagging aggregation performed before JOIN on customer\_orders. 

## Apply the Ranked Fixes in the Same Session

The report ends with recommendations ranked by impact. Fixing the NULL handling comes first, because it affects 38% of rows. Replacing `SELECT *` with an explicit column list comes second. The report also names a pattern to keep. Here, the pre-aggregate-then-join pattern needed no rewrite.

Spotlight 1 video, dbt SQL review in one click with Profile Query

Ask Altimate Code to patch the model, or ask a follow-up about any finding, in the same chat. For the rest of the panel, see the [Query Results panel guide](https://help.altimate.ai/dbt-power-user/test/queryResults/).

### Install the dbt VS Code extension

[Install from Marketplace](https://marketplace.visualstudio.com/items?itemName=innoverio.vscode-dbt-power-user) [Book a 30-min demo →](https://calendly.com/d/ctnv-rbc-yr3/altimate-ai-overview) [Read the docs →](https://help.altimate.ai/dbt-power-user/) 

## Frequently Asked Questions

Why is my dbt model slow?

Usually because of something the SQL text does not show. A filter may be written so the warehouse cannot prune on it. A join may multiply rows before its filter runs. Profile Query reads the compiled SQL with Altimate Code's tools and names the cause in plain English.

Where is the Profile Query button?

In the Query Results panel toolbar. It only appears once a query has returned results, so run the query first. If you have results and no button, the panel is showing a view other than the default query result.

What does Profile Query check?

Correctness first, then performance, cost and best practices. In the demo it found a NULL handling bug that affected 38 of 100 customers. It also flagged SELECT \* in the outer query, a division by a column that can be zero and an aggregation before a join.

Does it profile my Jinja or my compiled SQL?

The compiled SQL, and it falls back to the raw query text only when no compiled version is available. This is the right choice for review work, because the compiled query is what your warehouse runs.

Why use this instead of pasting my SQL into a chatbot?

A chatbot reasons only about the text you pasted and the checks you thought to name. Profile Query writes the prompt for you, and Altimate Code adds deterministic tools such as sql\_analyze. Those tools return the same findings for the same SQL, whatever words you would have used.

Can it explain the execution plan?

Yes, when you ask. Altimate Code's sql\_explain tool runs your warehouse's own EXPLAIN and reads the plan back. Snowflake does not support EXPLAIN ANALYZE, so there you get the plan and its estimates rather than measured runtimes.

Why did profiling fail on my query?

The most common cause is bind placeholders. The warehouse cannot explain a query that still carries `?`, `:name` or `$1`. Replace each placeholder with a real value, run the query again, then click Profile Query.

Will it change my model on its own?

No. It reports the findings and asks whether you want the fixes applied. You decide what changes in your model file. You can also ask follow-up questions about any finding before you accept a fix.

On this page

-   Click Profile Query Once the Query Returns Results 
-   Read the Correctness Bug Before the Style Warnings 
-   Apply the Ranked Fixes in the Same Session 

## Related Resources

PowerUser Plugin for dbt Ask Altimate Code About a dbt Model Straight from the Lineage Graph

https://altimate.ai/product-highlights/ask-ai-about-dbt-lineage-in-vs-code

PowerUser Plugin for dbt Generate dbt Unit Tests in the Documentation Editor, Next to Your Docs and Data Tests

https://altimate.ai/product-highlights/generate-dbt-unit-tests-in-the-documentation-editor

PowerUser Plugin for dbt Profile Every CTE in a dbt Model to Find the Join That Inflates Your Rows

https://altimate.ai/product-highlights/debug-a-dbt-model-by-profiling-each-cte

Help Doc BigQuery Cost Estimator

https://help.altimate.ai/dbt-power-user/test/bigquerycost/

## Install the dbt VS Code Extension. Free to Start.

Power User for dbt is an open source VS Code extension that adds column lineage, autocomplete, AI docs, query previews and health checks to your dbt project.

[Install from Marketplace](https://marketplace.visualstudio.com/items?itemName=innoverio.vscode-dbt-power-user) [Book a Demo](https://calendly.com/d/ctnv-rbc-yr3/altimate-ai-overview) 

[Read the docs →](https://help.altimate.ai/dbt-power-user/) 

 The Altimate platform: team spend by warehouse, dbt column lineage and an Altimate Code session recap
