CertSafari
    Databricks Certified Data Analyst Associate· Lessons

    Domain 5 · Lesson 21/39

    Query history and caching in Databricks SQL

    Utilize query history and caching to reduce development time and query latency.

    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

    • 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?

    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?

    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?

    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?

    Sources12

    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.

    system.query.history columns that matter for finding runs and spotting cache use
    ColumnWhat it tells you
    statement_idUnique ID of the execution; paste it into the Query History UI to find the run
    executed_byEmail address or username of the user who ran the statement
    execution_statusFINISHED, FAILED or CANCELED
    total_duration_msTotal execution time, excluding result fetch time
    total_task_duration_msSum of all task durations across all cores of all nodes
    from_result_cacheTRUE when the result was fetched from the cache
    cache_origin_statement_idFor a cached result, the statement that originally put it in the cache; otherwise the query's own ID
    read_io_cache_percentPercentage of bytes of persistent data read from the IO cache
    query_sourceDatabricks 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:

    1. Copy the record's statement_id.
    2. Check its workspace_id and log in to that workspace.
    3. Click Query History in the sidebar and paste the ID into the Statement ID filter.
    4. 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. 1.Check the record's workspace_id and log in to that workspace.
    2. 2.Click Query History in the sidebar and paste the ID into the Statement ID filter.
    3. 3.Copy the record's statement_id from system.query.history.
    4. 4.Click the query's name, then click See query profile.

    Sources31

    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.

    With use_cached_result on, the second identical query reuses the first one's resultsql
    > 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;

    Checkpoint 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?

    Sources45

    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.

    Databricks SQL caches compared: what each holds, how long it lasts and what clears it
    CacheHoldsLifetimeCleared by
    Databricks SQL UI cachePer-user query results and SQL editor visualizationsAt most 7 daysRe-running the query, or an update to the underlying tables
    Local result cacheQuery results in cluster memoryCluster lifetime or until full; entries 24 hoursWarehouse stop or restart; underlying table update
    Remote result cacheQuery results as workspace system data (serverless only)24 hours from cache entryUnderlying table update (survives warehouse restart)
    Disk cacheCopies of data files on local SSDSame as the local result cacheCluster 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.

    Sources463

    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?

    Sources47

    Practise it for real

    Produce a result-cache hit, recognise it in the history, then force the query to execute again

    1. 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. 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. 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. 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. 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
      “By default, only admins have access to your account's system tables.”
      ↩︎ Querying history across the account with system.query.history
    2. 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. 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. 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. 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. 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. 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

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