Skip to content

[Update] Support update syntax#6230

Merged
morningman merged 5 commits intoapache:masterfrom
EmmyMiao87:update
Jul 27, 2021
Merged

[Update] Support update syntax#6230
morningman merged 5 commits intoapache:masterfrom
EmmyMiao87:update

Conversation

@EmmyMiao87
Copy link
Contributor

Proposed changes

[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

Types of changes

What types of changes does your code introduce to Doris?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Code refactor (Modify the code structure, format the code, etc...)
  • Optimization. Including functional usability improvements and performance improvements.
  • Dependency. Such as changes related to third-party components.
  • Other.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have created an issue on (Fix Support update in unique data model #6229) and described the bug/feature there in detail
  • Compiling and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • If these changes need document changes, I have updated the document
  • Any dependent changes have been merged

@EmmyMiao87 EmmyMiao87 added area/update Issues or PRS related to update kind/feature Categorizes issue or PR as related to a new feature. labels Jul 14, 2021
@morningman morningman added the api-review Categorizes an issue or PR as actively needing an API review. label Jul 17, 2021
// get all specified partition ids.
// if no partition specified, return all partitions
// if no partition specified, return null
private List<Long> getAllPartitionIds() throws DdlException, AnalysisException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You change it to return null, but don' t change the caller to handle null? Such as in StreamLoadPlanner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unified handle this in the OlapTableSink.


// update stmt
update_stmt ::=
KW_UPDATE table_name:tbl KW_SET expr_list:setExprs where_clause:whereClause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add KW_UPDATE

morningman
morningman previously approved these changes Jul 20, 2021
Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morningman morningman added the approved Indicates a PR has been approved by one committer. label Jul 20, 2021
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 apache#6229
@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@morningman morningman merged commit b3a52a0 into apache:master Jul 27, 2021
@morningman morningman mentioned this pull request Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by one committer. area/update Issues or PRS related to update kind/feature Categorizes issue or PR as related to a new feature. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support update in unique data model

2 participants