刷新配置
build_mode 刷新时机
物化视图创建完成是否立即刷新。

IMMEDIATE：立即刷新，默认方式。
DEFERRED：延迟刷新。
refresh_method 刷新方式
COMPLETE：刷新所有分区。
AUTO：尽量增量刷新，只刷新自上次物化刷新后数据变化的分区，如果不能感知数据变化的分区，只能退化成全量刷新，刷新所有分区。
refresh_trigger 触发方式
ON MANUAL 手动触发

用户通过 SQL 语句触发物化视图的刷新，策略如下

--检测基表的分区数据自上次刷新后是否有变化，刷新数据变化的分区
REFRESH MATERIALIZED VIEW mvName AUTO;
--不校验基表的分区数据自上次刷新后是否有变化，直接刷新物化视图的所有分区。
REFRESH MATERIALIZED VIEW mvName COMPLETE;
--只刷新指定的分区。
REFRESH MATERIALIZED VIEW mvName partitions(partitionName1,partitionName2);
--ON SCHEDULE 定时触发
-- 定时全量
CREATE MATERIALIZED VIEW mv_6
REFRESH COMPLETE ON SCHEDULE EVERY 10 hour
AS
SELECT * FROM lineitem;
-- 定时增量
CREATE MATERIALIZED VIEW mv_8
REFRESH AUTO ON COMMIT
PARTITION by(l_shipdate)
AS
SELECT * FROM lineitem;
--ON COMMIT 自动触发 (Apache Doris 2.1.4 版本起支持此功能)
CREATE MATERIALIZED VIEW mv_8
REFRESH AUTO ON COMMIT
PARTITION by(l_shipdate)
AS
SELECT * FROM lineitem;
-- BUILD IMMEDIATE  创建完立即刷新
CREATE MATERIALIZED VIEW mv_1_0
BUILD IMMEDIATE
REFRESH AUTO
ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2
AS
SELECT
  l_linestatus,
  to_date(o_orderdate) as date_alias,
  o_shippriority
FROM
  orders
  LEFT JOIN lineitem ON l_orderkey = o_orderkey;
-- 延迟刷新 BUILD DEFERRED
CREATE MATERIALIZED VIEW mv_1_1
BUILD DEFERRED
REFRESH COMPLETE
ON SCHEDULE EVERY 1 DAY STARTS '2024-12-01 20:30:00'
PROPERTIES ('replication_num' = '1')
AS
SELECT
l_linestatus,
to_date(o_orderdate) as date_alias,
o_shippriority
FROM
orders
LEFT JOIN lineitem ON l_orderkey = o_orderkey;

-------
CREATE MATERIALIZED VIEW mv_yinzhou
BUILD IMMEDIATE              -- 创建后立即全量刷新
REFRESH AUTO                 -- 优先增量刷新（仅刷新变化分区）
ON SCHEDULE EVERY 1 DAY      -- 每日执行一次
STARTS '2025-06-27 03:15:00' -- 首次刷新时间（次日凌晨3:15）
DISTRIBUTED BY HASH(l_linestatus) BUCKETS AUTO  -- 自动分桶
AS
SELECT
  l_linestatus,
  to_date(o_orderdate) as date_alias,
  o_shippriority
FROM
  orders
  LEFT JOIN lineitem ON l_orderkey = o_orderkey;