liveBook · Manning

Persisted query result

As explained in Snowflake Data Engineering

A persisted query result is a previously computed Snowflake query result retained for reuse when a matching query is executed again.

A persisted query result is a previously computed Snowflake query result retained for reuse. Snowflake usually keeps results for about 24 hours, allowing repeated reports or transformations to return results without re-executing the query. section 9.2.1

Snowflake reuses a persisted result only when the reuse conditions hold:

  • The query must be exactly identical, including uppercase and lowercase differences. section 9.2.1
  • The underlying table data must not have changed. section 9.2.1
  • The session parameter USE_CACHED_RESULT must remain TRUE, its default setting. section 9.2.2

When reuse occurs, the query profile shows a single step indicating that results were reused. Retrieval avoids query execution, an active virtual warehouse, and credit consumption, which can improve performance and control costs. section 9.2.1

Benchmarking without result reuse

To compare execution statistics across warehouse sizes, run ALTER SESSION SET USE_CACHED_RESULT = FALSE;. Snowflake then executes the query each time, enabling comparisons of execution time, spilling, and credits consumed. Restore TRUE afterward for normal performance. section 9.2.2

Figure 9.5 Query profile after executing the query from listing 9.1 a second time, indicating that the query results were reused
figure

Inspect the query profile to verify that a repeated query used the persisted result rather than executing again. section 9.2.1

How Snowflake Data Engineering covers it

How deep it goes
Explains retention, exact-query and unchanged-data requirements, session control, and query-profile verification, but not internal cache mechanics.
Examples
Uses repeated bakery retail-data queries, a reused-result query profile, and warehouse-size comparisons with cached results disabled.
What it assumes
Assumes familiarity with Snowflake queries and virtual warehouses while demonstrating session parameters and query-profile inspection.
What you can do after
Operate/configure Snowflake query reuse and diagnose it through query profiles and the USE_CACHED_RESULT session parameter.
How it connects
Connects persisted results with query performance, virtual warehouses, query profiles, spilling, and credit consumption.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Snowflake Data Engineering. The section links point to the parts of the book it draws on.