Reusing Persisted Query Results¶
When a query is executed, the result is persisted for a period of time (currently 24 hours). At the end of the time period, the result is purged from the system.
A persisted result is available for reuse by another query, as long as the user executing the query has the necessary access privileges for the table(s) used in the query, and the following conditions have been met:
- The new query syntactically matches the previously-executed query.
- The table data contributing to the query result has not changed.
- The persisted result for the previous query is still available.
- Any configuration options that affect how the result was produced have not changed.
- The query does not include functions that must be evaluated at execution, e.g. CURRENT_TIMESTAMP.
Result reuse can substantially reduce query time because Snowflake bypasses query execution and, instead, retrieves the result directly from the cache.
Result reuse is controlled by the session parameter USE_CACHED_RESULT. By default, the parameter is enabled, but can be overridden at the account, user, and session level if desired.
Each time the persisted result for a query is reused, Snowflake resets the 24-hour retention period for the result, up to a maximum of 31 days from the date and time that the query was first executed. After 31 days, the result is purged and the next time the query is submitted, a new result is returned and persisted.