Files
doris/docs/en
pengxiangyu 7592f52d2e [Feature][Insert] Add transaction for the operation of insert #6244 (#6245)
## Proposed changes
Add transaction for the operation of insert. It will cost less time than non-transaction(it will cost 1/1000 time) when you want to insert a amount of rows.
### Syntax

```
BEGIN [ WITH LABEL label];
INSERT INTO table_name ...
[COMMIT | ROLLBACK];
```

### Example
commit a transaction:
```
begin;
insert into Tbl values(11, 22, 33);
commit;
```
rollback a transaction:
```
begin;
insert into Tbl values(11, 22, 33);
rollback;
```
commit a transaction with label:
```
begin with label test_label;
insert into Tbl values(11, 22, 33);
commit;
```

### Description
```
begin:  begin a transaction, the next insert will execute in the transaction until commit/rollback;
commit:  commit the transaction, the data in the transaction will be inserted into the table;
rollback:  abort the transaction, nothing will be inserted into the table;
```
### The main realization principle:
```
1. begin a transaction in the session. next sql is executed in the transaction;
2. insert sql will be parser and get the database name and table name, they will be used to select a be and create a pipe to accept data;
3. all inserted values will be sent to the be and write into the pipe;
4. a thread will get the data from the pipe, then write them to disk;
5. commit will complete this transaction and make these data visible;
6. rollback will abort this transaction
```

### Some restrictions on the use of update syntax.
1. Only ```insert``` can be called in a transaction.
2. If something error happened, ```commit``` will not succeed, it will ```rollback``` directly;
3. By default, if part of insert in the transaction is invalid, ```commit``` will only insert the other correct data into the table.
4. If you need ```commit``` return failed when any insert in the transaction is invalid, you need execute ```set enable_insert_strict = true``` before ```begin```.
2021-07-21 10:54:11 +08:00
..

home, heroImage, heroBgImage, heroText, tagline, structure, features, cases, actionText, actionLink
home heroImage heroBgImage heroText tagline structure features cases actionText actionLink
true /images/home/banner-stats.png /images/home/hero-bg.png
Welcome to
Apache Doris
A fast MPP database for all modern analytics on big data.
title subTitle descriptions image actionText actionLink
Apache Doris
Apache Doris is a modern MPP analytical database product. It can provide sub-second queries and efficient real-time data analysis. With it's distributed architecture, up to 10PB level datasets will be well supported and easy to operate.
Apache Doris can meet various data analysis demands, including history data reports, real-time data analysis, interactive data analysis, and exploratory data analysis. Make your data analysis easier!
/images/home/structure-fresh.png Learn More /en/getting-started/basic-usage
title subTitle list
Apache Doris Core Features
title icon
Modern MPP architecture /images/home/struct.png
title icon
Getting result of a query within one second /images/home/clock.png
title icon
Support standard SQL language, compatible with MySQL protocol /images/home/sql.png
title icon
Vectorized SQL executor /images/home/program.png
title icon
Effective data model for aggregation /images/home/aggr.png
title icon
Rollup, novel pre-computation mechanism /images/home/rollup.png
title icon
High performance, high availability, high reliability /images/home/cpu.png
title icon
easy for operation, Elastic data warehouse for big data /images/home/dev.png
title subTitle list
Apache Doris Users
logo alt
/images/home/logo-meituan.png 美团
logo alt
/images/home/logo-xiaomi.png 小米
logo alt
/images/home/logo-jd.png 京东
logo alt
/images/home/logo-huawei.png 华为
logo alt
/images/home/logo-baidu.png 百度
logo alt
/images/home/logo-weibo.png 新浪微博
logo alt
/images/home/logo-zuoyebang.png 作业帮
logo alt
/images/home/logo-vipkid.png Vipkid
logo alt
/images/home/logo-360.png 360
logo alt
/images/home/logo-shopee.png Shopee
logo alt
/images/home/logo-tantan.png 探探
logo alt
/images/home/logo-kuaishou.png 快手
logo alt
/images/home/logo-sohu.png 搜狐
logo alt
/images/home/logo-yidian.png 一点资讯
logo alt
/images/home/logo-dingdong.png 叮咚买菜
logo alt
/images/home/logo-youdao.png 有道
Quick Start → /en/installing/compilation