Files
doris/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/UPDATE.md
EmmyMiao87 b3a52a05d5 [Update] Support update syntax (#6230)
[Update] Support update syntax

    The current update syntax only supports updating the filtered data of a single table.

    Syntax:

     * UPDATE table_reference
     *     SET assignment_list
     *     [WHERE where_condition]
     *
     * value:
     *     {expr}
     *
     * assignment:
     *     col_name = value
     *
     * assignment_list:
     *     assignment [, assignment] ...

    Example
    Update unique_table
         set v1=1
         where k1=1

    New Frontend Config: enable_concurrent_update
    This configuration is used to control whether multi update stmt can be executed concurrently in one table.
    Default value is false which means A table can only have one update task being executed at the same time.
    If users want to update the same table concurrently,
      they need to modify the configuration value to true and restart the master frontend.
    Concurrent updates may cause write conflicts, the result is uncertain, please be careful.

    The main realization principle:
    1. Read the rows that meet the conditions according to the conditions set by where clause.
    2. Modify the result of the row according to the set clause.
    3. Write the modified row back to the table.

    Some restrictions on the use of update syntax.
    1. Only the unique table can be updated
    2. Only the value column of the unique table can be updated
    3. The where clause currently only supports single tables

    Possible risks:
    1. Since the current implementation method is a row update,
         when the same table is updated concurrently, there may be concurrency conflicts which may cause the incorrect result.
    2. Once the conditions of the where clause are unsatisfactory, it is likely to cause a full table scan and affect query performance.
       Please pay attention to whether the column in the where clause can match the index when using it.

    [Docs][Update] Add update document and sql-reference

    Fixed #6229
2021-07-27 13:38:15 +08:00

1.9 KiB

title, language
title language
UPDATE zh-CN

UPDATE

description

Syntax

UPDATE table_name 
    SET assignment_list
    WHERE expression

value:
    {expr | DEFAULT}

assignment:
    col_name = value

assignment_list:
    assignment [, assignment] ...

Parameters

  • table_name: 待更新数据的目标表。可以是 'db_name.table_name' 形式
  • assignment_list: 待更新的目标列,形如 'col_name = value, col_name = value' 格式
  • where expression: 期望更新的条件,一个返回 true 或者 false 的表达式即可

Note

当前 UPDATE 语句仅支持在 Unique 模型上的行更新,存在并发更新导致的数据冲突可能。 目前 Doris 并不处理这类问题,需要用户从业务侧规避这类问题。

example

test 表是一个 unique 模型的表,包含: k1, k2, v1, v2 四个列。其中 k1, k2 是 key,v1, v2 是value,聚合方式是 Replace。

  1. 将 'test' 表中满足条件 k1 =1 , k2 =2 的 v1 列更新为 1
UPDATE test SET v1 = 1 WHERE k1=1 and k2=2;
  1. 将 'test' 表中 k1=1 的列的 v1 列自增1
UPDATE test SET v1 = v1+1 WHERE k1=1;

keyword

UPDATE