forked from infiniflow/infinity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphysical_delete.cpp
69 lines (59 loc) · 2.39 KB
/
physical_delete.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright(C) 2023 InfiniFlow, Inc. All rights reserved.
//
// Licensed 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
//
// https://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.
module;
#include <string>
import stl;
import query_context;
import operator_state;
import physical_operator;
import physical_operator_type;
import query_context;
// import data_table;
import operator_state;
import logical_type;
import data_block;
import column_vector;
import internal_types;
module physical_delete;
namespace infinity {
void PhysicalDelete::Init() {}
bool PhysicalDelete::Execute(QueryContext *query_context, OperatorState *operator_state) {
OperatorState* prev_op_state = operator_state->prev_op_state_;
SizeT data_block_count = prev_op_state->data_block_array_.size();
for(SizeT block_idx = 0; block_idx < data_block_count; ++ block_idx) {
DataBlock *input_data_block_ptr = prev_op_state->data_block_array_[block_idx].get();
auto txn = query_context->GetTxn();
Vector<RowID> row_ids;
for (SizeT i = 0; i < input_data_block_ptr->column_count(); i++) {
SharedPtr<ColumnVector> column_vector = input_data_block_ptr->column_vectors[i];
if (column_vector->data_type()->type() == LogicalType::kRowID) {
row_ids.resize(column_vector->Size());
std::memcpy(row_ids.data(), column_vector->data(), column_vector->Size() * sizeof(RowID));
break;
}
}
if (!row_ids.empty()) {
txn->Delete(table_entry_ptr_, row_ids); // TODO: segment id in `row_ids` is fixed.
DeleteOperatorState* delete_operator_state = static_cast<DeleteOperatorState*>(operator_state);
++ delete_operator_state->count_;
delete_operator_state->sum_ += row_ids.size();
}
}
prev_op_state->data_block_array_.clear();
if (prev_op_state->Complete()) {
operator_state->SetComplete();
}
return true;
}
} // namespace infinity