## 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```.
This commit is contained in:
48
be/src/exec/plain_binary_line_reader.cpp
Normal file
48
be/src/exec/plain_binary_line_reader.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "exec/plain_binary_line_reader.h"
|
||||
|
||||
#include "common/status.h"
|
||||
#include "exec/file_reader.h"
|
||||
|
||||
namespace doris {
|
||||
|
||||
PlainBinaryLineReader::PlainBinaryLineReader(FileReader* file_reader)
|
||||
: _file_reader(file_reader) {
|
||||
}
|
||||
|
||||
PlainBinaryLineReader::~PlainBinaryLineReader() {
|
||||
close();
|
||||
}
|
||||
|
||||
void PlainBinaryLineReader::close() {
|
||||
}
|
||||
|
||||
Status PlainBinaryLineReader::read_line(const uint8_t** ptr, size_t* size, bool* eof) {
|
||||
std::unique_ptr<uint8_t[]> file_buf;
|
||||
int64_t read_size = 0;
|
||||
RETURN_IF_ERROR(_file_reader->read_one_message(&file_buf, &read_size));
|
||||
*ptr = file_buf.release();
|
||||
*size = read_size;
|
||||
if (read_size == 0) {
|
||||
*eof = true;
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
} // namespace doris
|
||||
Reference in New Issue
Block a user