Understanding dynamic table target lag¶
Dynamic table refresh is triggered by the data’s target lag, which determines how outdated it can be. You can set a fixed target lag or set the dynamic table to DOWNSTREAM, making its refresh timing depend on other dynamic tables that depend on it.
The target lag for a dynamic table is measured relative to the dynamic tables at the root of the graph, not the dynamic tables directly upstream. To see the graph of tables connected to your dynamic table, see View the graph of tables connected to your dynamic tables.
Snowflake schedules refreshes to keep the actual lag of your dynamic tables below their target lag. The duration of each refresh depends on the query, data pattern, and warehouse size. When choosing a target lag, consider the time needed to refresh each dynamic table in a chain to the root. If you don’t, some refreshes might be skipped, leading to a higher actual lag.
Types of target lag¶
You specify target lag in one of the following ways. Target lag is inversely proportional to the dynamic table’s refresh frequency: frequent refreshes imply a lower lag.
Measure of freshness: Defines the maximum amount of time that the dynamic table’s content should lag behind updates to the base tables.
The following example sets
my_dynamic_tableto refresh and maintain freshness within every hour:ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = '1 hour';
Downstream: Specifies that the dynamic table should refresh on demand when other dependent dynamic tables refresh. This refresh can be triggered by initialization at creation, manual refresh, or scheduled refresh of a downstream dynamic table.
In the following example,
my_dynamic_tableis set to refresh based on the target lag of its downstream dynamic tables. Ifmy_dynamic_tabledoesn’t have any dynamic tables that depend on it, then it won’t refresh.ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = DOWNSTREAM;
How Snowflake schedules refreshes¶
Snowflake schedules refreshes slightly earlier than the target lag to allow time for the refresh to complete. For example, if you set the target lag to 5 minutes, the table might refresh more frequently than every five minutes. Actual refresh intervals are often shorter than the specified lag.
Note
Target lag is a target, not a guarantee. Snowflake attempts to keep data within the target lag, but actual lag may exceed the target because of factors such as warehouse size, data volume, and query complexity.
For guidance on adjusting target lag for your workload, see Alter the warehouse or target lag for dynamic tables. For information about optimizing your target lag, see Identify the right target lag.
How upstream and downstream relationships affect target lag¶
The following diagram illustrates suspend, resume, and manual refresh operations in the context of upstream and downstream relationships to other dynamic tables.
The diagram depicts a simple declarative data pipeline built with dynamic tables:
DT2is described as downstream ofDT1because it depends on that dynamic table, and as upstream ofDT3, which depends on it.DT3is downstream of bothDT2andDT1because it depends onDT2directly and onDT1indirectly.DT1is directly or indirectly upstream of the other dynamic tables.
Example: Target lag for dynamic table chains¶
Consider the following example where a dynamic table (DT2) reads from another dynamic table (DT1) to materialize its contents. In
this scenario, a report consumes DT2’s data via a query.
The following results are possible, depending on how each dynamic table specifies its lag:
|
|
Refresh results |
|---|---|---|
|
|
|
|
|
This scenario should be avoided. The report query will not receive any data. DT1 is frequently refreshed and |
|
|
|
|
|
Neither |