Kusto中的视图与物化视图



场景:kusto表中的数据在5小时后更新。任务:从.net API调用查询在查询中,创建一个子查询,并使用该子查询在更大的表上执行联接

let table1=materialize(
Customer|where CustomerId=="cust-reg-aabb-cc232"|distinct CustomerId,City);
CustomerPurchase
|where CustomerId=="cust-reg-aabb-cc232"
//perform join with table1 and other things

let table1=view(){
Customer|where CustomerId=="cust-reg-aabb-cc232"|distinct CustomerId,City};
CustomerPurchase
|where CustomerId=="cust-reg-aabb-cc232"
//perform join with table1 and CustomerPurchase

每5小时更新一次CustomerPurchase和Customer数据(添加新行)。更优化的是:创建一个视图或使用实体化方法。我浏览了文档,但无法理解两者之间的区别。

此外,由于我正在实现API,是否可以使用物化视图而不是表1?

文档非常清楚:

实现

允许在中执行查询期间缓存子查询结果其他子查询可以引用部分结果的方式。

查看

视图是基于Kusto查询结果集的虚拟表语言查询。就像真实的表一样,视图包含行和列。与实际表不同,视图不包含自己的数据存储

视图是通过以下用户定义的函数定义的要求:

  • 函数的结果必须是表格形式的(例如,它不能是标量值)
  • 函数不能包含任何参数

视图关键字

默认情况下,支持通配符语法来指定表的运算符即使视图的名称与通配符。这类运算符的一个例子是并集运算符。在这种情况下,使用view关键字也可以包含视图。

物化视图

物化视图公开源表上的聚合查询,或者在另一个具体化的视图上。

顾名思义,聚合结果是物化的,意思是存储的
在不断获取数据的同时,不断更新结果。


在您的情况下,似乎没有理由使用materialize()view关键字。

使用以下物化视图(在CustomerId上带有筛选器)代替table1可能会提高性能。

.create materialized-view Customer_mv on table Customer
{
Customer
| summarize by CustomerId, City
}

更新

这里有几个例子展示了物化()的好处

1

let t = print x = rand(1000);
union t, t, t
x
337
998
242

最新更新