1 | #include "duckdb/storage/table/transient_segment.hpp" |
2 | #include "duckdb/common/types/null_value.hpp" |
3 | #include "duckdb/common/types/vector.hpp" |
4 | #include "duckdb/common/vector_operations/vector_operations.hpp" |
5 | #include "duckdb/storage/numeric_segment.hpp" |
6 | #include "duckdb/storage/string_segment.hpp" |
7 | #include "duckdb/storage/table/append_state.hpp" |
8 | |
9 | using namespace duckdb; |
10 | using namespace std; |
11 | |
12 | TransientSegment::TransientSegment(BufferManager &manager, TypeId type, idx_t start) |
13 | : ColumnSegment(type, ColumnSegmentType::TRANSIENT, start), manager(manager) { |
14 | if (type == TypeId::VARCHAR) { |
15 | data = make_unique<StringSegment>(manager, start); |
16 | } else { |
17 | data = make_unique<NumericSegment>(manager, type, start); |
18 | } |
19 | } |
20 | |
21 | void TransientSegment::InitializeScan(ColumnScanState &state) { |
22 | data->InitializeScan(state); |
23 | } |
24 | |
25 | void TransientSegment::Scan(Transaction &transaction, ColumnScanState &state, idx_t vector_index, Vector &result) { |
26 | data->Scan(transaction, state, vector_index, result); |
27 | } |
28 | |
29 | void TransientSegment::FilterScan(Transaction &transaction, ColumnScanState &state, Vector &result, |
30 | SelectionVector &sel, idx_t &approved_tuple_count) { |
31 | data->FilterScan(transaction, state, result, sel, approved_tuple_count); |
32 | } |
33 | |
34 | void TransientSegment::IndexScan(ColumnScanState &state, Vector &result) { |
35 | data->IndexScan(state, state.vector_index, result); |
36 | } |
37 | |
38 | void TransientSegment::Select(Transaction &transaction, ColumnScanState &state, Vector &result, SelectionVector &sel, |
39 | idx_t &approved_tuple_count, vector<TableFilter> &tableFilter) { |
40 | return data->Select(transaction, result, tableFilter, sel, approved_tuple_count, state); |
41 | } |
42 | |
43 | void TransientSegment::Fetch(ColumnScanState &state, idx_t vector_index, Vector &result) { |
44 | data->Fetch(state, vector_index, result); |
45 | } |
46 | |
47 | void TransientSegment::FetchRow(ColumnFetchState &state, Transaction &transaction, row_t row_id, Vector &result, |
48 | idx_t result_idx) { |
49 | data->FetchRow(state, transaction, row_id - this->start, result, result_idx); |
50 | } |
51 | |
52 | void TransientSegment::Update(ColumnData &column_data, Transaction &transaction, Vector &updates, row_t *ids, |
53 | idx_t count) { |
54 | data->Update(column_data, stats, transaction, updates, ids, count, this->start); |
55 | } |
56 | |
57 | void TransientSegment::InitializeAppend(ColumnAppendState &state) { |
58 | state.lock = data->lock.GetExclusiveLock(); |
59 | } |
60 | |
61 | idx_t TransientSegment::Append(ColumnAppendState &state, Vector &append_data, idx_t offset, idx_t count) { |
62 | idx_t appended = data->Append(stats, append_data, offset, count); |
63 | this->count += appended; |
64 | return appended; |
65 | } |
66 | |
67 | void TransientSegment::RevertAppend(idx_t start_row) { |
68 | data->tuple_count = start_row - this->start; |
69 | this->count = start_row - this->start; |
70 | } |
71 | |