You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/08/03 02:03:29 UTC

[GitHub] [incubator-doris] EmmyMiao87 commented on a change in pull request #4229: [Docs] Add Materialized view manual

EmmyMiao87 commented on a change in pull request #4229:
URL: https://github.com/apache/incubator-doris/pull/4229#discussion_r464158831



##########
File path: docs/zh-CN/administrator-guide/materialized_view.md
##########
@@ -0,0 +1,490 @@
+---
+{
+    "title": "物化视图",
+    "language": "zh-CN"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# 物化视图
+
+物化视图是将预先计算(根据定义好的 SELECT 语句)好的数据集,存储在 Doris 中的一个特殊的表。
+
+物化视图的出现主要是为了满足用户,既能对原始明细数据的任意维度分析,也能快速的对固定维度进行分析查询。
+
+## 适用场景
+
++ 分析需求覆盖明细数据查询以及固定维度查询两方面。
++ 查询仅涉及表中的很小一部分列或行。
++ 查询包含一些耗时处理操作,比如:时间很久的聚合操作等。
++ 查询需要匹配不同前缀索引。
+
+## 优势
+
++ 对于那些经常重复的使用相同的子查询结果的查询性能大幅提升
++ Doris自动维护物化视图的数据,无论是新的导入,还是删除操作都能保证base 表和物化视图表的数据一致性。无需任何额外的人工维护成本。
++ 查询时,会自动匹配到最优物化视图,并直接从物化视图中读取数据。
+
+*自动维护物化视图的数据会造成一些维护开销,会在后面的物化视图的局限性中展开说明。*
+
+## 物化视图 VS Rollup
+
+在没有物化视图功能之前,用户一般都是使用 Rollup 功能通过预聚合方式提升查询效率的。但是 Rollup 具有一定的局限性,他不能基于明细模型做预聚合。
+
+物化视图则在覆盖了 Rollup 的功能的同时,还能支持更丰富的聚合函数。所以物化视图其实是 Rollup 的一个超集。
+
+也就是说,之前 `ALTER TABLE ADD ROLLUP` 语法支持的功能现在均可以通过 `CREATE MATERIALIZED VIEW` 实现。
+
+## 使用物化视图
+
+Doris 系统提供了一整套对物化视图的 DDL 语法,包括创建,查看,删除。DDL 的语法和 PostgreSQL, Oracle都是一致的。
+
+### 创建物化视图
+
+这里首先你要根据你的查询语句的特点来决定创建一个什么样的物化视图。这里并不是说你的物化视图定义和你的某个查询语句一模一样就最好。这里有两个原则:
+
+1. 从查询语句中**抽象**出,多个查询共有的分组和聚合方式作为物化视图的定义。
+2. 不需要给所有维度组合都创建物化视图。
+
+首先第一个点,一个物化视图如果抽象出来,并且多个查询都可以匹配到这张物化视图。这种物化视图效果最好。因为物化视图的维护本身也需要消耗资源。
+
+如果物化视图只和某个特殊的查询很贴合,而其他查询均用不到这个物化视图。则会导致这张物化视图的性价比不高,既占用了集群的存储资源,还不能为更多的查询服务。
+
+所以用户需要结合自己的查询语句,以及数据维度信息去抽象出一些物化视图的定义。
+
+第二点就是,在实际的分析查询中,并不会覆盖到所有的维度分析。所以给常用的维度组合创建物化视图即可,从而到达一个空间和时间上的平衡。
+
+通过下面命令就可以创建物化视图了。创建物化视图是一个异步的操作,也就是说用户成功提交创建任务后,Doris 会在后台对存量的数据进行计算,直到创建成功。
+
+```
+CREATE MATERIALIZED VIEW
+```
+
+具体的语法可以通过下面命令查看:
+
+```
+HELP CREATE MATERIALIZED VIEW
+```
+
+### 支持聚合函数
+
+目前物化视图功能支持的聚合函数有:
+
++ SUM, MIN, MAX (Version 0.12)
++ COUNT, BITMAP\_UNION, HLL\_UNION (Version 0.13)

Review comment:
       物化视图建表支持的聚合函数。




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org