CertSafari
    Databricks Certified Data Analyst Associate· Lessons

    Domain 5 · Lesson 19/39

    Query profile and performance insights for slow queries

    Identify poorly performing queries in the Databricks Intelligence platform, such as Query Insights, Query Profiler log, etc.

    20 min read
    2.5% of exam
    7 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Open the query profile for a specific past query run from Query History, the SQL editor, a notebook or a system.query.history record
    • Find the expensive step in a profile using Top operators, DAG metrics and verbose mode
    • Match a performance insight such as spill, uneven data distribution or an exploding join to its recommended fix
    • Tell a query that was slow to execute from one that waited in the warehouse queue
    • Share a query profile by URL or as a JSON file, depending on the recipient's permissions

    Key concept

    Query profile — A query profile records how one specific query run actually executed: every operator with its measured time, rows and memory, plus the performance insights Databricks raised. You read it to find the step that cost the most, then fix that step instead of guessing.

    1.Opening the profile of a past query run

    Every query that runs on a SQL warehouse or serverless compute leaves a record, and the way into its execution details is Query History. Say a dashboard query that usually takes ten seconds took four minutes yesterday afternoon. Click Query History in the sidebar, narrow the list down, and click the query's name. The list can be filtered by user, date range, compute, duration, query status, statement type, statement ID and query tags, so finding yesterday's slow run is a matter of setting a date range and a duration filter. To spot the slowest queries across a whole warehouse instead of one known query, sort by duration in the UI or in the system table, as covered in Query history page and system.query.history.

    Clicking the query opens a query details panel on the right. It shows the run's status (Queued, Running, Finished, Failed or Cancelled), the user and compute, a UUID for this execution, the full statement, popular metrics with filter icons showing what percentage of data was pruned during scanning, and the wall-clock duration. Below the duration there is a breakdown into scheduling, query optimization and file pruning, and execution time. The panel also holds a small preview of the execution graph and a See longest operators for this query button. Click See query profile to open the full profile.

    The profile contains measurements from that particular execution: how long each operator ran, how many rows it handled, and how much memory it used. Other places in the workspace answer different questions. Catalog Explorer describes tables, and a warehouse's Monitoring tab shows load on the whole warehouse. Neither one breaks a single run down operator by operator.

    To view a profile, you must own the query or have at least CAN MONITOR on the SQL warehouse that ran it. Without one of those, the query can still be in the list, but its profile will not open for you.

    A cache hit is fast because nothing actually ran, and that is why it has nothing to profile. If you rerun a query to study it and get "Query profile is not available", force a real execution with a trivial edit, such as changing or removing the LIMIT.

    Checkpoint 1 of 9· Put it in order

    A dashboard query that usually takes ten seconds took four minutes yesterday afternoon. Put the steps to open that run's query profile in order.

    1. 1.Click Query History in the sidebar
    2. 2.Click See query profile to open the full profile
    3. 3.Filter the list by date range and duration to find yesterday's slow run
    4. 4.Click the query's name to open the query details panel on the right

    Checkpoint 2 of 9· Check yourself

    An analyst can see a colleague's slow query in Query History, but its profile won't open for them. The analyst does not own the query. Which access would let them open the profile?

    Checkpoint 3 of 9· Exam question

    A data analyst wants to investigate why a specific SQL query ran unusually slowly yesterday. Where in Databricks SQL should they go to open that query's detailed execution profile?

    Sources12

    2.Finding the expensive step: top operators, the DAG and verbose mode

    The detailed profile has summary tabs on the left and a graph on the right. The left tabs are Details (summary metrics), Top operators and Query text. Top operators is the fastest route to a diagnosis because it ranks the most expensive operators in the query. You can start from the costliest step instead of reading the plan from the top.

    The right half is the directed acyclic graph (DAG) of operators. Each node can display Time spent, Memory peak or Rows. Click a metric to switch which one the graph reports. Each one points to a different kind of problem. Time spent shows where the clock went. Rows shows where row counts jump unexpectedly, such as a join that outputs far more rows than it took in. Memory peak shows operators under memory pressure. You can search the graph to highlight operators or columns, zoom in on part of it, and click any operator to open a panel with its detailed metrics. Some non-Photon operations run as a group and share metrics, so they all show their parent operator's value for a given metric. For Databricks SQL queries, the kebab menu also offers Open in Spark UI.

    By default the graph hides metrics for some operations, because those operations are unlikely to cause bottlenecks. When the visible operators don't explain the runtime, use the menu at the top of the page and choose Enable verbose mode. It shows every operation and adds extra metrics.

    The operators you will meet most often in a profile, and what each one means for cost
    OperatorWhat happenedWhat to watch for
    ScanData was read from a data source and output as rowsFull table scans; check the pruning shown in the query metrics
    FilterInput was reduced by a criterion such as a WHERE clauseA filter that runs late, after expensive work has already happened
    JoinRows from multiple relations were combined into one setOutput rows far above input rows (an exploding join)
    UnionRows from relations with the same schema were concatenatedLarge inputs that are combined and then mostly discarded
    ShuffleData was redistributed or repartitionedExpensive, because data moves between executors on the cluster
    Hash / SortRows were grouped by key and aggregated with SUM, COUNT or MAXHigh memory peak on large groupings

    Checkpoint 4 of 9· Check yourself

    In a query profile, the operators visible in the DAG add up to only a fraction of the query's four-minute runtime. What should the analyst do next to find the missing cost?

    Sources1

    3.Performance insights: Databricks names the likely problem

    Operator metrics show you where time went. Performance insights go a step further and say what is probably wrong. When a query runs, Databricks can return insights that flag a likely cause, and each comes with a recommendation. They appear in two places. The query details panel shows a summary of the most impactful insights, ranked by their estimated effect on total task duration. The Performance insights tab in the full profile shows each insight in detail. Some insights don't flag a problem. They are labelled Accelerated and report optimizations Databricks already applied, such as reading less data thanks to Automatic Liquid Clustering, or choosing a broadcast join based on previous runs. They need no action.

    For insights you can act on, Optimize opens Genie Code. If the fix is a query change, Genie Code rewrites the query and presents the changes for your approval. If the fix involves the table or compute, it summarizes the recommended actions in plain language.

    Common performance insights and the action each one recommends
    What the insight reportsRecommended action
    Data spilled to disk because it did not fit in memoryIncrease the warehouse size to add memory; reduce the rows, columns or size of large columns
    Data is distributed unevenly across computing resourcesReview the data distribution, then use key salting or pre-aggregation
    The join produces significantly more rows than it readsChange the join condition or reduce input rows on both sides
    The join produces significantly fewer rows than it readsAdd filters before the join to reduce input rows
    The table is clustered or partitioned by keys not used in filtersAdd filters on the clustering or partitioning keys
    The query projects all columns from the tableProject only the columns you need
    The table scan reads many small filesEnable Predictive Optimization or run OPTIMIZE; switch partitioned tables to liquid clustering
    Cost-based optimizer statistics are missing or incompleteCollect statistics so the optimizer can produce a better plan
    Photon can't accelerate this operationReview Photon limitations and use a supported execution path
    The query waited in the warehouse queueIncrease the maximum number of clusters on the warehouse
    A cloud storage request was throttled by the cloud providerAsk your administrator to request higher storage request limits from the cloud provider

    Spill is the classic sign of memory pressure. Picture a GROUP BY over billions of rows that finishes but runs far too long. In its profile, the aggregation operator's memory peak is above what the warehouse has available, and data was spilled to disk. Each insight in the table has its own signature, and spill's signature is memory. That means the fix is either more memory (a larger warehouse) or less data reaching the operator (fewer rows, fewer columns, smaller wide columns). Throttling, queueing and table layout each produce their own, different insight.

    Skew looks different. The stage's total work may be reasonable, but one or a few tasks take much longer than the rest. In a join or aggregation, the usual cause is that a few key values hold most of the data. The task that gets those keys becomes the straggler that everything else waits for. The matching insight reports data distributed unevenly across computing resources. The fix targets that distribution: check how the join key's values are spread, then salt the hot keys or pre-aggregate. A larger warehouse doesn't help much, because the one overloaded task is still doing most of the work. Collecting statistics and avoiding Photon limitations are fixes for other insights, not this one.

    Checkpoint 5 of 9· Match them up

    Match each performance insight to the action Databricks recommends for it.

    Tap a term, then the definition that fits it.

    Checkpoint 6 of 9· Exam question

    A GROUP BY query aggregating billions of rows completes successfully but takes far longer than expected. In the query profile, the aggregation operator shows a large "bytes spilled to disk" value and a peak memory figure well above the warehouse's available memory. What does this indicate, and what should the analyst try first?

    Checkpoint 7 of 9· Exam question

    A join between a large fact table and a small dimension table finishes, but the query profile shows one task in the shuffle stage processing far more rows and taking dramatically longer than the other tasks in that same stage. What problem does this pattern point to, and what should the analyst investigate?

    Sources314

    4.Telling a slow query from a queued one

    A long wall-clock time doesn't always mean the SQL is slow. A query can spend most of its duration waiting for the warehouse before its first operator runs. The details panel breaks the duration into scheduling, optimization and file pruning, and execution. If scheduling dominates, the profile has little to tune. In system tables the split is explicit: waiting_at_capacity_duration_ms counts time spent queued for capacity, waiting_for_compute_duration_ms counts time waiting for compute to be provisioned, compilation_duration_ms covers metadata loading and optimization, and execution_duration_ms is the time actually spent running. How a warehouse admits, queues and scales queries is explained in Warehouse admission, queuing and scaling.

    Before you tune the SQL, check the warehouse load. On the warehouse's Monitoring tab, live statistics show the number of running queries, the number of queued queries and the current cluster count. You can hover over a duration in its query table to see it split into scheduling and running time. These views describe the warehouse as a whole, not the operators inside one query, so they tell you whether to look at capacity or at the query. To find queued queries across a week, query the system table directly:

    Queries that waited for warehouse capacity in the last 7 days, worst firstsql
    SELECT
      statement_id,
      executed_by,
      total_duration_ms,
      waiting_at_capacity_duration_ms,
      execution_duration_ms,
      start_time,
      statement_text
    FROM
      system.query.history
    WHERE
      compute.warehouse_id = '<warehouse-id>'
      AND start_time >= NOW() - INTERVAL 7 DAY
      AND waiting_at_capacity_duration_ms > 0
    ORDER BY
      waiting_at_capacity_duration_ms DESC
    LIMIT 50

    High queue time is a capacity problem, and the fix is to raise the warehouse's max_clusters so it can scale out. High execution time with little queueing points back to the profile and its insights. The same table also surfaces memory problems at scale: filter on spilled_local_bytes > 0 to list queries that spilled. Both cases are sizing signals, but for different resources. Queueing calls for more clusters, and spill calls for a larger cluster size.

    Aggregated task time (total_task_duration_ms in the system table) is the combined time across all cores of all nodes. Being larger than wall-clock time is normal and shows parallelism at work. Task time *shorter* than wall-clock time is the case to look at: it can mean tasks waited for available nodes.

    Checkpoint 8 of 9· Fill the gap

    An analyst suspects that a warehouse's slow dashboards were waiting for capacity, not running slow SQL. Which column completes the filter so that only queries that sat in the queue are listed?

    SELECT
      statement_id,
      executed_by,
      total_duration_ms,
      waiting_at_capacity_duration_ms,
      execution_duration_ms,
      start_time,
      statement_text
    FROM
      system.query.history
    WHERE
      compute.warehouse_id = '<warehouse-id>'
      AND start_time >= NOW() - INTERVAL 7 DAY
      AND  ?  > 0
    ORDER BY
      waiting_at_capacity_duration_ms DESC
    LIMIT 50

    Sources567

    5.Sharing a profile and reaching it from other tools

    Diagnosing a slow query often means showing it to someone else, and there are two ways to share a profile. If the colleague has CAN MANAGE on the query, open the query from Query History and click Share, which copies the profile URL to your clipboard. If they lack that permission or aren't in the workspace, click Download to save the profile as a JSON file. The recipient imports it from Query History's kebab menu with Import query profile (JSON). An imported profile loads into their browser session only and doesn't persist in the workspace, so they have to import it again each time they want to view it.

    Query History isn't the only way to open a profile. You can also reach one from:

    • The SQL editor, through the elapsed-time and row-count link below the results, which opens the query details panel
    • A notebook attached to a SQL warehouse or serverless compute, through See performance under the cell
    • The Query History tab of the Lakeflow pipelines UI, and the jobs UI for jobs run on SQL warehouses or serverless compute
    • A system.query.history record: copy its statement_id, make sure you are in the workspace named by workspace_id, paste the ID into the Statement ID filter in Query History, and click See query profile

    The last route turns a large-scale search, such as "every query that spilled this week", into an operator-level diagnosis of each one.

    Checkpoint 9 of 9· Put it in order

    A weekly query on system.query.history with spilled_local_bytes > 0 flags one statement as the worst spiller. To diagnose it operator by operator, arrange the steps that take you from that record to its query profile.

    1. 1.Copy the record's statement_id from the system table result
    2. 2.Check the record's workspace_id and make sure you are logged in to that workspace
    3. 3.Click the query's name, then click See query profile
    4. 4.Click Query History in the sidebar and paste the statement_id into the Statement ID filter

    Sources15

    Practise it for real

    Go from a warehouse-wide search for spilling queries to the operator-level diagnosis of one of them.

    1. 1.In the SQL editor, query system.query.history for the last 7 days with spilled_local_bytes > 0, ordered by spilled_local_bytes DESC, filtered to your warehouse's compute.warehouse_id.

      Why: The system table finds candidate queries at scale. By default only admins can read it, so ask an admin for access or a dynamic view if you need one.

      You should see: A list of statement_id values with spilled bytes, read bytes, duration and statement text.

    2. 2.Copy the statement_id of the worst offender, open Query History, and paste it into the Statement ID filter.

      Why: The statement_id identifies that exact execution in the Query History UI.

      You should see: One matching query run in the list.

    3. 3.Click the query, then See query profile, and open the Top operators tab.

      Why: Top operators ranks the most expensive steps, so you start at the costliest operator.

      You should see: An aggregation, join or sort near the top, with a high Memory peak.

    4. 4.Open the Performance insights tab.

      Why: The insight confirms the diagnosis and gives the recommended action.

      You should see: A spill insight recommending a larger warehouse or fewer rows, columns or large-column bytes.

    Stuck? Get a nudge

    If the profile shows as unavailable, the run you picked was served from cache. Choose a different statement_id where from_result_cache is false.

    Sources

    (7)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Click See query profile to open the detailed DAG.”
      ↩︎ Opening the profile of a past query run
      “you must have at least CAN MONITOR permission on the SQL warehouse that executed the query”
      ↩︎ Opening the profile of a past query run
      “A detailed breakdown of scheduling, query optimization and file pruning, and execution time appears below the summary.”
      ↩︎ Opening the profile of a past query run
      “A query profile is not available for queries that run from the query cache.”
      ↩︎ Opening the profile of a past query run
      “Top operators: Opens the Top operators panel which shows the most expensive operators used in your query.”
      ↩︎ Finding the expensive step: top operators, the DAG and verbose mode
      “The graph view shows metrics such as Time spent, Memory peak, and Rows.”
      ↩︎ Finding the expensive step: top operators, the DAG and verbose mode
      “These operations are unlikely to be the cause of performance bottlenecks.”
      ↩︎ Finding the expensive step: top operators, the DAG and verbose mode
      “Shuffle operations are expensive with regard to resources because they move data between executors on the cluster.”
      ↩︎ Finding the expensive step: top operators, the DAG and verbose mode
      “For Databricks SQL queries, you can also view the query profile in the Spark UI.”
      ↩︎ Finding the expensive step: top operators, the DAG and verbose mode
      “For an insight that requires a query change, Genie Code rewrites the query and presents the changes for your approval.”
      ↩︎ Performance insights: Databricks names the likely problem
      “If the other user has the CAN MANAGE permission on the query, you can share the URL for the query profile with them.”
      ↩︎ Sharing a profile and reaching it from other tools
      “When you import a query profile, it is dynamically loaded into your browser session and does not persist in your workspace.”
      ↩︎ Sharing a profile and reaching it from other tools
      “The query profile helps you troubleshoot performance bottlenecks during the query's execution.”
      ↩︎ Key concept
      “To circumvent the query cache, make a trivial change to the query, such as changing or removing the LIMIT.”
      ↩︎ Exam trap 1
      “If the other user has the CAN MANAGE permission on the query, you can share the URL for the query profile with them.”
      ↩︎ Exam trap 5
      “Click the name of a query. A query details panel appears on the right side of the screen.”
      ↩︎ Checkpoint
      “must either be the owner of the query or you must have at least CAN MONITOR permission on the SQL warehouse”
      ↩︎ Checkpoint
      “To see information for all operations, and to see additional metrics, click at the top of the page, then click Enable verbose mode.”
      ↩︎ Checkpoint
    2. 2.
      “filter the list by user, date range, compute, duration, query status, statement type, statement ID, and query tags”
      ↩︎ Opening the profile of a past query run
    3. 3.
      “The query details panel shows a summary of insights, ranked by their estimated effect on total task duration.”
      ↩︎ Performance insights: Databricks names the likely problem
      “Data spilled to disk during query execution because the data did not fit in memory.”
      ↩︎ Performance insights: Databricks names the likely problem
      “Increase the warehouse size to add memory.”
      ↩︎ Performance insights: Databricks names the likely problem
      “Review the data distribution, then use key salting or pre-aggregation to balance the workload.”
      ↩︎ Performance insights: Databricks names the likely problem
      “The join produces significantly more rows than it reads.”
      ↩︎ Performance insights: Databricks names the likely problem
      “Cost-based optimizer statistics are missing or incomplete, so the query plan uses standard heuristics.”
      ↩︎ Performance insights: Databricks names the likely problem
      “Photon can't accelerate this operation, so the query uses the standard runtime engine.”
      ↩︎ Performance insights: Databricks names the likely problem
      “A cloud storage request was throttled by the cloud provider.”
      ↩︎ Performance insights: Databricks names the likely problem
      “They appear in the Performance insights tab with an Accelerated label and do not require action.”
      ↩︎ Performance insights: Databricks names the likely problem
      “They appear in the Performance insights tab with an Accelerated label and do not require action.”
      ↩︎ Exam trap 2
      “Review the data distribution, then use key salting or pre-aggregation to balance the workload.”
      ↩︎ Exam trap 3
      “Recommendation: Review the data distribution, then use key salting or pre-aggregation to balance the workload.”
      ↩︎ Checkpoint
    4. 4.
      “Skew happens when one or a few tasks take much longer than the rest.”
      ↩︎ Performance insights: Databricks names the likely problem
      “If a few key values hold most of the data in a join or aggregation”
      ↩︎ Performance insights: Databricks names the likely problem
    5. 5.
      “Time spent waiting in queue for available compute capacity in milliseconds.”
      ↩︎ Telling a slow query from a queued one
      “It can be significantly longer than the wall-clock duration if multiple tasks are executed in parallel.”
      ↩︎ Telling a slow query from a queued one
      “In the Statement ID field, paste the statement_id on the record.”
      ↩︎ Sharing a profile and reaching it from other tools
      “Reference the record's workspace_id to ensure you are logged in to the same workspace as the record.”
      ↩︎ Checkpoint
    6. 6.
      “Queries with high waiting_at_capacity_duration_ms values are spending time queued instead of running.”
      ↩︎ Telling a slow query from a queued one
      “Queries with high waiting_at_capacity_duration_ms values are spending time queued instead of running.”
      ↩︎ Exam trap 4
    7. 7.
      “the number of running queries, the number of queued queries, and the warehouse's current cluster count”
      ↩︎ Telling a slow query from a queued one

    Spotted a mistake, or was something unclear? Tell us.