diff --git a/docs/en/docs/query-acceleration/async-materialized-view.md b/docs/en/docs/query-acceleration/async-materialized-view.md new file mode 100644 index 00000000000000..2a77ff2d4b4a65 --- /dev/null +++ b/docs/en/docs/query-acceleration/async-materialized-view.md @@ -0,0 +1,216 @@ +--- +{ + "title": "Asynchronous materialized view", + "language": "en" +} +--- + + + +# Asynchronous materialized view + +## Construction and maintenance of materialized views + +### Create materialized views + +Prepare two tables and data +```sql +use tpch; + +CREATE TABLE IF NOT EXISTS orders ( + o_orderkey integer not null, + o_custkey integer not null, + o_orderstatus char(1) not null, + o_totalprice decimalv3(15,2) not null, + o_orderdate date not null, + o_orderpriority char(15) not null, + o_clerk char(15) not null, + o_shippriority integer not null, + o_comment varchar(79) not null + ) + DUPLICATE KEY(o_orderkey, o_custkey) + PARTITION BY RANGE(o_orderdate)( + FROM ('2023-10-17') TO ('2023-10-20') INTERVAL 1 DAY) + DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 + PROPERTIES ("replication_num" = "1"); + +insert into orders values + (1, 1, 'ok', 99.5, '2023-10-17', 'a', 'b', 1, 'yy'), + (2, 2, 'ok', 109.2, '2023-10-18', 'c','d',2, 'mm'), + (3, 3, 'ok', 99.5, '2023-10-19', 'a', 'b', 1, 'yy'); + +CREATE TABLE IF NOT EXISTS lineitem ( + l_orderkey integer not null, + l_partkey integer not null, + l_suppkey integer not null, + l_linenumber integer not null, + l_quantity decimalv3(15,2) not null, + l_extendedprice decimalv3(15,2) not null, + l_discount decimalv3(15,2) not null, + l_tax decimalv3(15,2) not null, + l_returnflag char(1) not null, + l_linestatus char(1) not null, + l_shipdate date not null, + l_commitdate date not null, + l_receiptdate date not null, + l_shipinstruct char(25) not null, + l_shipmode char(10) not null, + l_comment varchar(44) not null + ) + DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) + PARTITION BY RANGE(l_shipdate) + (FROM ('2023-10-17') TO ('2023-10-20') INTERVAL 1 DAY) + DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 + PROPERTIES ("replication_num" = "1"); + +insert into lineitem values + (1, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy'), + (2, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-18', '2023-10-18', '2023-10-18', 'a', 'b', 'yyyyyyyyy'), + (3, 2, 3, 6, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', '2023-10-19', '2023-10-19', 'c', 'd', 'xxxxxxxxx'); +``` +Create materialized views +```sql +CREATE MATERIALIZED VIEW mv1 + BUILD DEFERRED REFRESH AUTO ON MANUAL + partition by(l_shipdate) + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS + select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total + from lineitem + left join orders on lineitem.l_orderkey = orders.o_orderkey and l_shipdate = o_orderdate + group by + l_shipdate, + o_orderdate, + l_partkey, + l_suppkey; +``` + +Specific syntax can be viewed [CREATE MATERIALIZED VIEW](../sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md) + +### View materialized view meta information + +```sql +select * from mv_infos("database"="tpch") where Name="mv1"; +``` + +The unique features of materialized views can be viewed through [mv_infos()](../sql-manual/sql-functions/table-functions/mv_infos.md) + +Properties related to table, still viewed through [SHOW TABLES](../sql-manual/sql-reference/Show-Statements/SHOW-TABLES.md) + +### Refresh materialized view + +The materialized view supports different refresh strategies, such as scheduled refresh and manual refresh. It also supports different refresh granularity, such as full refresh, incremental refresh of partition granularity, etc. Here we take manually refreshing partial partitions of the materialized view as an example. + +First, check the list of materialized view partitions +```sql +SHOW PARTITIONS FROM mv1; +``` + +Refresh partition named `p_20231017_20231018` +```sql +REFRESH MATERIALIZED VIEW mv1 partitions(p_20231017_20231018); +``` + +Specific syntax can be viewed [REFRESH MATERIALIZED VIEW](../sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md) + +### task management + +Each materialized view defaults to a job responsible for refreshing data, which is used to describe the refresh strategy and other information of the materialized view. Each time a refresh is triggered, a task is generated, +Task is used to describe specific refresh information, such as the time used for refreshing, which partitions were refreshed, etc + +#### View jobs in materialized views + +```sql +select * from jobs("type"="mv") order by CreateTime; +``` + +Specific syntax can be viewed [jobs("type"="mv")](../sql-manual/sql-functions/table-functions/jobs.md) + +#### Pause materialized view job scheduled scheduling + +```sql +PAUSE MATERIALIZED VIEW JOB ON mv1; +``` + +Can pause the scheduled scheduling of materialized views + +Specific syntax can be viewed [PAUSE MATERIALIZED VIEW JOB](../sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md) + +#### RESUME materialized view job scheduling + +```sql +RESUME MATERIALIZED VIEW JOB ON mv1; +``` + +Can RESUME scheduled scheduling of materialized views + +Specific syntax can be viewed [RESUME MATERIALIZED VIEW JOB](../sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md) + +#### Viewing tasks in materialized views + +```sql +select * from tasks("type"="mv"); +``` + +Specific syntax can be viewed [tasks("type"="mv")](../sql-manual/sql-functions/table-functions/tasks.md) + +#### Cancel the task of objectifying the view + +```sql +CANCEL MATERIALIZED VIEW TASK realTaskId on mv1; +``` + +Can cancel the operation of this task + +Specific syntax can be viewed [CANCEL MATERIALIZED VIEW TASK](../sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md) + +### Modifying materialized views + +Modify the properties of materialized views +```sql +ALTER MATERIALIZED VIEW mv1 set("grace_period"="3333"); +``` + +Modify the name of the materialized view, the refresh method of the materialized view, and the unique properties of the materialized view can be viewed through [ALTER MATERIALIZED VIEW](../sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md) + +The materialized view itself is also a Table, so Table related properties, such as the number of copies, are still modified through the syntax related to `ALTER TABLE`. + +### Delete materialized view + +```sql +DROP MATERIALIZED VIEW mv1; +``` + +The materialized view has a dedicated deletion syntax and cannot be deleted through the drop table, + +Specific syntax can be viewed [DROP MATERIALIZED VIEW](../sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md) + +## The use of materialized views + +### Directly view data from materialized views + +The materialized view itself is also a Table, so it can be directly queried + +```sql +select * FROM mv1; +``` + +### Transparent rewriting \ No newline at end of file diff --git a/docs/en/docs/sql-manual/sql-functions/table-functions/jobs.md b/docs/en/docs/sql-manual/sql-functions/table-functions/jobs.md new file mode 100644 index 00000000000000..602ef985dbabaf --- /dev/null +++ b/docs/en/docs/sql-manual/sql-functions/table-functions/jobs.md @@ -0,0 +1,90 @@ +--- +{ + "title": "JOBS", + "language": "en" +} +--- + + + +## `jobs` + +### Name + +jobs + +### description + +Table function, generating a temporary task table, which can view job information in a certain task type. + +This function is used in the from clause. + +#### syntax + +`jobs("type"="")` + +jobs("type"="mv")Table structure: +```sql +mysql> desc function jobs("type"="mv"); ++-------------------+------+------+-------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------------------+------+------+-------+---------+-------+ +| Id | TEXT | No | false | NULL | NONE | +| Name | TEXT | No | false | NULL | NONE | +| MvId | TEXT | No | false | NULL | NONE | +| MvName | TEXT | No | false | NULL | NONE | +| MvDatabaseId | TEXT | No | false | NULL | NONE | +| MvDatabaseName | TEXT | No | false | NULL | NONE | +| ExecuteType | TEXT | No | false | NULL | NONE | +| RecurringStrategy | TEXT | No | false | NULL | NONE | +| Status | TEXT | No | false | NULL | NONE | +| CreateTime | TEXT | No | false | NULL | NONE | ++-------------------+------+------+-------+---------+-------+ +10 rows in set (0.00 sec) +``` + +* Id: job ID. +* Name: job name. +* MvId: Materialized View ID +* MvName: Materialized View Name +* MvDatabaseId: DB ID of the materialized view +* MvDatabaseName: Name of the database to which the materialized view belongs +* ExecuteType: Execution type +* RecurringStrategy: Loop strategy +* Status: Job status +* CreateTime: Task creation time + +### example + +1. View jobs in all materialized views + +```sql +mysql> select * from jobs("type"="mv"); +``` + +2. View job with name `inner_mtmv_75043` + +```sql +mysql> select * from jobs("type"="mv") where Name="inner_mtmv_75043"; +``` + +### keywords + + jobs diff --git a/docs/en/docs/sql-manual/sql-functions/table-functions/mv_infos.md b/docs/en/docs/sql-manual/sql-functions/table-functions/mv_infos.md new file mode 100644 index 00000000000000..e9c9c24c9a7d5e --- /dev/null +++ b/docs/en/docs/sql-manual/sql-functions/table-functions/mv_infos.md @@ -0,0 +1,100 @@ +--- +{ + "title": "MV_INFOS", + "language": "en" +} +--- + + + +## `mv_infos` + +### Name + +mv_infos + +### description + +Table function, generating temporary tables for asynchronous materialized views, which can view information about asynchronous materialized views created in a certain database. + +This function is used in the from clause. + +#### syntax + +`mv_infos("database"="")` + +mv_infos() Table structure: +```sql +mysql> desc function mv_infos("database"="tpch100"); ++--------------------+---------+------+-------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+---------+------+-------+---------+-------+ +| Id | BIGINT | No | false | NULL | NONE | +| Name | TEXT | No | false | NULL | NONE | +| JobName | TEXT | No | false | NULL | NONE | +| State | TEXT | No | false | NULL | NONE | +| SchemaChangeDetail | TEXT | No | false | NULL | NONE | +| RefreshState | TEXT | No | false | NULL | NONE | +| RefreshInfo | TEXT | No | false | NULL | NONE | +| QuerySql | TEXT | No | false | NULL | NONE | +| EnvInfo | TEXT | No | false | NULL | NONE | +| MvProperties | TEXT | No | false | NULL | NONE | +| MvPartitionInfo | TEXT | No | false | NULL | NONE | +| SyncWithBaseTables | BOOLEAN | No | false | NULL | NONE | ++--------------------+---------+------+-------+---------+-------+ +12 rows in set (0.01 sec) +``` + +* Id: Materialized View ID +* Name: Materialized View Name +* JobName: The job name corresponding to the materialized view +* State: Materialized View State +* SchemaChangeDetail: The reason why the materialized view State becomes a SchemeChange +* RefreshState: Materialized view refresh status +* RefreshInfo: Refreshing strategy information defined by materialized views +* QuerySql: Query statements defined by materialized views +* EnvInfo: Environmental information during the creation of materialized views +* MvProperties: Materialized visual attributes +* MvPartitionInfo: Partition information of materialized views +* SyncWithBaseTables:Is it synchronized with the base table data? To see which partition is not synchronized, please use [SHOW PARTITIONS](../sql-reference/Show-Statements/SHOW-PARTITIONS.md) + +### example + +1. View all materialized views under db1 + +```sql +mysql> select * from mv_infos("database"="db1"); +``` + +2. View the materialized view named mv1 under db1 + +```sql +mysql> select * from mv_infos("database"="db1") where Name = "mv1"; +``` + +3. View the status of the materialized view named mv1 under db1 + +```sql +mysql> select State from mv_infos("database"="db1") where Name = "mv1"; +``` + +### keywords + + mv, infos diff --git a/docs/en/docs/sql-manual/sql-functions/table-functions/tasks.md b/docs/en/docs/sql-manual/sql-functions/table-functions/tasks.md new file mode 100644 index 00000000000000..e924cc8d6d90d0 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-functions/table-functions/tasks.md @@ -0,0 +1,106 @@ +--- +{ + "title": "TASKS", + "language": "en" +} +--- + + + +## `tasks` + +### Name + +tasks + +### description + +Table function, generating a temporary task table, which can view task information in a certain task type. + +This function is used in the from clause. + +#### syntax + +`tasks("type"="")` + +tasks("type"="mv") Table structure: +```sql +mysql> desc function tasks("type"="mv"); ++-----------------------+------+------+-------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-----------------------+------+------+-------+---------+-------+ +| TaskId | TEXT | No | false | NULL | NONE | +| JobId | TEXT | No | false | NULL | NONE | +| JobName | TEXT | No | false | NULL | NONE | +| MvId | TEXT | No | false | NULL | NONE | +| MvName | TEXT | No | false | NULL | NONE | +| MvDatabaseId | TEXT | No | false | NULL | NONE | +| MvDatabaseName | TEXT | No | false | NULL | NONE | +| Status | TEXT | No | false | NULL | NONE | +| ErrorMsg | TEXT | No | false | NULL | NONE | +| CreateTime | TEXT | No | false | NULL | NONE | +| StartTime | TEXT | No | false | NULL | NONE | +| FinishTime | TEXT | No | false | NULL | NONE | +| DurationMs | TEXT | No | false | NULL | NONE | +| TaskContext | TEXT | No | false | NULL | NONE | +| RefreshMode | TEXT | No | false | NULL | NONE | +| NeedRefreshPartitions | TEXT | No | false | NULL | NONE | +| CompletedPartitions | TEXT | No | false | NULL | NONE | +| Progress | TEXT | No | false | NULL | NONE | ++-----------------------+------+------+-------+---------+-------+ +18 rows in set (0.00 sec) +``` + +* TaskId: task id +* JobId: job id +* JobName: job Name +* MvId: Materialized View ID +* MvName: Materialized View Name +* MvDatabaseId: DB ID of the materialized view +* MvDatabaseName: Name of the database to which the materialized view belongs +* Status: task status +* ErrorMsg: Task failure information +* CreateTime: Task creation time +* StartTime: Task start running time +* FinishTime: Task End Run Time +* DurationMs: Task runtime +* TaskContext: Task running parameters +* RefreshMode: refresh mode +* NeedRefreshPartitions: The partition information that needs to be refreshed for this task +* CompletedPartitions: The partition information that has been refreshed for this task +* Progress: Task running progress + +### example + +1. View tasks for all materialized views + +```sql +mysql> select * from tasks("type"="mv"); +``` + +2. View all tasks with jobName `inner_mtmv_75043` + +```sql +mysql> select * from tasks("type"="mv") where JobName="inner_mtmv_75043"; +``` + +### keywords + + tasks diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..11f24aed95fa2a --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md @@ -0,0 +1,75 @@ +--- +{ + "title": "ALTER-ASYNC-MATERIALIZED-VIEW", + "language": "en" +} +--- + + + +## ALTER-ASYNC-MATERIALIZED-VIEW + +### Name + +ALTER ASYNC MATERIALIZED VIEW + +### Description + +This statement is used to modify asynchronous materialized views. + +#### syntax + +```sql +ALTER MATERIALIZED VIEW mvName=multipartIdentifier ((RENAME newName=identifier) + | (REFRESH (refreshMethod | refreshTrigger | refreshMethod refreshTrigger)) + | (SET LEFT_PAREN fileProperties=propertyItemList RIGHT_PAREN)) +``` + +#### illustrate + +##### RENAME + +Used to change the name of the materialized view + +For example, changing the name of mv1 to mv2 +```sql +ALTER MATERIALIZED VIEW mv1 rename mv2; +``` + +##### refreshMethod + +Same as [creating asynchronous materialized views](../Create/CREATE-ASYNC-MATERIALIZED-VIEW.md) + +##### refreshTrigger + +Same as [creating asynchronous materialized views](../Create/CREATE-ASYNC-MATERIALIZED-VIEW.md) + +##### SET +Modify properties unique to materialized views + +For example, modifying the grace_period of mv1 to 3000ms +```sql +ALTER MATERIALIZED VIEW mv1 set("grace_period"="3000"); +``` + +### Keywords + + ALTER, ASYNC, MATERIALIZED, VIEW + diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..31450326d7a59d --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md @@ -0,0 +1,216 @@ +--- +{ + "title": "CREATE-ASYNC-MATERIALIZED-VIEW", + "language": "en" +} +--- + + + +## CREATE-ASYNC-MATERIALIZED-VIEW + +### Name + +CREATE ASYNC MATERIALIZED VIEW + +### Description + +This statement is used to create an asynchronous materialized view. + +#### syntax + +```sql +CREATE MATERIALIZED VIEW (IF NOT EXISTS)? mvName=multipartIdentifier + (LEFT_PAREN cols=simpleColumnDefs RIGHT_PAREN)? buildMode? + (REFRESH refreshMethod? refreshTrigger?)? + (KEY keys=identifierList)? + (COMMENT STRING_LITERAL)? + (PARTITION BY LEFT_PAREN partitionKey = identifier RIGHT_PAREN)? + (DISTRIBUTED BY (HASH hashKeys=identifierList | RANDOM) (BUCKETS (INTEGER_VALUE | AUTO))?)? + propertyClause? + AS query +``` + +#### illustrate + +##### simpleColumnDefs + +Used to define the materialized view column information, if not defined, it will be automatically derived + +```sql +simpleColumnDefs +: cols+=simpleColumnDef (COMMA cols+=simpleColumnDef)* + ; + +simpleColumnDef +: colName=identifier (COMMENT comment=STRING_LITERAL)? + ; +``` + +For example, define two columns aa and bb, where the annotation for aa is "name" +```sql +CREATE MATERIALIZED VIEW mv1 +(aa comment "name",bb) +``` + +##### buildMode + +Used to define whether the materialized view is refreshed immediately after creation, default to IMMEDIATE + +IMMEDIATE:Refresh Now + +DEFERRED:Delay refresh + +```sql +buildMode +: BUILD (IMMEDIATE | DEFERRED) +; +``` + +For example, specifying the materialized view to refresh immediately + +```sql +CREATE MATERIALIZED VIEW mv1 +BUILD IMMEDIATE +``` + +##### refreshMethod + +Used to define the refresh method for materialized views, default to AUTO + +COMPLETE:Full refresh + +AUTO:Try to refresh incrementally as much as possible. If incremental refresh is not possible, refresh in full + +```sql +refreshMethod +: COMPLETE | AUTO +; +``` + +For example, specifying full refresh of materialized views +```sql +CREATE MATERIALIZED VIEW mv1 +REFRESH COMPLETE +``` + +##### refreshTrigger + +Trigger method for refreshing data in materialized views, default to MANUAL + +MANUAL:Manual refresh + +SCHEDULE:Timed refresh + +```sql +refreshTrigger +: ON MANUAL +| ON SCHEDULE refreshSchedule +; + +refreshSchedule +: EVERY INTEGER_VALUE mvRefreshUnit (STARTS STRING_LITERAL)? +; + +mvRefreshUnit +: MINUTE | HOUR | DAY | WEEK +; +``` + +For example: executed every 2 hours, starting from 21:07:09 on December 13, 2023 +```sql +CREATE MATERIALIZED VIEW mv1 +REFRESH ON SCHEDULE EVERY 2 HOUR STARTS "2023-12-13 21:07:09" +``` + +##### key +The materialized view is the DUPLICATE KEY model, therefore the specified columns are arranged in sequence + +```sql +identifierList +: LEFT_PAREN identifierSeq RIGHT_PAREN + ; + +identifierSeq +: ident+=errorCapturingIdentifier (COMMA ident+=errorCapturingIdentifier)* +; +``` + +For example, specifying k1 and k2 as sorting sequences +```sql +CREATE MATERIALIZED VIEW mv1 +KEY(k1,k2) +``` + +##### partition +There are two partition methods for materialized views. If no partition is specified, there is only one partition by default. If a partition field is specified, +it will automatically deduce which base table the field comes from and synchronize all partitions of the base table (constraint: the base table can only have one partition field and cannot allow null values) + +For example, if the base table is a range partition with a partition field of `create_time` and partitioning by day, and `partition by(ct) as select create_time as ct from t1` is specified when creating a materialized view, +then the materialized view will also be a range partition with a partition field of 'ct' and partitioning by day + +#### property +The materialized view can specify both the properties of the table and the properties unique to the materialized view. + +The properties unique to materialized views include: + +`grace_period`: Maximum delay time allowed for materialized view data during query rewriting + +`excluded_trigger_tables`: Table names ignored during data refresh, separated by commas. For example, ` table1, table2` + +`refresh_partition_num`: The number of partitions refreshed in a single insert statement, defaults to 1 + +##### query + +Create a query statement for the materialized view, and the result is the data in the materialized view + +Random functions are not supported, for example: +```sql +SELECT random() as dd,k3 FROM user +``` + +### Example + +1. Create a materialized view mv1 that refreshes immediately and then once a week, with the data source being the hive catalog + + ```sql + CREATE MATERIALIZED VIEW mv1 BUILD IMMEDIATE REFRESH COMPLETE ON SCHEDULE EVERY 1 WEEK + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ) + AS SELECT * FROM hive_catalog.db1.user; + ``` + +2. Create a materialized view with multiple table joins + + ```sql + CREATE MATERIALIZED VIEW mv1 BUILD IMMEDIATE REFRESH COMPLETE ON SCHEDULE EVERY 1 WEEK + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ) + AS select user.k1,user.k3,com.k4 from user join com on user.k1=com.k1; + ``` + +### Keywords + + CREATE, ASYNC, MATERIALIZED, VIEW + diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..a8bf6abafd1d1a --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md @@ -0,0 +1,68 @@ +--- +{ + "title": "DROP-ASYNC-MATERIALIZED-VIEW", + "language": "en" +} +--- + + + +## DROP-ASYNC-MATERIALIZED-VIEW + +### Name + +DROP ASYNC MATERIALIZED VIEW + +### Description + +This statement is used to delete asynchronous materialized views. + +syntax: + +```sql +DROP MATERIALIZED VIEW (IF EXISTS)? mvName=multipartIdentifier +``` + + +1. IF EXISTS: + If the materialized view does not exist, do not throw an error. If this keyword is not declared and the materialized view does not exist, an error will be reported. + +2. mv_name: + The name of the materialized view to be deleted. Required field. + +### Example + +1. Delete table materialized view mv1 + +```sql +DROP MATERIALIZED VIEW mv1; +``` +2.If present, delete the materialized view of the specified database + +```sql +DROP MATERIALIZED VIEW IF EXISTS db1.mv1; +``` + +### Keywords + + DROP, ASYNC, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/en/docs/sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md new file mode 100644 index 00000000000000..9b779fe9271bb3 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md @@ -0,0 +1,56 @@ +--- +{ + "title": "CANCEL-MATERIALIZED-VIEW-TASK", + "language": "en" +} +--- + + + +## CANCEL-MATERIALIZED-VIEW-TASK + +### Name + +CANCEL MATERIALIZED VIEW TASK + +### Description + +This statement is used to cancel the task of materialized views + +syntax: + +```sql +CANCEL MATERIALIZED VIEW TASK taskId=INTEGER_VALUE ON mvName=multipartIdentifier +``` + +### Example + +1. Cancel the task with id 1 in materialized view mv1 + + ```sql + CANCEL MATERIALIZED VIEW TASK 1 on mv1; + ``` + +### Keywords + + CANCEL, MATERIALIZED, VIEW, TASK + +### Best Practice + diff --git a/docs/en/docs/sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..7eec77abe38ac6 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md @@ -0,0 +1,56 @@ +--- +{ + "title": "PAUSE-MATERIALIZED-VIEW", + "language": "en" +} +--- + + + +## PAUSE-MATERIALIZED-VIEW + +### Name + +PAUSE MATERIALIZED VIEW + +### Description + +This statement is used to pause the scheduled scheduling of materialized views + +syntax: + +```sql +PAUSE MATERIALIZED VIEW JOB ON mvName=multipartIdentifier +``` + +### Example + +1. Pause scheduled scheduling of materialized view mv1 + + ```sql + PAUSE MATERIALIZED VIEW mv1; + ``` + +### Keywords + + PAUSE, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/en/docs/sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..e51424e90a8529 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md @@ -0,0 +1,72 @@ +--- +{ + "title": "REFRESH-MATERIALIZED-VIEW", + "language": "en" +} +--- + + + +## REFRESH-MATERIALIZED-VIEW + +### Name + +REFRESH MATERIALIZED VIEW + +### Description + +This statement is used to manually refresh the specified asynchronous materialized view + +syntax: + +```sql +REFRESH MATERIALIZED VIEW mvName=multipartIdentifier (partitionSpec | COMPLETE)? +``` + +Explanation: + +Asynchronous refresh of data for a materialized view + +### Example + +1. Refresh materialized view mv1 (automatically calculate the partition to be refreshed) + + ```sql + REFRESH MATERIALIZED VIEW mv1; + ``` + +2. Refresh partition named p_19950801_19950901和p_19950901_19951001 + + ```sql + REFRESH MATERIALIZED VIEW mv1 partitions(p_19950801_19950901,p_19950901_19951001); + ``` + +3. Force refresh of all materialized view data + + ```sql + REFRESH MATERIALIZED VIEW mv1 complete; + ``` + +### Keywords + + REFRESH, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/en/docs/sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..2f89fb2288de66 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md @@ -0,0 +1,56 @@ +--- +{ + "title": "RESUME-MATERIALIZED-VIEW", + "language": "en" +} +--- + + + +## RESUME-MATERIALIZED-VIEW + +### Name + +RESUME MATERIALIZED VIEW + +### Description + +This statement is used to temporarily restore the scheduled scheduling of materialized views + +syntax: + +```sql +RESUME MATERIALIZED VIEW JOB ON mvName=multipartIdentifier +``` + +### Example + +1. Timed scheduling for restoring materialized view mv1 + + ```sql + RESUME MATERIALIZED VIEW mv1; + ``` + +### Keywords + + RESUME, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/zh-CN/docs/query-acceleration/async-materialized-view.md b/docs/zh-CN/docs/query-acceleration/async-materialized-view.md new file mode 100644 index 00000000000000..15a222813c54b4 --- /dev/null +++ b/docs/zh-CN/docs/query-acceleration/async-materialized-view.md @@ -0,0 +1,216 @@ +--- +{ + "title": "异步物化视图", + "language": "zh-CN" +} +--- + + + +# 异步物化视图 + +## 物化视图的构建和维护 + +### 创建物化视图 + +准备两张表和数据 +```sql +use tpch; + +CREATE TABLE IF NOT EXISTS orders ( + o_orderkey integer not null, + o_custkey integer not null, + o_orderstatus char(1) not null, + o_totalprice decimalv3(15,2) not null, + o_orderdate date not null, + o_orderpriority char(15) not null, + o_clerk char(15) not null, + o_shippriority integer not null, + o_comment varchar(79) not null + ) + DUPLICATE KEY(o_orderkey, o_custkey) + PARTITION BY RANGE(o_orderdate)( + FROM ('2023-10-17') TO ('2023-10-20') INTERVAL 1 DAY) + DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 + PROPERTIES ("replication_num" = "1"); + +insert into orders values + (1, 1, 'ok', 99.5, '2023-10-17', 'a', 'b', 1, 'yy'), + (2, 2, 'ok', 109.2, '2023-10-18', 'c','d',2, 'mm'), + (3, 3, 'ok', 99.5, '2023-10-19', 'a', 'b', 1, 'yy'); + +CREATE TABLE IF NOT EXISTS lineitem ( + l_orderkey integer not null, + l_partkey integer not null, + l_suppkey integer not null, + l_linenumber integer not null, + l_quantity decimalv3(15,2) not null, + l_extendedprice decimalv3(15,2) not null, + l_discount decimalv3(15,2) not null, + l_tax decimalv3(15,2) not null, + l_returnflag char(1) not null, + l_linestatus char(1) not null, + l_shipdate date not null, + l_commitdate date not null, + l_receiptdate date not null, + l_shipinstruct char(25) not null, + l_shipmode char(10) not null, + l_comment varchar(44) not null + ) + DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) + PARTITION BY RANGE(l_shipdate) + (FROM ('2023-10-17') TO ('2023-10-20') INTERVAL 1 DAY) + DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 + PROPERTIES ("replication_num" = "1"); + +insert into lineitem values + (1, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy'), + (2, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-18', '2023-10-18', '2023-10-18', 'a', 'b', 'yyyyyyyyy'), + (3, 2, 3, 6, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-10-19', '2023-10-19', '2023-10-19', 'c', 'd', 'xxxxxxxxx'); +``` +创建物化视图 +```sql +CREATE MATERIALIZED VIEW mv1 + BUILD DEFERRED REFRESH AUTO ON MANUAL + partition by(l_shipdate) + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS + select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total + from lineitem + left join orders on lineitem.l_orderkey = orders.o_orderkey and l_shipdate = o_orderdate + group by + l_shipdate, + o_orderdate, + l_partkey, + l_suppkey; +``` + +具体的语法可查看[CREATE MATERIALIZED VIEW](../sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md) + +### 查看物化视图元信息 + +```sql +select * from mv_infos("database"="tpch") where Name="mv1"; +``` + +物化视图独有的特性可以通过[mv_infos()](../sql-manual/sql-functions/table-functions/mv_infos.md)查看 + +和table相关的属性,仍通过[SHOW TABLES](../sql-manual/sql-reference/Show-Statements/SHOW-TABLES.md)来查看 + +### 刷新物化视图 + +物化视图支持不同刷新策略,如定时刷新和手动刷新。也支持不同的刷新粒度,如全量刷新,分区粒度的增量刷新等。这里我们以手动刷新物化视图的部分分区为例。 + +首先查看物化视图分区列表 +```sql +SHOW PARTITIONS FROM mv1; +``` + +刷新名字为`p_20231017_20231018`的分区 +```sql +REFRESH MATERIALIZED VIEW mv1 partitions(p_20231017_20231018); +``` + +具体的语法可查看[REFRESH MATERIALIZED VIEW](../sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md) + +### 任务管理 + +每个物化视图都会默认有一个job负责刷新数据,job用来描述物化视图的刷新策略等信息,每次触发刷新,都会产生一个task, +task用来描述具体的一次刷新信息,例如刷新用的时间,刷新了哪些分区等 + +#### 查看物化视图的job + +```sql +select * from jobs("type"="mv") order by CreateTime; +``` + +具体的语法可查看[jobs("type"="mv")](../sql-manual/sql-functions/table-functions/jobs.md) + +#### 暂停物化视图job定时调度 + +```sql +PAUSE MATERIALIZED VIEW JOB ON mv1; +``` + +可以暂停物化视图的定时调度 + +具体的语法可查看[PAUSE MATERIALIZED VIEW JOB](../sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md) + +#### 恢复物化视图job定时调度 + +```sql +RESUME MATERIALIZED VIEW JOB ON mv1; +``` + +可以恢复物化视图的定时调度 + +具体的语法可查看[RESUME MATERIALIZED VIEW JOB](../sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md) + +#### 查看物化视图的task + +```sql +select * from tasks("type"="mv"); +``` + +具体的语法可查看[tasks("type"="mv")](../sql-manual/sql-functions/table-functions/tasks.md) + +#### 取消物化视图的task + +```sql +CANCEL MATERIALIZED VIEW TASK realTaskId on mv1; +``` + +可以取消本次task的运行 + +具体的语法可查看[CANCEL MATERIALIZED VIEW TASK](../sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md) + +### 修改物化视图 + +修改物化视图的属性 +```sql +ALTER MATERIALIZED VIEW mv1 set("grace_period"="3333"); +``` + +修改物化视图的名字,物化视图的刷新方式及物化视图特有的property可通过[ALTER MATERIALIZED VIEW](../sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md)来修改 + +物化视图本身也是一个 Table,所以 Table 相关的属性,例如副本数,仍通过`ALTER TABLE`相关的语法来修改。 + +### 删除物化视图 + +```sql +DROP MATERIALIZED VIEW mv1; +``` + +物化视图有专门的删除语法,不能通过drop table来删除, + +具体的语法可查看[DROP MATERIALIZED VIEW](../sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md) + +## 物化视图的使用 + +### 直接查看物化视图的数据 + +物化视图本身也是一个 Table,所以可以直接查询 + +```sql +select * FROM mv1; +``` + +### 透明改写 \ No newline at end of file diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/jobs.md b/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/jobs.md new file mode 100644 index 00000000000000..cbbe080703e8d7 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/jobs.md @@ -0,0 +1,90 @@ +--- +{ + "title": "JOBS", + "language": "zh-CN" +} +--- + + + +## `jobs` + +### Name + +jobs + +### description + +表函数,生成任务临时表,可以查看某个任务类型中的job信息。 + +该函数用于 from 子句中。 + +#### syntax + +`jobs("type"="")` + +jobs("type"="mv")表结构: +```sql +mysql> desc function jobs("type"="mv"); ++-------------------+------+------+-------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------------------+------+------+-------+---------+-------+ +| Id | TEXT | No | false | NULL | NONE | +| Name | TEXT | No | false | NULL | NONE | +| MvId | TEXT | No | false | NULL | NONE | +| MvName | TEXT | No | false | NULL | NONE | +| MvDatabaseId | TEXT | No | false | NULL | NONE | +| MvDatabaseName | TEXT | No | false | NULL | NONE | +| ExecuteType | TEXT | No | false | NULL | NONE | +| RecurringStrategy | TEXT | No | false | NULL | NONE | +| Status | TEXT | No | false | NULL | NONE | +| CreateTime | TEXT | No | false | NULL | NONE | ++-------------------+------+------+-------+---------+-------+ +10 rows in set (0.00 sec) +``` + +* Id:job id. +* Name:job名称. +* MvId:物化视图id +* MvName:物化视图名称 +* MvDatabaseId:物化视图所属db id +* MvDatabaseName:物化视图所属db名称 +* ExecuteType:执行类型 +* RecurringStrategy:循环策略 +* Status:job状态 +* CreateTime:task创建时间 + +### example + +1. 查看所有物化视图的job + +```sql +mysql> select * from jobs("type"="mv"); +``` + +2. 查看name为`inner_mtmv_75043`的job + +```sql +mysql> select * from jobs("type"="mv") where Name="inner_mtmv_75043"; +``` + +### keywords + + jobs diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/mv_infos.md b/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/mv_infos.md new file mode 100644 index 00000000000000..ee9064ded0d3a0 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/mv_infos.md @@ -0,0 +1,100 @@ +--- +{ + "title": "MV_INFOS", + "language": "zh-CN" +} +--- + + + +## `mv_infos` + +### Name + +mv_infos + +### description + +表函数,生成异步物化视图临时表,可以查看某个db中创建的异步物化视图信息。 + +该函数用于 from 子句中。 + +#### syntax + +`mv_infos("database"="")` + +mv_infos()表结构: +```sql +mysql> desc function mv_infos("database"="tpch100"); ++--------------------+---------+------+-------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+---------+------+-------+---------+-------+ +| Id | BIGINT | No | false | NULL | NONE | +| Name | TEXT | No | false | NULL | NONE | +| JobName | TEXT | No | false | NULL | NONE | +| State | TEXT | No | false | NULL | NONE | +| SchemaChangeDetail | TEXT | No | false | NULL | NONE | +| RefreshState | TEXT | No | false | NULL | NONE | +| RefreshInfo | TEXT | No | false | NULL | NONE | +| QuerySql | TEXT | No | false | NULL | NONE | +| EnvInfo | TEXT | No | false | NULL | NONE | +| MvProperties | TEXT | No | false | NULL | NONE | +| MvPartitionInfo | TEXT | No | false | NULL | NONE | +| SyncWithBaseTables | BOOLEAN | No | false | NULL | NONE | ++--------------------+---------+------+-------+---------+-------+ +12 rows in set (0.01 sec) +``` + +* Id:物化视图id +* Name:物化视图Name +* JobName:物化视图对应的job名称 +* State:物化视图状态 +* SchemaChangeDetail:物化视图State变为SchemaChange的原因 +* RefreshState:物化视图刷新状态 +* RefreshInfo:物化视图定义的刷新策略信息 +* QuerySql:物化视图定义的查询语句 +* EnvInfo:物化视图创建时的环境信息 +* MvProperties:物化视属性 +* MvPartitionInfo:物化视图的分区信息 +* SyncWithBaseTables:是否和base表数据同步,如需查看哪个分区不同步,请使用[SHOW PARTITIONS](../sql-reference/Show-Statements/SHOW-PARTITIONS.md) + +### example + +1. 查看db1下的所有物化视图 + +```sql +mysql> select * from mv_infos("database"="db1"); +``` + +2. 查看db1下的物化视图名称为mv1的物化视图 + +```sql +mysql> select * from mv_infos("database"="db1") where Name = "mv1"; +``` + +3. 查看db1下的物化视图名称为mv1的状态 + +```sql +mysql> select State from mv_infos("database"="db1") where Name = "mv1"; +``` + +### keywords + + mv, infos diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/tasks.md b/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/tasks.md new file mode 100644 index 00000000000000..0a4ee24bbb6d24 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-functions/table-functions/tasks.md @@ -0,0 +1,106 @@ +--- +{ + "title": "TASKS", + "language": "zh-CN" +} +--- + + + +## `tasks` + +### Name + +tasks + +### description + +表函数,生成任务临时表,可以查看某个任务类型中的task信息。 + +该函数用于 from 子句中。 + +#### syntax + +`tasks("type"="")` + +tasks("type"="mv")表结构: +```sql +mysql> desc function tasks("type"="mv"); ++-----------------------+------+------+-------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-----------------------+------+------+-------+---------+-------+ +| TaskId | TEXT | No | false | NULL | NONE | +| JobId | TEXT | No | false | NULL | NONE | +| JobName | TEXT | No | false | NULL | NONE | +| MvId | TEXT | No | false | NULL | NONE | +| MvName | TEXT | No | false | NULL | NONE | +| MvDatabaseId | TEXT | No | false | NULL | NONE | +| MvDatabaseName | TEXT | No | false | NULL | NONE | +| Status | TEXT | No | false | NULL | NONE | +| ErrorMsg | TEXT | No | false | NULL | NONE | +| CreateTime | TEXT | No | false | NULL | NONE | +| StartTime | TEXT | No | false | NULL | NONE | +| FinishTime | TEXT | No | false | NULL | NONE | +| DurationMs | TEXT | No | false | NULL | NONE | +| TaskContext | TEXT | No | false | NULL | NONE | +| RefreshMode | TEXT | No | false | NULL | NONE | +| NeedRefreshPartitions | TEXT | No | false | NULL | NONE | +| CompletedPartitions | TEXT | No | false | NULL | NONE | +| Progress | TEXT | No | false | NULL | NONE | ++-----------------------+------+------+-------+---------+-------+ +18 rows in set (0.00 sec) +``` + +* TaskId:task id +* JobId:job id +* JobName:job名称 +* MvId:物化视图id +* MvName:物化视图名称 +* MvDatabaseId:物化视图所属db id +* MvDatabaseName:物化视图所属db名称 +* Status:task状态 +* ErrorMsg:task失败信息 +* CreateTime:task创建时间 +* StartTime:task开始运行时间 +* FinishTime:task结束运行时间 +* DurationMs:task运行时间 +* TaskContext:task运行参数 +* RefreshMode:刷新模式 +* NeedRefreshPartitions:本次task需要刷新的分区信息 +* CompletedPartitions:本次task刷新完成的分区信息 +* Progress:task运行进度 + +### example + +1. 查看所有物化视图的task + +```sql +mysql> select * from tasks("type"="mv"); +``` + +2. 查看jobName为`inner_mtmv_75043`的所有task + +```sql +mysql> select * from tasks("type"="mv") where JobName="inner_mtmv_75043"; +``` + +### keywords + + tasks diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..0bb39ff32a9085 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-ASYNC-MATERIALIZED-VIEW.md @@ -0,0 +1,75 @@ +--- +{ + "title": "ALTER-ASYNC-MATERIALIZED-VIEW", + "language": "zh-CN" +} +--- + + + +## ALTER-ASYNC-MATERIALIZED-VIEW + +### Name + +ALTER ASYNC MATERIALIZED VIEW + +### Description + +该语句用于修改异步物化视图。 + +#### 语法 + +```sql +ALTER MATERIALIZED VIEW mvName=multipartIdentifier ((RENAME newName=identifier) + | (REFRESH (refreshMethod | refreshTrigger | refreshMethod refreshTrigger)) + | (SET LEFT_PAREN fileProperties=propertyItemList RIGHT_PAREN)) +``` + +#### 说明 + +##### RENAME + +用来更改物化视图的名字 + +例如: 将mv1的名字改为mv2 +```sql +ALTER MATERIALIZED VIEW mv1 rename mv2; +``` + +##### refreshMethod + +同[创建异步物化视图](../Create/CREATE-ASYNC-MATERIALIZED-VIEW.md) + +##### refreshTrigger + +同[创建异步物化视图](../Create/CREATE-ASYNC-MATERIALIZED-VIEW.md) + +##### SET +修改物化视图特有的property + +例如修改mv1的grace_period为3000ms +```sql +ALTER MATERIALIZED VIEW mv1 set("grace_period"="3000"); +``` + +### Keywords + + ALTER, ASYNC, MATERIALIZED, VIEW + diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..7be195589a8752 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md @@ -0,0 +1,215 @@ +--- +{ + "title": "CREATE-ASYNC-MATERIALIZED-VIEW", + "language": "zh-CN" +} +--- + + + +## CREATE-ASYNC-MATERIALIZED-VIEW + +### Name + +CREATE ASYNC MATERIALIZED VIEW + +### Description + +该语句用于创建异步物化视图。 + +#### 语法 + +```sql +CREATE MATERIALIZED VIEW (IF NOT EXISTS)? mvName=multipartIdentifier + (LEFT_PAREN cols=simpleColumnDefs RIGHT_PAREN)? buildMode? + (REFRESH refreshMethod? refreshTrigger?)? + (KEY keys=identifierList)? + (COMMENT STRING_LITERAL)? + (PARTITION BY LEFT_PAREN partitionKey = identifier RIGHT_PAREN)? + (DISTRIBUTED BY (HASH hashKeys=identifierList | RANDOM) (BUCKETS (INTEGER_VALUE | AUTO))?)? + propertyClause? + AS query +``` + +#### 说明 + +##### simpleColumnDefs + +用来定义物化视图column信息,如果不定义,将自动推导 + +```sql +simpleColumnDefs +: cols+=simpleColumnDef (COMMA cols+=simpleColumnDef)* + ; + +simpleColumnDef +: colName=identifier (COMMENT comment=STRING_LITERAL)? + ; +``` + +例如:定义两列aa和bb,其中aa的注释为"name" +```sql +CREATE MATERIALIZED VIEW mv1 +(aa comment "name",bb) +``` + +##### buildMode + +用来定义物化视图是否创建完成立即刷新,默认IMMEDIATE + +IMMEDIATE:立即刷新 + +DEFERRED:延迟刷新 + +```sql +buildMode +: BUILD (IMMEDIATE | DEFERRED) +; +``` + +例如:指定物化视图立即刷新 + +```sql +CREATE MATERIALIZED VIEW mv1 +BUILD IMMEDIATE +``` + +##### refreshMethod + +用来定义物化视图刷新方式,默认AUTO + +COMPLETE:全量刷新 + +AUTO:尽量增量刷新,如果不能增量刷新,就全量刷新 + +```sql +refreshMethod +: COMPLETE | AUTO +; +``` + +例如:指定物化视图全量刷新 +```sql +CREATE MATERIALIZED VIEW mv1 +REFRESH COMPLETE +``` + +##### refreshTrigger + +物化视图刷新数据的触发方式,默认MANUAL + +MANUAL:手动刷新 + +SCHEDULE:定时刷新 + +```sql +refreshTrigger +: ON MANUAL +| ON SCHEDULE refreshSchedule +; + +refreshSchedule +: EVERY INTEGER_VALUE mvRefreshUnit (STARTS STRING_LITERAL)? +; + +mvRefreshUnit +: MINUTE | HOUR | DAY | WEEK +; +``` + +例如:每2小时执行一次,从2023-12-13 21:07:09开始 +```sql +CREATE MATERIALIZED VIEW mv1 +REFRESH ON SCHEDULE EVERY 2 HOUR STARTS "2023-12-13 21:07:09" +``` + +##### key +物化视图为DUPLICATE KEY模型,因此指定的列为排序列 + +```sql +identifierList +: LEFT_PAREN identifierSeq RIGHT_PAREN + ; + +identifierSeq +: ident+=errorCapturingIdentifier (COMMA ident+=errorCapturingIdentifier)* +; +``` + +例如:指定k1,k2为排序列 +```sql +CREATE MATERIALIZED VIEW mv1 +KEY(k1,k2) +``` + +##### partition +物化视图有两种分区方式,如果不指定分区,默认只有一个分区,如果指定分区字段,会自动推导出字段来自哪个基表并同步基表的所有分区(限制条件:基表只能有一个分区字段且不能允许空值) + +例如:基表是range分区,分区字段为`create_time`并按天分区,创建物化视图时指定`partition by(ct) as select create_time as ct from t1` +那么物化视图也会是range分区,分区字段为`ct`,并且按天分区 + +#### property +物化视图既可以指定table的property,也可以指定物化视图特有的property。 + +物化视图特有的property包括: + +`grace_period`:查询改写时允许物化视图数据的最大延迟时间 + +`excluded_trigger_tables`:数据刷新时忽略的表名,逗号分割。例如`table1,table2` + +`refresh_partition_num`:单次insert语句刷新的分区数量,默认为1 + +##### query + +创建物化视图的查询语句,其结果即为物化视图中的数据 + +不支持随机函数,例如: +```sql +SELECT random() as dd,k3 FROM user +``` + +### Example + +1. 创建一个立即刷新,之后每周刷新一次的物化视图mv1,数据源为hive catalog + + ```sql + CREATE MATERIALIZED VIEW mv1 BUILD IMMEDIATE REFRESH COMPLETE ON SCHEDULE EVERY 1 WEEK + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ) + AS SELECT * FROM hive_catalog.db1.user; + ``` + +2. 创建一个多表join的物化视图 + + ```sql + CREATE MATERIALIZED VIEW mv1 BUILD IMMEDIATE REFRESH COMPLETE ON SCHEDULE EVERY 1 WEEK + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ) + AS select user.k1,user.k3,com.k4 from user join com on user.k1=com.k1; + ``` + +### Keywords + + CREATE, ASYNC, MATERIALIZED, VIEW + diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..49694b7309ce77 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Drop/DROP-ASYNC-MATERIALIZED-VIEW.md @@ -0,0 +1,68 @@ +--- +{ + "title": "DROP-ASYNC-MATERIALIZED-VIEW", + "language": "zh-CN" +} +--- + + + +## DROP-ASYNC-MATERIALIZED-VIEW + +### Name + +DROP ASYNC MATERIALIZED VIEW + +### Description + +该语句用于删除异步物化视图。 + +语法: + +```sql +DROP MATERIALIZED VIEW (IF EXISTS)? mvName=multipartIdentifier +``` + + +1. IF EXISTS: + 如果物化视图不存在,不要抛出错误。如果不声明此关键字,物化视图不存在则报错。 + +2. mv_name: + 待删除的物化视图的名称。必填项。 + +### Example + +1. 删除表物化视图mv1 + +```sql +DROP MATERIALIZED VIEW mv1; +``` +2.如果存在,删除指定 database 的物化视图 + +```sql +DROP MATERIALIZED VIEW IF EXISTS db1.mv1; +``` + +### Keywords + + DROP, ASYNC, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md new file mode 100644 index 00000000000000..d96b28f7912959 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/CANCEL-MATERIALIZED-VIEW-TASK.md @@ -0,0 +1,56 @@ +--- +{ + "title": "CANCEL-MATERIALIZED-VIEW-TASK", + "language": "zh-CN" +} +--- + + + +## CANCEL-MATERIALIZED-VIEW-TASK + +### Name + +CANCEL MATERIALIZED VIEW TASK + +### Description + +该语句用于取消物化视图的task + +语法: + +```sql +CANCEL MATERIALIZED VIEW TASK taskId=INTEGER_VALUE ON mvName=multipartIdentifier +``` + +### Example + +1. 取消物化视图mv1的id为1的task + + ```sql + CANCEL MATERIALIZED VIEW TASK 1 on mv1; + ``` + +### Keywords + + CANCEL, MATERIALIZED, VIEW, TASK + +### Best Practice + diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..ae5bd7bd803aac --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/PAUSE-MATERIALIZED-VIEW.md @@ -0,0 +1,56 @@ +--- +{ + "title": "PAUSE-MATERIALIZED-VIEW", + "language": "zh-CN" +} +--- + + + +## PAUSE-MATERIALIZED-VIEW + +### Name + +PAUSE MATERIALIZED VIEW + +### Description + +该语句用于暂停物化视图的定时调度 + +语法: + +```sql +PAUSE MATERIALIZED VIEW JOB ON mvName=multipartIdentifier +``` + +### Example + +1. 暂停物化视图mv1的定时调度 + + ```sql + PAUSE MATERIALIZED VIEW mv1; + ``` + +### Keywords + + PAUSE, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..b719d4aefe6ffd --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/REFRESH-MATERIALIZED-VIEW.md @@ -0,0 +1,72 @@ +--- +{ + "title": "REFRESH-MATERIALIZED-VIEW", + "language": "zh-CN" +} +--- + + + +## REFRESH-MATERIALIZED-VIEW + +### Name + +REFRESH MATERIALIZED VIEW + +### Description + +该语句用于手动刷新指定的异步物化视图 + +语法: + +```sql +REFRESH MATERIALIZED VIEW mvName=multipartIdentifier (partitionSpec | COMPLETE)? +``` + +说明: + +异步刷新某个物化视图的数据 + +### Example + +1. 刷新物化视图mv1(自动计算要刷新的分区) + + ```sql + REFRESH MATERIALIZED VIEW mv1; + ``` + +2. 刷新名字为p_19950801_19950901和p_19950901_19951001的分区 + + ```sql + REFRESH MATERIALIZED VIEW mv1 partitions(p_19950801_19950901,p_19950901_19951001); + ``` + +3. 强制刷新物化视图全部数据 + + ```sql + REFRESH MATERIALIZED VIEW mv1 complete; + ``` + +### Keywords + + REFRESH, MATERIALIZED, VIEW + +### Best Practice + diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md new file mode 100644 index 00000000000000..2d772578b67deb --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/RESUME-MATERIALIZED-VIEW.md @@ -0,0 +1,56 @@ +--- +{ + "title": "RESUME-MATERIALIZED-VIEW", + "language": "zh-CN" +} +--- + + + +## RESUME-MATERIALIZED-VIEW + +### Name + +RESUME MATERIALIZED VIEW + +### Description + +该语句用于暂恢复物化视图的定时调度 + +语法: + +```sql +RESUME MATERIALIZED VIEW JOB ON mvName=multipartIdentifier +``` + +### Example + +1. 恢复物化视图mv1的定时调度 + + ```sql + RESUME MATERIALIZED VIEW mv1; + ``` + +### Keywords + + RESUME, MATERIALIZED, VIEW + +### Best Practice +