What you will be able to do
- Find, filter and copy any past query run from the Query History page, and know who is allowed to see it
- Use the query details panel to see where a slow run spent its time before you change anything
- Query system.query.history for account-wide history and spot result-cache hits in it
- Explain when the UI cache, local and remote result caches, disk cache and dashboard cache are used, and what invalidates each one
- Turn off result caching for a benchmark, and say why you should not leave it off
Key concept
Result reuse on unchanged tables — When the same statement runs again and none of the tables it reads have changed, Databricks SQL can return the result it already computed instead of executing the query again. Each cache layer is a variation on that rule: it differs in where the result or data is kept, how long it lasts, and what clears it.
1.Finding past runs on the Query History page
Every statement that runs on a SQL warehouse leaves a record on the Query History page, so you seldom need to retype SQL from memory. Click Query History in the sidebar to get a list of past runs. In a workspace enabled for serverless compute, the list also holds the SQL and Python queries that serverless notebooks and jobs ran. The page is useful for debugging, and it is just as useful for picking up work you or a colleague already did.
The filters at the top of the page turn a long list into a short one. You can filter by user, date range, compute, duration, query status, statement type, statement ID and query tags. Say a colleague ran a five-table join in the SQL editor sometime last week and never saved it. Filter by their user name and last week's dates, click the matching query text, and the details panel shows the complete statement. You can copy it from there. Re-running something similar won't bring the text back. Neither will turning on a cache or opening the profile of your own query. Only the history keeps the statement text.
Who can see a run depends on the warehouse, not on the query. You always see runs of queries you own. Other users see a run if they have at least CAN VIEW on the SQL warehouse that executed it. Shared queries have one more rule. If a user shares a Databricks SQL query with Run as Owner permissions, and another user with CAN RUN executes it, the run is recorded in the history of the user who executed it, not the user who shared it. So when you look for a teammate's run of a shared query, filter by the person who clicked Run.
Checkpoint 1 of 9· Check yourself
You shared a Databricks SQL query with Run as Owner permissions. A colleague with CAN RUN executed it yesterday, and you now want to see that run on the Query History page. What should you do?
When a query is shared with Run as Owner, each run goes into the query history of the user who executed it, not the user who shared it. So you filter by the person who clicked Run. Re-running the query does not bring back anyone else's run.
“appear in the query history of the user executing the query and not the user that shared the query”Source: docs.databricks.com
Checkpoint 2 of 9· Exam question
A data analyst wants to reuse a complex five-table join a colleague ran in the SQL editor sometime last week, but the analyst cannot find a saved copy and does not want to retype the join logic from memory. Which approach lets the analyst locate and copy the exact query text without rewriting it?
Correct answer: A — Open Query History in the SQL editor, filter the list by date range and by the colleague's user name, and open the matching entry to copy the full statement text.
- A. Query History records every executed statement with filters for user, date range, compute, and duration, so filtering by the colleague's name and last week's dates surfaces the run and its full statement text for copying.
- B. Query Profile visualizes the execution plan and timing of a specific completed query, but it does not search across other users' run history or recover a colleague's query text.
- C. The disk cache stores previously read data files on local SSD to speed up scans of the same underlying data; it does not index or expose the SQL text of past queries.
- D. Disabling result-cache reuse forces every query to recompute from the underlying tables and has no effect on finding or retrieving a previously run query's statement text.
Sources1
2.Reading a run's details before you change anything
Click a query's text in the history and a summary panel opens on the right. It shows status (Queued, Running, Finished, Failed or Cancelled), the user and compute, the run's UUID, the full statement (click ... more lines for long text), headline metrics, the query source, and I/O details about the data read and written. When a statement is still running, a Cancel button appears next to Status. You can use it to stop a long-running query started by you or another user. Statements on Lakeflow pipelines compute can be cancelled only from the Pipelines UI.
Two duration figures answer different questions. Wall-clock duration is the elapsed time from the start of scheduling to the end of execution, split into scheduling, query optimisation and file pruning, and execution. Aggregated task time adds up the work across all cores of all nodes. It is much larger than wall-clock when many tasks run in parallel. It can be smaller than wall-clock when tasks were waiting for available nodes. A run whose wall-clock time is mostly scheduling needs compute. A run whose execution time grows each week needs a closer look at the query and its data.
That closer look is the query profile. Click See query profile in the panel to open the full execution graph. There you can find the slowest part of the run at a glance and check whether a change to the query helped. Take a scheduled dashboard query that used to finish in seconds and now takes minutes after a month of table growth. The first step is to open that slow run from the history and read its profile, which shows whether scanning, shuffling or something else is taking the time. Adding a LIMIT measures a different, smaller query and tells you nothing about the original. A warehouse restart only empties its caches. Reading individual operators and performance insights is covered under identifying poorly performing queries.
Sometimes the profile shows Query profile is not available. Runs answered from the query cache have no profile, because nothing executed. To get one, make a trivial change to the statement, such as changing or removing the LIMIT, so it misses the cache and actually runs.
Checkpoint 3 of 9· Check yourself
An analyst with CAN VIEW on a SQL warehouse finds a colleague's slow run in Query History, but permissions stop them from opening that run's query profile. What lets them open the profile of that exact run?
CAN VIEW on the warehouse is enough to see the run in the history, but the profile needs ownership of the query or at least CAN MONITOR on the warehouse. Re-running the statement creates a new run of the analyst's own. It does not open the colleague's original run.
“you must either be the owner of the query or you must have at least CAN MONITOR permission on the SQL warehouse”Source: docs.databricks.com
Checkpoint 4 of 9· Exam question
An analyst notices a scheduled dashboard query that used to finish in a few seconds now regularly takes several minutes, and the underlying table has grown substantially over the past month. Before changing anything, the analyst wants to confirm where the extra time is actually being spent. What should the analyst do first?
Correct answer: A — Open the slow run in Query History and inspect its Query Profile to see the time breakdown across stages, such as scanning, shuffling, or spilling to disk.
- A. Query Profile, reached from the query's entry in Query History, breaks execution down into stages like scan, shuffle, and spill so the analyst can see exactly where time is going before making any change.
- B. Adding a
LIMITchanges what the query computes and returns, so its runtime is not representative of the original query's bottleneck and does not diagnose anything. - C. Restarting the warehouse clears in-memory state but is not a diagnostic step, and a cold cluster is only one of many possible causes of slower execution over time.
- D. Re-typing identical SQL in a new tab executes the same logical query against the same growing table and provides no additional insight into where time is spent.
3.Querying history across the account with system.query.history
The UI shows one workspace at a time. The system table system.query.history holds tabular history records for the whole account. It covers queries run on SQL warehouses, on serverless compute for notebooks and jobs, and in Lakeflow pipelines on serverless or classic compute. It includes every workspace in your account that is in the same region as the workspace you query it from. Records usually arrive within an hour, so this table is the wrong place to look for a query you ran a minute ago.
Access is restricted by default. Only admins can read system tables. To give a user or group access, Databricks recommends a dynamic view for each user or group rather than a direct grant. Even with access, the statement_text column shows <REDACTED> unless you are an account admin or a member of the databricks_pii_access account-level group.
| Column | What it tells you |
|---|---|
| statement_id | Unique ID of the execution; paste it into the Query History UI to find the run |
| executed_by | Email address or username of the user who ran the statement |
| execution_status | FINISHED, FAILED or CANCELED |
| total_duration_ms | Total execution time, excluding result fetch time |
| total_task_duration_ms | Sum of all task durations across all cores of all nodes |
| from_result_cache | TRUE when the result was fetched from the cache |
| cache_origin_statement_id | For a cached result, the statement that originally put it in the cache; otherwise the query's own ID |
| read_io_cache_percent | Percentage of bytes of persistent data read from the IO cache |
| query_source | Databricks entities involved, such as a dashboard_id, job_info, alert_id or genie_space_id |
To get from a row in the table to that run's query profile:
- Copy the record's
statement_id. - Check its
workspace_idand log in to that workspace. - Click Query History in the sidebar and paste the ID into the Statement ID filter.
- Click the query's name, then click See query profile.
Checkpoint 5 of 9· Put it in order
A row in system.query.history shows a slow run that happened in another workspace in your account. Put the steps for opening that run's query profile in order.
- 1.Check the record's workspace_id and log in to that workspace.
- 2.Click Query History in the sidebar and paste the ID into the Statement ID filter.
- 3.Copy the record's statement_id from system.query.history.
- 4.Click the query's name, then click See query profile.
The system table covers every workspace in the region, but the Query History UI shows only one workspace at a time. So you take the statement_id, log in to the workspace that ran it, and filter the history by that ID before you open the profile.
“Reference the record's workspace_id to ensure you are logged in to the same workspace as the record.”Source: docs.databricks.com
4.Local and remote result caches
The result cache stores finished query results, and it applies to every query sent through a SQL warehouse. It has two tiers. The local cache is held in memory on the cluster. It lasts for the cluster's lifetime or until it fills up, whichever comes first, and stopping or restarting the cluster wipes it. The remote result cache is serverless-only and stores results as workspace system data. It is shared across all warehouses in the workspace and is available to ODBC/JDBC clients and the SQL Statement API.
Lookups go in a fixed order. A warehouse checks its local cache first, then the remote result cache, and executes the query only if neither has the result. Entries in both tiers last 24 hours from when they were written, and both are invalidated once the underlying tables are updated. The remote tier gets past the in-memory limit that results disappear when compute stops, but it still needs a running warehouse to read from. Restarting a warehouse is not a fix for slowness: it throws away the local cache, so the next queries have less to reuse, not more.
Result caching is on by default: use_cached_result defaults to TRUE for each session. To time a query fairly while you tune it, you need every run to execute for real, so turn caching off for the session with SET use_cached_result = false. Use this only for testing or benchmarking. Leaving it off makes every repeated query recompute and uses more warehouse time.
> SET use_cached_result = true;
> SELECT count(1) FROM T;
-- Re-use the result from the previous query
> SELECT count(1) FROM T;Checkpoint 6 of 9· Fill the gap
Which value makes the second identical SELECT return the first query's result instead of executing again?
> SET use_cached_result = ? ;
> SELECT count(1) FROM T;
-- Re-use the result from the previous query
> SELECT count(1) FROM T;use_cached_result = true lets the session reuse a cached result when the same query runs again on unchanged tables, and TRUE is also the system default. Setting it to false makes every run execute for real, which is meant only for testing or benchmarking. The parameter does not choose between the local and remote tiers.
Source: docs.databricks.comCheckpoint 7 of 9· Exam question
A team runs the same reporting query each morning against a serverless SQL warehouse that Databricks automatically stops overnight due to inactivity. The underlying table has not changed since the previous run. When the team runs the identical query again after the warehouse restarts, the result appears almost instantly with no new compute activity. What explains this behavior?
Correct answer: A — The remote result cache is stored outside the cluster and persists across a warehouse restart, so the identical query reuses the earlier computed result.
- A. The remote result cache is a workspace-level store separate from any single cluster, has a lifecycle of up to 24 hours, and survives a warehouse being stopped and restarted, so an unchanged identical query returns the cached result immediately.
- B. The disk cache lives on local SSD attached to compute nodes and is cleared when a cluster or warehouse restarts, so it could not have survived the overnight stop to serve this result.
- C. Running a query in the SQL editor does not create a materialized view of the result; no persistent view object is created just by executing a SELECT statement.
- D. A stopped serverless warehouse is not still running underneath the billing layer; the near-instant response comes from the persistent remote result cache, not from hidden active compute.
5.The disk cache stores data files, not results
The disk cache works one level lower than the result cache. It keeps copies of the data files a query reads. When a node fetches a Parquet file from cloud storage, including a Delta Lake table's files, it saves a copy on its local SSD in a fast intermediate format. Later reads of the same files are served locally. A different query that scans the same table still benefits from those copies. The result cache only helps when the same statement runs again.
Neither caching nor invalidation needs anything from you. Files go into the cache the first time they are read. The cache notices when data files are created, deleted, modified or overwritten and evicts the stale copies, and it removes old entries in least-recently-used order. On SQL warehouses, and on Databricks Runtime 14.2 and above, the CACHE SELECT command is ignored and an improved caching algorithm is used instead. Older material may call this the Delta cache or the DBIO cache. Both are former names for the same proprietary Databricks feature, which is not part of the Delta Lake protocol.
The disk cache has the same lifecycle as the local result cache: stopping or restarting the cluster clears it, and it has to fill up again. So after an overnight stop, a fast first query can't be the disk cache's doing. The read_io_cache_percent column in the system table shows how much of a query's persistent data was read from this cache.
| Cache | Holds | Lifetime | Cleared by |
|---|---|---|---|
| Databricks SQL UI cache | Per-user query results and SQL editor visualizations | At most 7 days | Re-running the query, or an update to the underlying tables |
| Local result cache | Query results in cluster memory | Cluster lifetime or until full; entries 24 hours | Warehouse stop or restart; underlying table update |
| Remote result cache | Query results as workspace system data (serverless only) | 24 hours from cache entry | Underlying table update (survives warehouse restart) |
| Disk cache | Copies of data files on local SSD | Same as the local result cache | Cluster stop or restart; detected file changes |
Checkpoint 8 of 9· Match them up
Match each Databricks SQL cache to what it keeps and how it behaves.
Tap a term, then the definition that fits it.
The disk cache works below the result caches: it stores data files rather than results, so any query that reads those files benefits, not only a repeat of the same statement. Of the caches that live on the warehouse, it and the local result cache are both cleared by a restart. Only the serverless remote result cache keeps results through a restart.
“Disk cache: Local SSD caching for data read from data storage for queries through SQL warehouses.”Source: docs.databricks.com
6.The SQL UI cache and the AI/BI dashboard cache
The Databricks SQL UI cache is why a saved query or a legacy SQL dashboard shows a result the moment you open it. The result shown is the most recent one, including results from scheduled runs. This cache is per user, lives in the Databricks filesystem in your account, and lasts at most 7 days. To remove a stored result, re-run the query, which replaces the old result. An update to the underlying tables also invalidates it. It does not apply to AI/BI dashboards, which have their own cache.
The AI/BI dashboard cache keeps results for 24 hours on a best-effort basis, and it is checked before the general query result cache. The two invalidate differently. The query result cache never returns stale data, because any change to the underlying data invalidates its entries. The dashboard cache can serve results up to 24 hours old after the data has changed. A data change does not refresh it, and neither does a pipeline step that reloads the table. A dashboard schedule refreshes it reliably. Otherwise it updates only when the dashboard runs a query the cache cannot serve. How to set the schedule is covered under scheduling dashboard refreshes.
Three more behaviours matter in practice. Serving from the dashboard cache does not start the SQL warehouse, because no query runs. A function such as current_timestamp() in the SQL invalidates the query result cache, which inspects the SQL text, but not the dashboard cache. Who shares a cached result depends on how the dashboard was published: with shared data permissions, all viewers share one cache and see the same results. Draft dashboards, and dashboards published with individual data permissions, cache per user, so each viewer sees results based on their own data permissions.
Dashboards also explain some gaps in the query history. For a small dataset (100K rows or fewer and 100MB or less), filtering and aggregation run in the browser after the first load, so those interactions never reach the warehouse or the history. Larger datasets push filters to the backend, where the dataset query is wrapped in a WITH clause. Several visualisations can then appear as one combined query. A missing history entry for a filter click does not mean the dashboard is broken.
Checkpoint 9 of 9· Check yourself
A nightly pipeline reloads the sales table at 02:00. At 08:00, viewers of a published AI/BI dashboard still see yesterday's figures. What reliably makes the dashboard show the reloaded data?
The dashboard cache can serve results up to 24 hours old after the data changes, and neither the data change nor the pipeline reload refreshes it. A dashboard schedule refreshes it reliably. current_timestamp() and use_cached_result only affect the query result cache, and the dashboard serves cached results without running the warehouse, so restarting the warehouse doesn't clear the dashboard cache.
“To reliably refresh the dashboard cache, configure a dashboard schedule.”Source: docs.databricks.com
Practise it for real
Produce a result-cache hit, recognise it in the history, then force the query to execute again
1.In the SQL editor on a SQL warehouse, run a simple aggregate such as SELECT count(1) on a table you can read, then run the identical statement a second time.
Why: An identical statement over unchanged tables can be answered from the result cache.
You should see: The second run returns almost immediately.
2.Open Query History, click the second run, and click See query profile.
Why: Cache hits do not execute, so they have no profile.
You should see: The panel reports that a query profile is not available for this run.
3.If you are an admin, query system.query.history for both statement IDs and compare from_result_cache and cache_origin_statement_id.
Why: These columns record whether a result came from the cache and which run first put it there.
You should see: Records can take up to about an hour to appear. The second run shows from_result_cache = TRUE, and its cache_origin_statement_id matches the first run's statement_id.
4.Run SET use_cached_result = false, run the same statement again, and then open its profile.
Why: Turning off result reuse for the session makes the query execute, which you need when benchmarking.
You should see: The run takes its normal execution time and has a query profile.
Stuck? Get a nudge
If the second run was not a cache hit, check whether the table was written between the two runs: any update to it invalidates the cached result.
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“filter the list by user, date range, compute, duration, query status, statement type, statement ID, and query tags”
↩︎ Finding past runs on the Query History page“Other users can view query runs if they have at least CAN VIEW access to the SQL warehouse that executed the query.”
↩︎ Finding past runs on the Query History page“appear in the query history of the user executing the query and not the user that shared the query”
↩︎ Finding past runs on the Query History page“Query statement: This section includes the complete query statement.”
↩︎ Finding past runs on the Query History page“It can be significantly longer than the wall-clock duration if multiple tasks are excuted in parallel.”
↩︎ Reading a run's details before you change anything“Next to Status, click Cancel.”
↩︎ Reading a run's details before you change anything“By default, only admins have access to your account's system tables.”
↩︎ Querying history across the account with system.query.history - 2.
“You can identify the slowest part of a query execution at a glance and assess the impacts of modifications to the query.”
↩︎ Reading a run's details before you change anything“A query profile is not available for queries that run from the query cache.”
↩︎ Reading a run's details before you change anything“To circumvent the query cache, make a trivial change to the query, such as changing or removing the LIMIT.”
↩︎ Reading a run's details before you change anything“you must have at least CAN MONITOR permission on the SQL warehouse that executed the query”
↩︎ Exam trap 3“you must either be the owner of the query or you must have at least CAN MONITOR permission on the SQL warehouse”
↩︎ Checkpoint - 3.
“Records are typically available within one hour.”
↩︎ Querying history across the account with system.query.history“records from all workspaces in your account that are in the same region”
↩︎ Querying history across the account with system.query.history“Databricks recommends creating a dynamic view for each user or group.”
↩︎ Querying history across the account with system.query.history“By default, this field returns <REDACTED> unless you are an account admin or a member of the databricks_pii_access account-level group.”
↩︎ Querying history across the account with system.query.history“In the Statement ID field, paste the statement_id on the record.”
↩︎ Querying history across the account with system.query.history“The percentage of bytes of persistent data read from the IO cache.”
↩︎ The disk cache stores data files, not results“Reference the record's workspace_id to ensure you are logged in to the same workspace as the record.”
↩︎ Checkpoint - 4.
“When processing a query, a cluster first looks in its local cache and then looks in the remote result cache if necessary.”
↩︎ Local and remote result caches“Both the local and the remote caches have a life cycle of 24 hours, which starts at cache entry.”
↩︎ Local and remote result caches“The remote cache is a persistent shared cache across all warehouses in a Databricks workspace.”
↩︎ Local and remote result caches“Accessing the remote result cache requires a running warehouse.”
↩︎ Local and remote result caches“once the cluster is stopped or restarted, the cache is cleaned and all query results are removed.”
↩︎ Local and remote result caches“Local SSD caching for data read from data storage for queries through SQL warehouses.”
↩︎ The disk cache stores data files, not results“The Databricks SQL UI cache has at most a 7-day life cycle.”
↩︎ The SQL UI cache and the AI/BI dashboard cache“The Databricks SQL UI cache does not apply to AI/BI dashboards (formerly Lakeview dashboards).”
↩︎ The SQL UI cache and the AI/BI dashboard cache“The disk cache shares the same lifecycle characteristics as the local result cache.”
↩︎ Exam trap 1“You should use this option only in testing or benchmarking.”
↩︎ Exam trap 4“The remote result cache persists through the stopping or restarting of a SQL warehouse.”
↩︎ Prediction“Disk cache: Local SSD caching for data read from data storage for queries through SQL warehouses.”
↩︎ Checkpoint - 5.
“The system default for this setting is TRUE.”
↩︎ Local and remote result caches“If a query is re-submitted and the underlying tables have not changed, Databricks SQL can re-use the result set, reducing query execution cost.”
↩︎ Key concept - 6.
“In SQL warehouses and Databricks Runtime 14.2 and above, the CACHE SELECT command is ignored.”
↩︎ The disk cache stores data files, not results“Disk caching on Databricks was formerly referred to as the Delta cache and the DBIO cache.”
↩︎ The disk cache stores data files, not results“The disk cache automatically detects when data files are created, deleted, modified, or overwritten and updates its content accordingly.”
↩︎ The disk cache stores data files, not results - 7.
“To improve loading times, dashboards first check the dashboard cache.”
↩︎ The SQL UI cache and the AI/BI dashboard cache“To reliably refresh the dashboard cache, configure a dashboard schedule.”
↩︎ The SQL UI cache and the AI/BI dashboard cache“Serving results from the dashboard cache does not start the SQL warehouse.”
↩︎ The SQL UI cache and the AI/BI dashboard cache“Using current_timestamp() or similar functions in your SQL query does not invalidate the dashboard-level cache.”
↩︎ The SQL UI cache and the AI/BI dashboard cache“Because these operations are processed locally, they avoid further interaction with the data warehouse and don't appear in the query history.”
↩︎ The SQL UI cache and the AI/BI dashboard cache“The dashboard cache can return results that are up to 24 hours old even when the underlying data has changed”
↩︎ Exam trap 2