了解动态表目标滞后

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.

  1. 新鲜度度量:定义动态表内容滞后于基表更新的最长时间。

    以下示例将 my_dynamic_table 设置为每小时刷新一次并保持新鲜度:

    ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = '1 hour';
    
    Copy
  2. 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_mode is set to downstream, 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;
    
    Copy

    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上游

  • DT3DT2DT1 的下游,因为它直接依赖于 DT2、间接依赖于 DT1

  • DT1 直接或间接位于其他动态表的上游。

Example: Target lag for dynamic table chains

考虑以下示例,其中动态表 (DT2) 从另一个动态表 (DT1) 读取数据,以物化其内容。在这种情景下,报告通过查询使用 DT2 的数据。

两个动态表的简单示例,DT2 基于 DT1 定义。

可能出现以下结果,具体取决于每个动态表指定其滞后的方式:

DT1

DT2

刷新结果

TARGET_LAG = DOWNSTREAM

TARGET_LAG = 10minutes

DT2 至少每 10 分钟更新一次。DT1 根据 DT2 推断其滞后,并且每次 DT2 需要更新时都会更新。

TARGET_LAG = 10minutes

TARGET_LAG = DOWNSTREAM

应避免这种情况。报告查询不会收到任何数据。DT1 经常刷新且 DT2 不刷新,因为没有基于 DT2 的动态表。

TARGET_LAG = 5minutes

TARGET_LAG = 10minutes

DT2 大约每 10 分钟使用 DT1 的数据更新一次,而后者最多 5 分钟更新一次。

TARGET_LAG = DOWNSTREAM

TARGET_LAG = DOWNSTREAM

由于 DT1DT2 都有下游滞后,并且都没有已定义滞后的下游使用者,因此它们都不会定期刷新。

语言: 中文