materialized_view() 函数materialized_view() function

引用具体化视图的具体化部分。References the materialized part of a materialized view.

materialized_view() 函数支持仅查询视图的具体化部分,同时指定用户愿容忍的最大延迟。The materialized_view() function supports a way of querying the materialized part only of the view, while specifying the max latency the user is willing to tolerate. 此选项不保证返回最新记录,但与查询整个视图相比,此选项始终更加高效。This option isn't guaranteed to return the most up-to-date records, but should always be more performant than querying the entire view. 此函数适用于愿舍弃一些新鲜度以提高性能的方案,例如在遥测仪表板中。This function is useful for scenarios in which you're willing to sacrifice some freshness for performance, for example in telemetry dashboards.

materialized_view('ViewName')

语法Syntax

materialized_view(ViewName, [max_age]) materialized_view(ViewName, [ max_age ])

参数Arguments

  • ViewName:materialized view 的名称。ViewName : The name of the materialized view.
  • max_age:可选。max_age : Optional. 如果未提供,则仅返回视图的具体化部分。If not provided, only the materialized part of the view is returned. 如果已提供,并且上次具体化时间晚于 [@now - max_age],则函数将返回视图的具体化部分。If provided, function will return the materialized part of the view if last materialization time is greater than [@now - max_age]. 否则,返回整个视图(等同于直接查询 ViewName。Otherwise, the entire view is returned (identical to querying ViewName directly.

示例Examples

仅查询视图的具体化部分,与视图上次具体化的时间无关。Query the materialized part of the view only, independent on when it was last materialized.

materialized_view("ViewName")

仅在最近 10 分钟内具体化了视图时才查询具体化部分。Query the materialized part only if it was materialized in the last 10 minutes. 如果具体化部分的时间在 10 分钟之前,则返回完整视图。If the materialized part is older than 10 minutes, return the full view. 预计此选项比查询具体化部分低效。This option is expected to be less performant than querying the materialized part.

materialized_view("ViewName", 10m)

说明Notes

  • 创建视图后,可以以查询数据库中的其他任何表的方式对其进行查询,包括参与跨群集/跨数据库查询。Once a view is created, it can be queried just as any other table in the database, including participate in cross-cluster / cross-database queries.
  • 通配符并集或搜索中不包含具体化视图。Materialized views aren't included in wildcard unions or searches.
  • 查询视图的语法是视图名称(如表格引用)。Syntax for querying the view is the view name (like a table reference).
  • 查询具体化视图将始终根据引入源表的所有记录返回最新结果。Querying the materialized view will always return the most up-to-date results, based on all records ingested to the source table. 该查询会将视图的具体化部分与源表中的所有未具体化记录结合起来。The query combines the materialized part of the view with all unmaterialized records in the source table. 有关详细信息,请参阅幕后For more information, see behind the scenes for details.