了解动态表目标滞后¶
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 the dynamic tables that depend on it.
动态表的目标滞后是相对于图表根中的动态表来衡量的,而不是直接上游的动态表。要查看连接到动态表的表图形,请参阅 查看连接到动态表的表图形。
Snowflake 计划刷新,使动态表的实际滞后低于目标滞后。每次刷新的持续时间取决于查询、数据模式和仓库规模。选择目标滞后时,请考虑将 链中的每个动态表 刷新到根所需的时间。否则,系统可能会跳过一些刷新,从而导致更高的实际滞后。
目标滞后的类型¶
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.
新鲜度度量:定义动态表内容滞后于基表更新的最长时间。
以下示例将
my_dynamic_table设置为每小时刷新一次并保持新鲜度:ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = '1 hour';
Downstream: Specifies that the dynamic table should refresh on demand when downstream tables (tables that depend on this table) refresh. This refresh can be triggered by initialization at creation, manual refresh, or scheduled refresh of a downstream table.
When
refresh_modeis set todownstream, the refresh schedule of a dynamic table is driven by the most demanding (shortest) lag of its downstream dependents. For example, if one downstream dependent table requires data that is no older than 10 minutes and another downstream dependent table requires data that is no older than 1 hour, the refresh schedule of this dynamic table will be every 10 minutes because that is the shortest lag of its downstream dependents.在下面的示例中,
my_dynamic_table设置为基于其下游动态表的目标滞后进行刷新。如果my_dynamic_table没有任何依赖于它的动态表,则它不会刷新。ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = DOWNSTREAM;
For more examples of downstream target lag, see Example: Target lag for dynamic table chains.
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.
备注
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 更改动态表的仓库或目标滞后. For information about optimizing your target lag, see 确定合适的目标滞后.
上游和下游关系如何影响目标滞后¶
下图说明了在与其他动态表的上游和下游关系的上下文中执行的暂停、恢复和手动刷新操作。
该图描述了使用动态表构建的简单声明性数据管道:
DT2被描述为DT1的 下游,因为它依赖于该动态表,并被描述为依赖于它的DT3的 上游。DT3是DT2和DT1的下游,因为它直接依赖于DT2、间接依赖于DT1。DT1直接或间接位于其他动态表的上游。
Example: Target lag for dynamic table chains¶
考虑以下示例,其中动态表 (DT2) 从另一个动态表 (DT1) 读取数据,以物化其内容。在这种情景下,报告通过查询使用 DT2 的数据。
可能出现以下结果,具体取决于每个动态表指定其滞后的方式:
|
|
刷新结果 |
|---|---|---|
|
|
|
|
|
应避免这种情况。报告查询不会收到任何数据。DT1 经常刷新且 |
|
|
|
|
|
由于 |