What you will be able to do
- Use the Query History page and its filters to find slow, failed or queued queries
- Read the query details panel: wall-clock duration, aggregated task time, pruning and I/O
- Query system.query.history to rank queries by queue time or disk spill, and go from a record to its query profile
- Use the SQL warehouse Monitoring tab to tell whether queries are waiting for capacity
Key concept
Query history → query profile drill-down — You find poorly performing queries in two steps. Query history (the UI page or the system table) tells you which runs were slow, failed or queued. The query profile for one of those runs then shows where its time went.
1.Start with the Query History page
Before you can fix a slow query, you have to find it. In Databricks the usual starting point is Query History in the workspace sidebar. The documentation calls it a debugging tool: it lists previous query runs, and you can click any of them to see what happened. On a workspace enabled for serverless compute, the list covers more than SQL warehouses. It also includes SQL and Python queries run on serverless compute for notebooks and jobs.
Use the filters at the top of the page to narrow the list. You can filter by user, date range, compute, duration, query status, statement type, statement ID and query tags. For performance work, the duration filter is the useful one: sort or filter for the long runs on a given warehouse and you have your candidate list. The status filter finds queries that are Failed, Cancelled or still Queued.
Who can see what depends on permissions. You can always see your own query runs. To see other people's runs, you need at least CAN VIEW on the SQL warehouse that executed them. Queries shared with Run as Owner permissions appear in the history of the person who ran them, not the person who shared them. If a long-running query is holding up the warehouse right now, open it and click Cancel next to Status. That button only shows up while the query is running. Statements that use Lakeflow pipelines compute can only be canceled from the Pipelines UI.
Checkpoint 1 of 5· Check yourself
An analyst wants to look at a colleague's slow query runs in Query History. What is the minimum access the analyst needs?
Owners always see their own runs. Anyone else needs at least CAN VIEW on the warehouse that ran the query.
“Other users can view query runs if they have at least CAN VIEW access to the SQL warehouse that executed the query.”Source: docs.databricks.com
Sources1
2.Reading the query details panel
Click a query's text and a summary panel opens on the right. It shows the status (Queued, Running, Finished, Failed or Cancelled), the user and compute details, the statement's UUID and the full statement text. Below the text are the metrics that tell you whether the run performed poorly.
Query metrics are the common analysis numbers. Some of them have a filter icon, which shows the percent of data pruned during scanning. Little pruning on a big table is an early sign of a full scan. Input/Output (IO) shows the data read and written. See longest operators for this query opens the Top operators panel, which lists the operators that ran longest. A small preview of the query profile DAG gives you a rough idea of how complex the query is.
The panel reports two different times, and they measure different things. Query wall-clock duration is the elapsed time from the start of scheduling to the end of execution. It is broken down into scheduling, query optimization and file pruning, and execution, so you can tell a query that waited from one that ran slowly. Aggregated task time is the total time across all cores of all nodes. It can be much longer than wall-clock time when tasks run in parallel, and shorter when tasks had to wait for available nodes.
| Metric | What it measures | How to read it |
|---|---|---|
| Query wall-clock duration | Elapsed time from the start of scheduling to the end of execution | Look at the scheduling / optimization and file pruning / execution breakdown to see where the time went |
| Aggregated task time | Combined execution time across all cores of all nodes | Longer than wall-clock when tasks run in parallel; shorter when tasks waited for available nodes |
Checkpoint 2 of 5· 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?
Correct answer: A — Open Query History, select the query by name or timestamp, then choose "See query profile" to view its execution DAG and metrics.
- A. Query History lists every executed query, and selecting a query and opening its query profile is the documented path to the per-operator execution DAG, timing, and I/O metrics used to diagnose poor performance. This is the correct starting point for investigating a specific past query.
- B. Query lineage in Catalog Explorer shows which queries and jobs read or wrote a table, not the execution timing or resource usage of a single run. It does not surface the DAG or task-level metrics needed to diagnose slowness.
- C. The warehouse monitoring page shows aggregate cluster utilization and concurrency across all queries on that warehouse, not the execution breakdown of one specific query. It cannot pinpoint which operator inside a single query caused the slowdown.
- D. Running `EXPLAIN` returns the planned logical and physical execution steps before the query runs, not the actual runtime metrics, row counts, or spill/skew data from the completed execution. It is useful for plan inspection but not for profiling a query that already ran.
Sources1
3.Finding slow queries at scale with system.query.history
The UI is fine for checking one warehouse by eye. To rank queries across the account, use the system table system.query.history. It holds records for SQL warehouses, serverless compute for notebooks and jobs, and Lakeflow pipelines, from every workspace in the account that is in the same region. Two limits apply. Only admins can read it by default; to give other users or groups access, Databricks recommends creating a dynamic view for each. Records also usually take up to an hour to appear, so it is not a live view.
Databricks provides example queries that point at the two most common warehouse-level problems. Queries with a high waiting_at_capacity_duration_ms were queued instead of running; the fix is to raise the warehouse's max_clusters so it can scale out. Queries with spilled_local_bytes > 0 needed more memory than was available; the fix is a larger warehouse size, or a query that does less work.
SELECT
statement_id,
executed_by,
spilled_local_bytes / (1024 * 1024) AS spilled_mb,
read_bytes / (1024 * 1024) AS read_mb,
total_duration_ms,
start_time,
statement_text
FROM
system.query.history
WHERE
compute.warehouse_id = '<warehouse-id>'
AND start_time >= NOW() - INTERVAL 7 DAY
AND spilled_local_bytes > 0
ORDER BY
spilled_local_bytes DESC
LIMIT 50Checkpoint 3 of 5· Fill the gap
This query lists the queries that spent time queued because the warehouse was at capacity. Which column completes the filter?
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 50waiting_at_capacity_duration_ms is the time a query spent queued instead of running. That makes it the column to filter on when you are looking for capacity problems.
Source: docs.databricks.comWhen comparing scan columns, keep in mind that read_bytes is not on the same scale as table_bytes (pruned_files_bytes + read_files_bytes). The file-size columns are compressed on-disk sizes. read_bytes counts the data actually read, including uncompressed data from the disk cache and any retried reads, so it can be larger than table_bytes. Once a record stands out, open its full profile in the UI:
Checkpoint 4 of 5· Put it in order
Put these steps in order to open the query profile for a record you found in system.query.history.
- 1.Check the record's workspace_id and make sure you are logged in to that workspace
- 2.Click Query History in the workspace sidebar
- 3.Paste the statement_id into the Statement ID field
- 4.Click the name of the query, then click See query profile
- 5.Copy the record's statement_id
The system table covers every workspace in the region, so you first make sure you are in the right workspace. Then you filter Query History by statement ID and open the profile.
“In the Statement ID field, paste the statement_id on the record.”Source: docs.databricks.com
4.Checking the warehouse: is the query slow or just waiting?
Sometimes a query looks slow but its plan is fine; it simply sat in the queue. To check, click the SQL warehouse and open its Monitoring tab. The live statistics at the top show the warehouse status, running queries, queued queries and current cluster count. The Peak query count chart shows the highest number of running plus queued queries in each 5-minute window. The tab also has its own query history table. Hover over a duration there to see how much of it was scheduling and how much was running.
The sizing guidance gives you three signals. On the Monitoring page, Peak Queued Queries that stays above 0 means you may need a larger cluster size or more clusters. Query history shows which queries are the bottlenecks. In the query profile, Bytes spilled to disk means the warehouse may be too small. Every queue holds at most 1,000 queries, whatever the warehouse type.
Checkpoint 5 of 5· Check yourself
On a warehouse's Monitoring tab, Peak Queued Queries stays above 0 all afternoon. What does the documentation suggest?
Queries that keep queueing point to a capacity problem, not a problem with the SQL itself.
“A consistent value above 0 indicates that you may need a larger cluster size or more clusters.”Source: docs.databricks.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.An aggregated task time far above the wall-clock duration means the query is inefficient or double-counting.Why is that wrong?
Aggregated task time adds up the time across all cores of all nodes, so parallel execution makes it larger than wall-clock time as a matter of course.
Covered in Reading the query details panel
2.Queue time and disk spill have the same fix: a bigger warehouse.Why is that wrong?
They have different fixes. Queue time (waiting_at_capacity_duration_ms) calls for a higher max_clusters so the warehouse can scale out. Disk spill calls for a larger warehouse size so queries get more memory.
Covered in Finding slow queries at scale with system.query.history
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“You can use the information available through this screen to help you debug issues with queries.”
↩︎ Start with the Query History page“filter the list by user, date range, compute, duration, query status, statement type, statement ID, and query tags”
↩︎ Start with the Query History page“Cancel only appears when a query is running.”
↩︎ Start with the Query History page“The filter icons that appear with some metrics indicate the percent of data pruned during scanning.”
↩︎ Reading the query details panel“It can be shorter than the wall-clock duration if tasks waited for available nodes.”
↩︎ Reading the query details panel“For more detailed information about the query's performance, including its execution plan, click View Query Profile near the bottom of the page.”
↩︎ Key concept“View the combined time it took to execute the query across all cores of all nodes.”
↩︎ Exam trap 1“Other users can view query runs if they have at least CAN VIEW access to the SQL warehouse that executed the query.”
↩︎ Checkpoint“It can be significantly longer than the wall-clock duration if multiple tasks are excuted in parallel.”
↩︎ Prediction - 2.
“By default, only admins have access to the system table.”
↩︎ Finding slow queries at scale with system.query.history“Records are typically available within one hour.”
↩︎ Finding slow queries at scale with system.query.history“As a result, read_bytes can exceed table_bytes.”
↩︎ Finding slow queries at scale with system.query.history“In the Statement ID field, paste the statement_id on the record.”
↩︎ Checkpoint - 3.
“Disk spill occurs when a query requires more memory than is available.”
↩︎ Finding slow queries at scale with system.query.history“Consider increasing the warehouse max_clusters setting to allow the warehouse to scale.”
↩︎ Exam trap 2 - 4.
“they indicate the warehouse status, the number of running queries, the number of queued queries, and the warehouse's current cluster count.”
↩︎ Checking the warehouse: is the query slow or just waiting? - 5.
“Inspect execution plans for metrics such as Bytes spilled to disk, which indicates that the warehouse size may be too small.”
↩︎ Checking the warehouse: is the query slow or just waiting?“A consistent value above 0 indicates that you may need a larger cluster size or more clusters.”
↩︎ Checkpoint