具体化视图策略Materialized views policies

本文提供了有关可在具体化视图上设置的策略的信息。This article includes information about policies that can be set on a materialized views.

保留和缓存策略Retention and caching policy

具体化视图有保留策略缓存策略,就像任何 Azure 数据资源管理器表一样。A materialized view has a retention policy and caching policy, like any Azure Data Explorer table. 默认情况下,具体化视图会派生数据库保留和缓存策略。The materialized view derives the database retention and caching policies by default. 可以使用保留策略控制命令缓存策略控制命令来更改这些策略。These policies can be changed using retention policy control commands or caching policy control commands.

这两个策略仅应用于具体化视图的具体化部分。Both policies are applied on the materialized part of the materialized view only. 有关“具体化部分”与“增量部分”之间区别的说明,请参阅具体化视图的工作原理For an explanation of the differences between the materialized part and delta part, see how materialized views work. 例如,如果某个具体化视图的缓存策略设置为 7d,但其源表的缓存策略设置为 0d,则查询具体化视图时,可能仍会出现磁盘未命中的情况。For example, if the caching policy of a materialized view is set to 7d, but the caching policy of its source table is set to 0d, there may still be disk misses when querying the materialized view. 发生这种情况是因为源表(增量部分)也参与查询。This will happen because the source table (delta part) participates in the query as well.

具体化视图的保留策略与源表的保留策略无关。The retention policy of the materialized view is unrelated to the retention policy of the source table. 如果需要更短的时间段的源记录,则源表的保留策略可以短于具体化视图的保留策略。Retention policy of source table can be shorter than the retention policy of the materialized view, if source records are required for a shorter period. 建议将最小保留策略至少保留几天,并在源表上将可恢复性设置为 true。We recommend a minimum retention policy of at least few days, and recoverability set to true on the source table. 此设置可用来从错误中快速恢复以及进行诊断。This setting allows for fast recovery for errors and for diagnostic purposes.

备注

不支持源表上的零保留策略。Zero retention policy on the source table isn't supported.

分区策略Partitioning policy

可以在具体化视图上应用分区策略A partitioning policy can be applied on a materialized view. 当大部分或全部视图查询按具体化视图的分组依据键之一进行筛选时,建议在具体化视图上配置分区策略。We recommend configuring a partitioning policy on a materialized view when most or all of the view queries filter by one of the materialized view's group-by keys. 这在多租户解决方案中很常见,其中,实例化视图的分组依据键之一是租户的标识符(例如 tenantIdcustomerId)。This is common in multi-tenant solutions, where one of the materialized view's group-by keys is the tenant's identifer (for example, tenantId, customerId). 有关详细信息,请参阅分区策略常见方案页面中介绍的第一个用例。For more information, see the first use case described in the partitioning policy common scenarios page.

有关用于更改具体化视图的分区策略的命令,请参阅分区策略命令For the commands to alter a materialized view's partitioning policy, see partitioning policy commands.

在具体化视图上添加分区策略会增加具体化视图中的区数,并会为具体化过程增加更多“工作”。Adding a partitioning policy on a materialized views will increase the number of extents in the materialized view, and will create more "work" for the materialization process. 若要详细了解为何会发生此情况,请参阅具体化视图的工作原理中提到的区重新生成过程。For more information on why this happens, see the extents rebuild process mentioned in how materialized views work). EngineV3 群集中,此过程比在 V2 中更高效。In EngineV3 clusters, this process is much more efficient than in V2. 因此,仅当群集是 V3 群集时,才建议在具体化视图上添加分区策略。Therefore, we recommend to only add a partitioning policy on a materialized view only if the cluster is a V3 cluster.

行级别安全策略Row level security policy

行级安全性可以应用于具体化视图,但有几个限制:A row level security can be applied on a materialized view, with several limitations:

  • 此策略只能应用于采用 arg_max()/arg_min()/any() 聚合函数的具体化视图。The policy can be applied only to materialized views with arg_max()/arg_min()/any() aggregation functions.
  • 此策略仅应用于视图的具体化部分The policy is applied to the materialized part of the view only.
    • 如果未在具体化视图的源表上定义相同的行级安全策略,则查询具体化视图时可能会返回应由策略隐藏的记录。If the same row level security policy is not defined on the source table of the materialized view, then querying the materialized view may return records that should be hidden by the policy. 发生这种情况是因为查询具体化视图时也会查询源表。This happens because querying the materialized view queries the source table as well.
    • 如果视图为 arg_max()arg_min()/any(),则建议在源表和具体化视图上定义相同的行级安全策略。We recommend defining the same row level security policy both on the source table and the materialized view if the view is an arg_max() or arg_min()/any().
  • arg_max()arg_min()/any() 具体化视图的源表上定义行级安全策略时,如果没有在具体化视图自身上定义行级安全策略,则命令会失败。When defining a row level security policy on the source table of an arg_max() or arg_min()/any() materialized view, the command will fail if there is no row level security policy defined on the materialized view itself. 失败的目的在于提醒用户存在潜在的数据泄露,因为具体化视图可能会公开信息。The purpose of the failure is to alert the user of a potential data leak, since the materialized view may expose information. 若要缓解此错误,请执行以下操作之一:To mitigate this error, do one of the following actions:
    • 定义针对具体化视图的行级安全策略。Define the row level security policy over the materialized view.
    • 通过将 allowMaterializedViewsWithoutRowLevelSecurity 属性添加到 alter policy 命令来选择忽略错误。Choose to ignore the error by adding allowMaterializedViewsWithoutRowLevelSecurity property to the alter policy command. 例如:For example:
    .alter table SourceTable policy row_level_security enable with (allowMaterializedViewsWithoutRowLevelSecurity=true) "RLS_function"

有关在具体化视图中配置行级安全策略的命令,请参阅 row_level_security 策略命令For commands for configuring a row level security policy on a materialized view, see row_level_security policy commands.