1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/storage/table/append_state.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/common.hpp"
12#include "duckdb/storage/storage_lock.hpp"
13#include "duckdb/storage/buffer/buffer_handle.hpp"
14#include "duckdb/common/vector.hpp"
15#include "duckdb/function/compression_function.hpp"
16#include "duckdb/transaction/transaction_data.hpp"
17
18namespace duckdb {
19class ColumnSegment;
20class DataTable;
21class LocalTableStorage;
22class RowGroup;
23class UpdateSegment;
24
25struct TableAppendState;
26
27struct ColumnAppendState {
28 //! The current segment of the append
29 ColumnSegment *current;
30 //! Child append states
31 vector<ColumnAppendState> child_appends;
32 //! The write lock that is held by the append
33 unique_ptr<StorageLockKey> lock;
34 //! The compression append state
35 unique_ptr<CompressionAppendState> append_state;
36};
37
38struct RowGroupAppendState {
39 RowGroupAppendState(TableAppendState &parent_p) : parent(parent_p) {
40 }
41
42 //! The parent append state
43 TableAppendState &parent;
44 //! The current row_group we are appending to
45 RowGroup *row_group;
46 //! The column append states
47 unsafe_unique_array<ColumnAppendState> states;
48 //! Offset within the row_group
49 idx_t offset_in_row_group;
50};
51
52struct IndexLock {
53 unique_lock<mutex> index_lock;
54};
55
56struct TableAppendState {
57 TableAppendState();
58 ~TableAppendState();
59
60 RowGroupAppendState row_group_append_state;
61 unique_lock<mutex> append_lock;
62 row_t row_start;
63 row_t current_row;
64 //! The total number of rows appended by the append operation
65 idx_t total_append_count;
66 //! The first row-group that has been appended to
67 RowGroup *start_row_group;
68 //! The transaction data
69 TransactionData transaction;
70 //! The remaining append count, only if the append count is known beforehand
71 idx_t remaining;
72};
73
74struct LocalAppendState {
75 TableAppendState append_state;
76 LocalTableStorage *storage;
77};
78
79} // namespace duckdb
80