Skip to content

[Roadmap] Support multi table materialized view #7503

Closed

Description

@EmmyMiao87

root issue
Support multi table materialized view, such as join.

Activity

  1. changed the title [-]多表物化视图Doris 当前的 "物化视图" 更偏向 "物化索引" 的概念。后续 Doris 将实现真正的物化视图(Materialized View)以支持单表、多表视图的全量、增量构建。[/-] [+][Proposal] Support multi table materialized view[/+] on Dec 31, 2021
  2. changed the title [-][Proposal] Support multi table materialized view[/-] [+][Roadmap] Support multi table materialized view[/+] on Jan 2, 2022
  3. yangzhg commented on Jun 17, 2022

    @yangzhg
    Member

    Background

    At present, materialized views can be created on a single table, and can use pre-computed results to achieve query acceleration, but support for multi-table scenarios cannot be realized. Many query scenarios are relatively simple and the data update frequency is not high. Materialized views can effectively improve query performance and reduce data calculation

    Competitors

    Both traditional TP database ORACLE and emerging AP database CK are supported

    oracle https://docs.oracle.com/cd/E11882_01/server.112/e10706/repmview.htm#REPLN003,

    CK https://clickhouse.com/docs/en/sql-reference/statements/create/view

    grammar

    Create

    The syntax refers to oracle design

    create materialized view mv_name         -- 1. Create a materialized view
    build [immediate | deferred]             -- 2. Create method, default immediate
    refresh [fast | complete | never]        -- 3. Refresh method of materialized view,
    on [commit | demand]                     -- 4. Refresh trigger method
    start with start_time                    -- 5. Set the start time
    next interval                            -- 6. Set the interval time
    PARTITION BY [range|list]                -- 7. Set the partition column
    DISTRIBUTED BY hash(cols..) BUCKETS 16   -- 8. Set up buckets
    PROPERTIES()                             -- 9. properties
    as                                       -- 10. Keywords
    select ...;                              -- 11. select statement

    explain

    1. "build" -- how to create
    	(1) 'immediate': Take effect immediately, default.
    	(2) 'deferred' : Delay until the first refresh to take effect
    2. "refresh" refresh method
    	(1) fast : 'Fast refresh'. Incremental refresh
    	(2) complete: 'complete refresh'. Update all data when refreshing, including the original data that has been generated in the view
    	(3) never : never refresh
    3. "on" trigger mode (On demand, only need to set 'start time' and 'interval time')
    	(1) on commit: When the base table has a commit action, refresh the map ("Cannot execute across databases")
    	(2) on demand: refresh when needed
    		[1] Refresh according to the 'start time' and 'end time' set later
    		[2] Manual call to refresh

    DESC

    DESCRIBE test_mv_view;

    SHOW CREATE

    SHOW CREATE MATERIALIZED VIEW test_mv_view;

    DROP

    DROP MATERIALIZED VIEW test_mv_view;

    ALTER

    alter materialized view name
    refresh [fast | complete | never]
    on [commit | demand]
    start with start time
    next interval

    refresh

    REFRESH MATERIALIZED VIEW test_mv_view [complete];

    query

    select .... from test_mv_view;

    Optional Automatically hit multi-table materialized views

    design

    Create

    A multi-table materialized view exists as a special type of table. It is essentially a table. All management is the same as a table, but it cannot be updated or imported. It is the same as view in display.

    Multi-table materialized view information is recorded in the information_schema library table

    The table structure is as follows

    +----------------------+------------+------+-------+---------+-------+
    | Field                | Type       | Null | Key   | Default | Extra |
    +----------------------+------------+------+-------+---------+-------+
    | TABLE_CATALOG        | VARCHAR(*) | Yes  | false | NULL    |       |
    | TABLE_SCHEMA         | VARCHAR(*) | Yes  | false | NULL    |       |
    | TABLE_NAME           | VARCHAR(*) | Yes  | false | NULL    |       |
    | VIEW_DEFINITION      | VARCHAR(*) | Yes  | false | NULL    |       |
    | CHECK_OPTION         | VARCHAR(*) | Yes  | false | NULL    |       |
    | IS_UPDATABLE         | VARCHAR(*) | Yes  | false | NULL    |       |
    | DEFINER              | VARCHAR(*) | Yes  | false | NULL    |       |
    | SECURITY_TYPE        | VARCHAR(*) | Yes  | false | NULL    |       |
    | CHARACTER_SET_CLIENT | VARCHAR(*) | Yes  | false | NULL    |       |
    | COLLATION_CONNECTION | VARCHAR(*) | Yes  | false | NULL    |       |
    | STATUS               | VARCHAR(*) | Yes  | false | NULL    |       |
    +----------------------+------------+------+-------+---------+-------+
    
    The STATUS field represents the current state of the materialized view, and the optional value [Syncing|OutDate|UpToDate|Never|Error] checks the data update state of the materialized view during display

    refresh

    According to the refresh strategy, data is imported or refreshed periodically. If the data is not up-to-date, it will be updated according to the conditions, and the command to refresh the data will be issued at the same time, and it will be converted into a normal view query. You can also refresh manually. The refresh command is essentially insert into select, which is completed in the background. At the same time, change the STATUS in materialized_views to Syncing, and change it to UpToDate after synchronization is complete.

    alter

    When performing schema change on a table, it is necessary to judge the impact and whether it is necessary to update the multi-table materialized view

    query

    • Multi-table materialized views can be directly queried and automatically hit if possible

    other

    • Multi-table materialized views are not suitable for frequently updated tables when updated on commit
  4. self-assigned this
    on Jun 17, 2022
  5. yangzhg commented on Jun 20, 2022

    @yangzhg
    Member

    hi @yangzhg , that would be a great feature. I have some questions about this feature:

    1. Do we support insert/update and delete? If yes, how to do that?
    2. The MV can be queried directly, are we plan to also support auto query in feature?
    1. MV is read only and updated only by system
    2. auto hit mv is a greate feature, maybe it can be implemented
  6. morningman commented on Jun 20, 2022

    @morningman
    Contributor
    • MV is read only and updated only by system

    Oh, I mean if I update/insert/delete the base table, the mv can be updated automatically? Is it an incremental update, or fully rebuild?

  7. yangzhg commented on Jun 20, 2022

    @yangzhg
    Member
    • MV is read only and updated only by system

    Oh, I mean if I update/insert/delete the base table, the mv can be updated automatically? Is it an incremental update, or fully rebuild?

    2. "refresh" refresh method
    	(1) fast : 'Fast refresh'. Incremental refresh
    	(2) complete: 'complete refresh'. Update all data when refreshing, including the original data that has been generated in the view
    	(3) never : never refresh

    Incremental updates and automatic hits may not be possible in the short term and can be used as future optimization goals

  8. yangzhg commented on Jun 20, 2022

    @yangzhg
    Member

    缘起

    现在物化视图能够支持在单表上创建,能够使用预计算的结果实现查询加速,但是对于多表场景的支持还不能实现,很多查询场景比较单一,数据更新频率不高的情况下,多表的物化视图能够有效的提升查询性能,减少数据的计算

    竞品

    传统TP数据库ORACLE 和新兴AP数据库 CK 都支持

    oracle https://docs.oracle.com/cd/E11882_01/server.112/e10706/repmview.htm#REPLN003、

    CK https://clickhouse.com/docs/en/sql-reference/statements/create/view

    语法

    创建

    语法参照oracle 设计

    create materialized view mv_name          -- 1. 创建物化视图
    build [immediate | deferred] 			        -- 2. 创建方式,默认 immediate
    refresh [fast | complete | never].        -- 3. 物化视图刷新方式,
    on [commit | demand] 					            -- 4. 刷新触发方式
    start with start_time				              -- 5. 设置开始时间
    next interval				                      -- 6. 设置间隔时间
    PARTITION BY [range|list]                 -- 7. 设置分区列
    DISTRIBUTED BY hash(cols..) BUCKETS 16    -- 8. 设置分桶
    PROPERTIES()                              -- 9. properties
    as	                                      -- 10. 关键字
    select ...;                               -- 11. select 语句

    解释

    1. "build" -- 创建方式
    	(1) 'immediate':立即生效,默认。
    	(2) 'deferred' : 延迟至第一次 refresh 时才生效
    2. "refresh" 刷新方式
    	(2) fast	:'快速刷新'。增量刷新
    	(3) complete: '完全刷新'。刷新时更新全部数据,包括视图中已经生成的原有数据
    	(4) never	: 从不刷新	
    3. "on" 触发方式 (on demand 中,才需要设置 '开始时间' 和 '间隔时间')
    	(1) on commit:基表有 commit 动作时,刷新刷图("不能跨库执行")
    	(2) on demand:在需要时刷新
    			   [1] 根据后面设定的 '开始时间' 和 '结束时间' 进行刷新
    			   [2] 手动调用进行刷新			       

    DESC

    DESCRIBE test_mv_view;

    SHOW CREATE

    SHOW CREATE MATERIALIZED VIEW test_mv_view;

    DROP

    DROP MATERIALIZED VIEW test_mv_view;

    ALTER

    alter materialized view 物化视图名
    refresh [fast | complete | never]
    on [commit | demand]
    start with 开始时间
    next 间隔时间

    刷新

    REFRESH MATERIALIZED VIEW test_mv_view [complete];

    查询

    select .... from test_mv_view;

    可选 自动命中多表物化视图

    实现

    创建

    多表物化视图作为一种特殊类型表存在,本质上是一张表,所有管理和表一样,但是无法更新,无法导入, 在显示上和view 相同

    多表物化视图信息记录在 information_schema 库中 表中

    表结构如下

    +----------------------+------------+------+-------+---------+-------+
    | Field                | Type       | Null | Key   | Default | Extra |
    +----------------------+------------+------+-------+---------+-------+
    | TABLE_CATALOG        | VARCHAR(*) | Yes  | false | NULL    |       |
    | TABLE_SCHEMA         | VARCHAR(*) | Yes  | false | NULL    |       |
    | TABLE_NAME           | VARCHAR(*) | Yes  | false | NULL    |       |
    | VIEW_DEFINITION      | VARCHAR(*) | Yes  | false | NULL    |       |
    | CHECK_OPTION         | VARCHAR(*) | Yes  | false | NULL    |       |
    | IS_UPDATABLE         | VARCHAR(*) | Yes  | false | NULL    |       |
    | DEFINER              | VARCHAR(*) | Yes  | false | NULL    |       |
    | SECURITY_TYPE        | VARCHAR(*) | Yes  | false | NULL    |       |
    | CHARACTER_SET_CLIENT | VARCHAR(*) | Yes  | false | NULL    |       |
    | COLLATION_CONNECTION | VARCHAR(*) | Yes  | false | NULL    |       |
    | STATUS               | VARCHAR(*) | Yes  | false | NULL    |       |
    +----------------------+------------+------+-------+---------+-------+
    
    STATUS 字段表示当前物化视图状态,可选值 [Syncing|OutDate|UpToDate|Never|Error] 在展示时检查物化视图的数据更新状态

    更新

    根据刷新策略,在数据导入或者定时刷新数据。 如果数据不是最新的则根据条件更新,发出刷新数据命令同时转换成普通视图查询。也可以手动刷新,刷新命令本质上是 insert into select ,在后台完成,同时将materialized_views 中STATUS改成Syncing,同步完成后改成UpToDate

    更改

    在对表进行schema chang 时需要判断影响,是否需要更新多表物化视图

    查询

    • 多表物化视图可以直接查询,如果可能也可以自动命中

    其他

    • 多表物化视图在 on commit 更新时不适合 频繁更新的表
  9. BiteTheDDDDt commented on Jun 21, 2022

    @BiteTheDDDDt
    Contributor

    Can we think that this is a new mv that is not related to the original single-table mv?

  10. yangzhg commented on Jun 22, 2022

    @yangzhg
    Member

    Can we think that this is a new mv that is not related to the original single-table mv?

    I think so, single-table mv more like an index

  11. voyagertanyao commented on Sep 20, 2022

    @voyagertanyao

    弱弱的问一下,物化视图增强版什么时候可以发布呢?目前我们在调研doris 1.1.1,用起来感觉这个功能限制实在是太多了,不是特别好用,本想用这个功能替换kylin的,目前感觉这个物化视图功能还不够完善;

    1. 支持的聚合函数太少;
    2. 不支持计算列;
    3. count(1),count(*)这种无法创建物化视图,select count(1)查询无法命中;
    4. 不支持多表;
    5. 同一列不支持多个计算函数;
    6. 基础表的分桶字段不能作为度量列;
  12. deleted a comment from xxiao2018 on Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions