From 4d93fac3ac354f45faad1d23eb99764b25491ac8 Mon Sep 17 00:00:00 2001 From: EsoragotoSpirit Date: Wed, 25 Dec 2024 17:58:19 +0800 Subject: [PATCH 1/2] [Doc] V3.4 - Dynamic Overwrite Signed-off-by: EsoragotoSpirit --- docs/en/loading/InsertInto.md | 34 +++++++++++++++++++ docs/en/sql-reference/System_variable.md | 8 +++++ .../loading_unloading/INSERT.md | 32 +++++++++++++++++ docs/zh/loading/InsertInto.md | 34 +++++++++++++++++++ docs/zh/sql-reference/System_variable.md | 9 +++++ .../loading_unloading/INSERT.md | 32 +++++++++++++++++ 6 files changed, 149 insertions(+) diff --git a/docs/en/loading/InsertInto.md b/docs/en/loading/InsertInto.md index d9301f008c1cb..ebeae7770113a 100644 --- a/docs/en/loading/InsertInto.md +++ b/docs/en/loading/InsertInto.md @@ -20,6 +20,8 @@ StarRocks v2.4 further supports overwriting data into a table by using INSERT OV > > If you need to verify the data before overwriting it, instead of using INSERT OVERWRITE, you can follow the above procedures to overwrite your data and verify it before swapping the partitions. +From v3.4.0 onwards, StarRocks supports a new semantic - Dynamic Overwrite for INSERT OVERWRITE with partitioned tables. For more information, see [Dynamic Overwrite](#dynamic-overwrite). + ## Precautions - You can cancel a synchronous INSERT transaction only by pressing the **Ctrl** and **C** keys from your MySQL client. @@ -356,6 +358,38 @@ WITH LABEL insert_load_wikipedia_ow_3 SELECT event_time, channel FROM source_wiki_edit; ``` +### Dynamic Overwrite + +From v3.4.0 onwards, StarRocks supports a new semantic - Dynamic Overwrite for INSERT OVERWRITE with partitioned tables. + +Currently, the default behavior of INSERT OVERWRITE is as follows: + +- When overwriting a partitioned table as a whole (that is, without specifying the PARTITION clause), new data records will replace the data in their corresponding partitions. If there are partitions that are not involved, they will be truncated while the others are overwritten. +- When overwriting an empty partitioned table (that is, with no partitions in it) and specifying the PARTITION clause, the system returns an error `ERROR 1064 (HY000): Getting analyzing error. Detail message: Unknown partition 'xxx' in table 'yyy'`. +- When overwriting a partitioned table and specifying a non-existent partition in the PARTITION clause, the system returns an error `ERROR 1064 (HY000): Getting analyzing error. Detail message: Unknown partition 'xxx' in table 'yyy'`. +- When overwriting a partitioned table with data records that do not match any of the specified partitions in the PARTITION clause, the system either returns an error `ERROR 1064 (HY000): Insert has filtered data in strict mode` (if the strict mode is enabled) or filters the unqualified data records (if the strict mode is disabled). + +The behavior of the new Dynamic Overwrite semantic is much different: + +When overwriting a partitioned table as a whole, new data records will replace the data in their corresponding partitions. If there are partitions that are not involved, they will be left alone, instead of being truncated or deleted. And if there are new data records correspond a non-existent partition, the system will create the partition. + +The Dynamic Overwrite semantic is disabled by default. To enable it, you need to set the system variable `dynamic_overwrite` to `true`. + +Enable Dynamic Overwrite in the current session: + +```SQL +SET dynamic_overwrite = true; +``` + +You can also set it in the hint of the INSERT OVERWRITE statement to allow it take effect for the statement only:. + +Example: + +```SQL +INSERT OVERWRITE /*+set_var(set dynamic_overwrite = false)*/ insert_wiki_edit +SELECT * FROM source_wiki_edit; +``` + ## Insert data into a table with generated columns A generated column is a special column whose value is derived from a pre-defined expression or evaluation based on other columns. Generated columns are especially useful when your query requests involve evaluations of expensive expressions, for example, querying a certain field from a JSON value, or calculating ARRAY data. StarRocks evaluates the expression and stores the results in the generated columns while data is being loaded into the table, thereby avoiding the expression evaluation during queries and improving the query performance. diff --git a/docs/en/sql-reference/System_variable.md b/docs/en/sql-reference/System_variable.md index fb029b324e5fc..6a29fe92a64a0 100644 --- a/docs/en/sql-reference/System_variable.md +++ b/docs/en/sql-reference/System_variable.md @@ -373,6 +373,14 @@ Used to enable the streaming pre-aggregations. The default value is `false`, mea Used for MySQL client compatibility. No practical usage. +### dynamic_overwrite + +* **Description**: Whether to enable the [Dynamic Overwrite](./sql-statements/loading_unloading/INSERT.md#dynamic-overwrite) semantic for INSERT OVERWRITE with partitioned tables. Valid values: + * `true`: Enables Dynamic Overwrite. + * `false`: Disables Dynamic Overwrite and uses the default semantic. +* **Default**: false +* **Introduced in**: v3.4.0 +