duckdb 0.7.2-dev2233.0 → 0.7.2-dev2320.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +1 -0
- package/package.json +1 -1
- package/src/duckdb/src/catalog/catalog.cpp +18 -17
- package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +0 -4
- package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +0 -4
- package/src/duckdb/src/catalog/catalog_set.cpp +3 -3
- package/src/duckdb/src/common/adbc/adbc.cpp +441 -0
- package/src/duckdb/src/common/adbc/driver_manager.cpp +749 -0
- package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +1 -1
- package/src/duckdb/src/common/tree_renderer.cpp +3 -3
- package/src/duckdb/src/common/types/conflict_manager.cpp +2 -1
- package/src/duckdb/src/execution/column_binding_resolver.cpp +1 -1
- package/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp +1 -1
- package/src/duckdb/src/execution/operator/filter/physical_filter.cpp +2 -2
- package/src/duckdb/src/execution/operator/helper/physical_execute.cpp +2 -2
- package/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp +5 -5
- package/src/duckdb/src/execution/operator/join/physical_cross_product.cpp +1 -1
- package/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +11 -10
- package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +3 -3
- package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +9 -9
- package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +4 -4
- package/src/duckdb/src/execution/operator/join/physical_join.cpp +7 -7
- package/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp +3 -3
- package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +3 -3
- package/src/duckdb/src/execution/operator/join/physical_positional_join.cpp +2 -2
- package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +8 -9
- package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +20 -19
- package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +3 -3
- package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +25 -24
- package/src/duckdb/src/execution/operator/persistent/physical_update.cpp +1 -1
- package/src/duckdb/src/execution/operator/projection/physical_projection.cpp +2 -2
- package/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp +12 -6
- package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +10 -11
- package/src/duckdb/src/execution/operator/set/physical_union.cpp +2 -2
- package/src/duckdb/src/execution/physical_operator.cpp +13 -13
- package/src/duckdb/src/execution/physical_plan/plan_column_data_get.cpp +2 -4
- package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +5 -5
- package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +3 -3
- package/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp +6 -7
- package/src/duckdb/src/execution/physical_plan/plan_explain.cpp +2 -4
- package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +2 -2
- package/src/duckdb/src/execution/physical_plan/plan_show_select.cpp +2 -4
- package/src/duckdb/src/execution/physical_plan/plan_update.cpp +3 -3
- package/src/duckdb/src/function/compression_config.cpp +9 -9
- package/src/duckdb/src/function/scalar/date/strftime.cpp +1 -1
- package/src/duckdb/src/function/table/copy_csv.cpp +5 -0
- package/src/duckdb/src/function/table/pragma_detailed_profiling_output.cpp +6 -5
- package/src/duckdb/src/function/table/pragma_last_profiling_output.cpp +7 -5
- package/src/duckdb/src/function/table/system/duckdb_databases.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_extensions.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_keywords.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_settings.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_tables.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_temporary_files.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_types.cpp +1 -1
- package/src/duckdb/src/function/table/system/pragma_collations.cpp +1 -1
- package/src/duckdb/src/function/table/system/pragma_database_size.cpp +1 -1
- package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +5 -5
- package/src/duckdb/src/function/table/system/pragma_table_info.cpp +1 -1
- package/src/duckdb/src/function/table/system/test_all_types.cpp +1 -1
- package/src/duckdb/src/function/table/table_scan.cpp +3 -4
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -3
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +1 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -2
- package/src/duckdb/src/include/duckdb/common/adbc/adbc-init.hpp +37 -0
- package/src/duckdb/src/include/duckdb/common/adbc/adbc.h +1088 -0
- package/src/duckdb/src/include/duckdb/common/adbc/adbc.hpp +85 -0
- package/src/duckdb/src/include/duckdb/common/adbc/driver_manager.h +84 -0
- package/src/duckdb/src/include/duckdb/common/helper.hpp +3 -0
- package/src/duckdb/src/include/duckdb/common/types/conflict_manager.hpp +3 -2
- package/src/duckdb/src/include/duckdb/common/types.hpp +0 -1
- package/src/duckdb/src/include/duckdb/execution/executor.hpp +7 -7
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_result_collector.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp +3 -3
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_index_join.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_join.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +2 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_export.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_column_data_scan.hpp +3 -4
- package/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/set/physical_union.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/physical_operator.hpp +3 -3
- package/src/duckdb/src/include/duckdb/execution/physical_operator_states.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/cast/cast_function_set.hpp +1 -1
- package/src/duckdb/src/include/duckdb/main/config.hpp +2 -2
- package/src/duckdb/src/include/duckdb/main/query_profiler.hpp +10 -9
- package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +4 -4
- package/src/duckdb/src/include/duckdb/parallel/pipeline.hpp +18 -17
- package/src/duckdb/src/include/duckdb/parallel/pipeline_executor.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +14 -17
- package/src/duckdb/src/include/duckdb/planner/binder.hpp +6 -6
- package/src/duckdb/src/include/duckdb/planner/expression_binder/index_binder.hpp +4 -4
- package/src/duckdb/src/include/duckdb/planner/expression_binder/where_binder.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_create.hpp +3 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_create_table.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_delete.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_insert.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_update.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/parsed_data/bound_create_function_info.hpp +3 -2
- package/src/duckdb/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp +3 -2
- package/src/duckdb/src/include/duckdb/planner/table_binding.hpp +6 -5
- package/src/duckdb/src/include/duckdb/planner/tableref/bound_basetableref.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_compress.hpp +3 -7
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_compress.hpp +3 -7
- package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/column_data_checkpointer.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +4 -4
- package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +3 -3
- package/src/duckdb/src/include/duckdb/transaction/cleanup_state.hpp +3 -3
- package/src/duckdb/src/include/duckdb/transaction/commit_state.hpp +5 -5
- package/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp +3 -3
- package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +31 -30
- package/src/duckdb/src/include/duckdb/transaction/transaction_data.hpp +2 -1
- package/src/duckdb/src/include/duckdb/transaction/undo_buffer.hpp +1 -1
- package/src/duckdb/src/main/client_context.cpp +1 -1
- package/src/duckdb/src/main/query_profiler.cpp +24 -22
- package/src/duckdb/src/parallel/executor.cpp +55 -49
- package/src/duckdb/src/parallel/meta_pipeline.cpp +5 -5
- package/src/duckdb/src/parallel/pipeline.cpp +43 -26
- package/src/duckdb/src/parallel/pipeline_executor.cpp +22 -22
- package/src/duckdb/src/planner/bind_context.cpp +67 -71
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +6 -7
- package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +6 -8
- package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +3 -4
- package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +17 -18
- package/src/duckdb/src/planner/binder/statement/bind_update.cpp +16 -17
- package/src/duckdb/src/planner/binder/statement/bind_vacuum.cpp +6 -5
- package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +9 -9
- package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +20 -18
- package/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp +1 -1
- package/src/duckdb/src/planner/binder.cpp +4 -4
- package/src/duckdb/src/planner/expression_binder/index_binder.cpp +2 -1
- package/src/duckdb/src/planner/expression_binder/where_binder.cpp +3 -2
- package/src/duckdb/src/planner/operator/logical_create_table.cpp +1 -1
- package/src/duckdb/src/planner/operator/logical_delete.cpp +5 -5
- package/src/duckdb/src/planner/operator/logical_insert.cpp +6 -7
- package/src/duckdb/src/planner/operator/logical_update.cpp +6 -7
- package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +4 -5
- package/src/duckdb/src/planner/table_binding.cpp +6 -5
- package/src/duckdb/src/storage/compression/bitpacking.cpp +5 -6
- package/src/duckdb/src/storage/compression/dictionary_compression.cpp +5 -6
- package/src/duckdb/src/storage/compression/fsst.cpp +3 -5
- package/src/duckdb/src/storage/compression/rle.cpp +4 -6
- package/src/duckdb/src/storage/data_table.cpp +27 -28
- package/src/duckdb/src/storage/local_storage.cpp +70 -68
- package/src/duckdb/src/storage/storage_manager.cpp +12 -13
- package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +2 -2
- package/src/duckdb/src/storage/table/column_data.cpp +2 -2
- package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +18 -6
- package/src/duckdb/src/storage/table/column_segment.cpp +23 -24
- package/src/duckdb/src/storage/table/row_group.cpp +3 -3
- package/src/duckdb/src/storage/table/row_group_collection.cpp +1 -1
- package/src/duckdb/src/storage/table/update_segment.cpp +15 -15
- package/src/duckdb/src/storage/wal_replay.cpp +1 -1
- package/src/duckdb/src/transaction/cleanup_state.cpp +10 -10
- package/src/duckdb/src/transaction/commit_state.cpp +19 -19
- package/src/duckdb/src/transaction/duck_transaction.cpp +7 -7
- package/src/duckdb/src/transaction/rollback_state.cpp +1 -1
- package/src/duckdb/src/transaction/undo_buffer.cpp +2 -1
- package/src/duckdb/ub_src_common_adbc.cpp +4 -0
- package/src/duckdb/src/include/duckdb/common/single_thread_ptr.hpp +0 -185
@@ -20,7 +20,7 @@ unique_ptr<ColumnSegment> ColumnSegment::CreatePersistentSegment(DatabaseInstanc
|
|
20
20
|
CompressionType compression_type,
|
21
21
|
BaseStatistics statistics) {
|
22
22
|
auto &config = DBConfig::GetConfig(db);
|
23
|
-
CompressionFunction
|
23
|
+
optional_ptr<CompressionFunction> function;
|
24
24
|
shared_ptr<BlockHandle> block;
|
25
25
|
if (block_id == INVALID_BLOCK) {
|
26
26
|
// constant segment, no need to allocate an actual block
|
@@ -30,7 +30,7 @@ unique_ptr<ColumnSegment> ColumnSegment::CreatePersistentSegment(DatabaseInstanc
|
|
30
30
|
block = block_manager.RegisterBlock(block_id);
|
31
31
|
}
|
32
32
|
auto segment_size = Storage::BLOCK_SIZE;
|
33
|
-
return make_uniq<ColumnSegment>(db, std::move(block), type, ColumnSegmentType::PERSISTENT, start, count, function,
|
33
|
+
return make_uniq<ColumnSegment>(db, std::move(block), type, ColumnSegmentType::PERSISTENT, start, count, *function,
|
34
34
|
std::move(statistics), block_id, offset, segment_size);
|
35
35
|
}
|
36
36
|
|
@@ -46,7 +46,7 @@ unique_ptr<ColumnSegment> ColumnSegment::CreateTransientSegment(DatabaseInstance
|
|
46
46
|
} else {
|
47
47
|
buffer_manager.Allocate(segment_size, false, &block);
|
48
48
|
}
|
49
|
-
return make_uniq<ColumnSegment>(db, std::move(block), type, ColumnSegmentType::TRANSIENT, start, 0, function,
|
49
|
+
return make_uniq<ColumnSegment>(db, std::move(block), type, ColumnSegmentType::TRANSIENT, start, 0, *function,
|
50
50
|
BaseStatistics::CreateEmpty(type), INVALID_BLOCK, 0, segment_size);
|
51
51
|
}
|
52
52
|
|
@@ -55,15 +55,14 @@ unique_ptr<ColumnSegment> ColumnSegment::CreateSegment(ColumnSegment &other, idx
|
|
55
55
|
}
|
56
56
|
|
57
57
|
ColumnSegment::ColumnSegment(DatabaseInstance &db, shared_ptr<BlockHandle> block, LogicalType type_p,
|
58
|
-
ColumnSegmentType segment_type, idx_t start, idx_t count, CompressionFunction
|
58
|
+
ColumnSegmentType segment_type, idx_t start, idx_t count, CompressionFunction &function_p,
|
59
59
|
BaseStatistics statistics, block_id_t block_id_p, idx_t offset_p, idx_t segment_size_p)
|
60
60
|
: SegmentBase<ColumnSegment>(start, count), db(db), type(std::move(type_p)),
|
61
61
|
type_size(GetTypeIdSize(type.InternalType())), segment_type(segment_type), function(function_p),
|
62
62
|
stats(std::move(statistics)), block(std::move(block)), block_id(block_id_p), offset(offset_p),
|
63
63
|
segment_size(segment_size_p) {
|
64
|
-
|
65
|
-
|
66
|
-
segment_state = function->init_segment(*this, block_id);
|
64
|
+
if (function.get().init_segment) {
|
65
|
+
segment_state = function.get().init_segment(*this, block_id);
|
67
66
|
}
|
68
67
|
}
|
69
68
|
|
@@ -81,7 +80,7 @@ ColumnSegment::~ColumnSegment() {
|
|
81
80
|
// Scan
|
82
81
|
//===--------------------------------------------------------------------===//
|
83
82
|
void ColumnSegment::InitializeScan(ColumnScanState &state) {
|
84
|
-
state.scan_state = function
|
83
|
+
state.scan_state = function.get().init_scan(*this);
|
85
84
|
}
|
86
85
|
|
87
86
|
void ColumnSegment::Scan(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset,
|
@@ -97,23 +96,23 @@ void ColumnSegment::Scan(ColumnScanState &state, idx_t scan_count, Vector &resul
|
|
97
96
|
}
|
98
97
|
|
99
98
|
void ColumnSegment::Skip(ColumnScanState &state) {
|
100
|
-
function
|
99
|
+
function.get().skip(*this, state, state.row_index - state.internal_index);
|
101
100
|
state.internal_index = state.row_index;
|
102
101
|
}
|
103
102
|
|
104
103
|
void ColumnSegment::Scan(ColumnScanState &state, idx_t scan_count, Vector &result) {
|
105
|
-
function
|
104
|
+
function.get().scan_vector(*this, state, scan_count, result);
|
106
105
|
}
|
107
106
|
|
108
107
|
void ColumnSegment::ScanPartial(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset) {
|
109
|
-
function
|
108
|
+
function.get().scan_partial(*this, state, scan_count, result, result_offset);
|
110
109
|
}
|
111
110
|
|
112
111
|
//===--------------------------------------------------------------------===//
|
113
112
|
// Fetch
|
114
113
|
//===--------------------------------------------------------------------===//
|
115
114
|
void ColumnSegment::FetchRow(ColumnFetchState &state, row_t row_id, Vector &result, idx_t result_idx) {
|
116
|
-
function
|
115
|
+
function.get().fetch_row(*this, state, row_id - this->start, result, result_idx);
|
117
116
|
}
|
118
117
|
|
119
118
|
//===--------------------------------------------------------------------===//
|
@@ -138,34 +137,34 @@ void ColumnSegment::Resize(idx_t new_size) {
|
|
138
137
|
|
139
138
|
void ColumnSegment::InitializeAppend(ColumnAppendState &state) {
|
140
139
|
D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
|
141
|
-
if (!function
|
140
|
+
if (!function.get().init_append) {
|
142
141
|
throw InternalException("Attempting to init append to a segment without init_append method");
|
143
142
|
}
|
144
|
-
state.append_state = function
|
143
|
+
state.append_state = function.get().init_append(*this);
|
145
144
|
}
|
146
145
|
|
147
146
|
idx_t ColumnSegment::Append(ColumnAppendState &state, UnifiedVectorFormat &append_data, idx_t offset, idx_t count) {
|
148
147
|
D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
|
149
|
-
if (!function
|
148
|
+
if (!function.get().append) {
|
150
149
|
throw InternalException("Attempting to append to a segment without append method");
|
151
150
|
}
|
152
|
-
return function
|
151
|
+
return function.get().append(*state.append_state, *this, stats, append_data, offset, count);
|
153
152
|
}
|
154
153
|
|
155
154
|
idx_t ColumnSegment::FinalizeAppend(ColumnAppendState &state) {
|
156
155
|
D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
|
157
|
-
if (!function
|
156
|
+
if (!function.get().finalize_append) {
|
158
157
|
throw InternalException("Attempting to call FinalizeAppend on a segment without a finalize_append method");
|
159
158
|
}
|
160
|
-
auto result_count = function
|
159
|
+
auto result_count = function.get().finalize_append(*this, stats);
|
161
160
|
state.append_state.reset();
|
162
161
|
return result_count;
|
163
162
|
}
|
164
163
|
|
165
164
|
void ColumnSegment::RevertAppend(idx_t start_row) {
|
166
165
|
D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
|
167
|
-
if (function
|
168
|
-
function
|
166
|
+
if (function.get().revert_append) {
|
167
|
+
function.get().revert_append(*this, start_row);
|
169
168
|
}
|
170
169
|
this->count = start_row - this->start;
|
171
170
|
}
|
@@ -193,8 +192,8 @@ void ColumnSegment::ConvertToPersistent(BlockManager *block_manager, block_id_t
|
|
193
192
|
}
|
194
193
|
|
195
194
|
segment_state.reset();
|
196
|
-
if (function
|
197
|
-
segment_state = function
|
195
|
+
if (function.get().init_segment) {
|
196
|
+
segment_state = function.get().init_segment(*this, block_id);
|
198
197
|
}
|
199
198
|
}
|
200
199
|
|
@@ -207,8 +206,8 @@ void ColumnSegment::MarkAsPersistent(shared_ptr<BlockHandle> block_p, uint32_t o
|
|
207
206
|
block = std::move(block_p);
|
208
207
|
|
209
208
|
segment_state.reset();
|
210
|
-
if (function
|
211
|
-
segment_state = function
|
209
|
+
if (function.get().init_segment) {
|
210
|
+
segment_state = function.get().init_segment(*this, block_id);
|
212
211
|
}
|
213
212
|
}
|
214
213
|
|
@@ -927,14 +927,14 @@ void RowGroup::GetStorageInfo(idx_t row_group_index, TableStorageInfo &result) {
|
|
927
927
|
//===--------------------------------------------------------------------===//
|
928
928
|
class VersionDeleteState {
|
929
929
|
public:
|
930
|
-
VersionDeleteState(RowGroup &info, TransactionData transaction, DataTable
|
930
|
+
VersionDeleteState(RowGroup &info, TransactionData transaction, DataTable &table, idx_t base_row)
|
931
931
|
: info(info), transaction(transaction), table(table), current_info(nullptr),
|
932
932
|
current_chunk(DConstants::INVALID_INDEX), count(0), base_row(base_row), delete_count(0) {
|
933
933
|
}
|
934
934
|
|
935
935
|
RowGroup &info;
|
936
936
|
TransactionData transaction;
|
937
|
-
DataTable
|
937
|
+
DataTable &table;
|
938
938
|
ChunkVectorInfo *current_info;
|
939
939
|
idx_t current_chunk;
|
940
940
|
row_t rows[STANDARD_VECTOR_SIZE];
|
@@ -948,7 +948,7 @@ public:
|
|
948
948
|
void Flush();
|
949
949
|
};
|
950
950
|
|
951
|
-
idx_t RowGroup::Delete(TransactionData transaction, DataTable
|
951
|
+
idx_t RowGroup::Delete(TransactionData transaction, DataTable &table, row_t *ids, idx_t count) {
|
952
952
|
lock_guard<mutex> lock(row_group_lock);
|
953
953
|
VersionDeleteState del_state(*this, transaction, table, this->start);
|
954
954
|
|
@@ -456,7 +456,7 @@ void RowGroupCollection::MergeStorage(RowGroupCollection &data) {
|
|
456
456
|
//===--------------------------------------------------------------------===//
|
457
457
|
// Delete
|
458
458
|
//===--------------------------------------------------------------------===//
|
459
|
-
idx_t RowGroupCollection::Delete(TransactionData transaction, DataTable
|
459
|
+
idx_t RowGroupCollection::Delete(TransactionData transaction, DataTable &table, row_t *ids, idx_t count) {
|
460
460
|
idx_t delete_count = 0;
|
461
461
|
// delete is in the row groups
|
462
462
|
// we need to figure out for each id to which row group it belongs
|
@@ -461,15 +461,15 @@ void UpdateSegment::FetchRow(TransactionData transaction, idx_t row_id, Vector &
|
|
461
461
|
// Rollback update
|
462
462
|
//===--------------------------------------------------------------------===//
|
463
463
|
template <class T>
|
464
|
-
static void RollbackUpdate(UpdateInfo
|
465
|
-
auto base_data = (T *)base_info
|
466
|
-
auto rollback_data = (T *)rollback_info
|
464
|
+
static void RollbackUpdate(UpdateInfo &base_info, UpdateInfo &rollback_info) {
|
465
|
+
auto base_data = (T *)base_info.tuple_data;
|
466
|
+
auto rollback_data = (T *)rollback_info.tuple_data;
|
467
467
|
idx_t base_offset = 0;
|
468
|
-
for (idx_t i = 0; i < rollback_info
|
469
|
-
auto id = rollback_info
|
470
|
-
while (base_info
|
468
|
+
for (idx_t i = 0; i < rollback_info.N; i++) {
|
469
|
+
auto id = rollback_info.tuples[i];
|
470
|
+
while (base_info.tuples[base_offset] < id) {
|
471
471
|
base_offset++;
|
472
|
-
D_ASSERT(base_offset < base_info
|
472
|
+
D_ASSERT(base_offset < base_info.N);
|
473
473
|
}
|
474
474
|
base_data[base_offset] = rollback_data[i];
|
475
475
|
}
|
@@ -511,13 +511,13 @@ static UpdateSegment::rollback_update_function_t GetRollbackUpdateFunction(Physi
|
|
511
511
|
}
|
512
512
|
}
|
513
513
|
|
514
|
-
void UpdateSegment::RollbackUpdate(UpdateInfo
|
514
|
+
void UpdateSegment::RollbackUpdate(UpdateInfo &info) {
|
515
515
|
// obtain an exclusive lock
|
516
516
|
auto lock_handle = lock.GetExclusiveLock();
|
517
517
|
|
518
518
|
// move the data from the UpdateInfo back into the base info
|
519
|
-
D_ASSERT(root->info[info
|
520
|
-
rollback_update_function(root->info[info
|
519
|
+
D_ASSERT(root->info[info.vector_index]);
|
520
|
+
rollback_update_function(*root->info[info.vector_index]->info, info);
|
521
521
|
|
522
522
|
// clean up the update chain
|
523
523
|
CleanupUpdateInternal(*lock_handle, info);
|
@@ -526,16 +526,16 @@ void UpdateSegment::RollbackUpdate(UpdateInfo *info) {
|
|
526
526
|
//===--------------------------------------------------------------------===//
|
527
527
|
// Cleanup Update
|
528
528
|
//===--------------------------------------------------------------------===//
|
529
|
-
void UpdateSegment::CleanupUpdateInternal(const StorageLockKey &lock, UpdateInfo
|
530
|
-
D_ASSERT(info
|
531
|
-
auto prev = info
|
532
|
-
prev->next = info
|
529
|
+
void UpdateSegment::CleanupUpdateInternal(const StorageLockKey &lock, UpdateInfo &info) {
|
530
|
+
D_ASSERT(info.prev);
|
531
|
+
auto prev = info.prev;
|
532
|
+
prev->next = info.next;
|
533
533
|
if (prev->next) {
|
534
534
|
prev->next->prev = prev;
|
535
535
|
}
|
536
536
|
}
|
537
537
|
|
538
|
-
void UpdateSegment::CleanupUpdate(UpdateInfo
|
538
|
+
void UpdateSegment::CleanupUpdate(UpdateInfo &info) {
|
539
539
|
// obtain an exclusive lock
|
540
540
|
auto lock_handle = lock.GetExclusiveLock();
|
541
541
|
CleanupUpdateInternal(*lock_handle, info);
|
@@ -411,7 +411,7 @@ void ReplayState::ReplayCreateIndex() {
|
|
411
411
|
}
|
412
412
|
}
|
413
413
|
auto binder = Binder::CreateBinder(context);
|
414
|
-
auto expressions = binder->BindCreateIndexExpressions(table, info
|
414
|
+
auto expressions = binder->BindCreateIndexExpressions(*table, *info);
|
415
415
|
|
416
416
|
// create the empty index
|
417
417
|
unique_ptr<Index> index;
|
@@ -29,12 +29,12 @@ void CleanupState::CleanupEntry(UndoFlags type, data_ptr_t data) {
|
|
29
29
|
}
|
30
30
|
case UndoFlags::DELETE_TUPLE: {
|
31
31
|
auto info = (DeleteInfo *)data;
|
32
|
-
CleanupDelete(info);
|
32
|
+
CleanupDelete(*info);
|
33
33
|
break;
|
34
34
|
}
|
35
35
|
case UndoFlags::UPDATE_TUPLE: {
|
36
36
|
auto info = (UpdateInfo *)data;
|
37
|
-
CleanupUpdate(info);
|
37
|
+
CleanupUpdate(*info);
|
38
38
|
break;
|
39
39
|
}
|
40
40
|
default:
|
@@ -42,16 +42,16 @@ void CleanupState::CleanupEntry(UndoFlags type, data_ptr_t data) {
|
|
42
42
|
}
|
43
43
|
}
|
44
44
|
|
45
|
-
void CleanupState::CleanupUpdate(UpdateInfo
|
45
|
+
void CleanupState::CleanupUpdate(UpdateInfo &info) {
|
46
46
|
// remove the update info from the update chain
|
47
47
|
// first obtain an exclusive lock on the segment
|
48
|
-
info
|
48
|
+
info.segment->CleanupUpdate(info);
|
49
49
|
}
|
50
50
|
|
51
|
-
void CleanupState::CleanupDelete(DeleteInfo
|
52
|
-
auto version_table = info
|
53
|
-
D_ASSERT(version_table->info->cardinality >= info
|
54
|
-
version_table->info->cardinality -= info
|
51
|
+
void CleanupState::CleanupDelete(DeleteInfo &info) {
|
52
|
+
auto version_table = info.table;
|
53
|
+
D_ASSERT(version_table->info->cardinality >= info.count);
|
54
|
+
version_table->info->cardinality -= info.count;
|
55
55
|
if (version_table->info->indexes.Empty()) {
|
56
56
|
// this table has no indexes: no cleanup to be done
|
57
57
|
return;
|
@@ -62,8 +62,8 @@ void CleanupState::CleanupDelete(DeleteInfo *info) {
|
|
62
62
|
current_table = version_table;
|
63
63
|
}
|
64
64
|
count = 0;
|
65
|
-
for (idx_t i = 0; i < info
|
66
|
-
row_numbers[count++] = info
|
65
|
+
for (idx_t i = 0; i < info.count; i++) {
|
66
|
+
row_numbers[count++] = info.vinfo->start + info.rows[i];
|
67
67
|
}
|
68
68
|
Flush();
|
69
69
|
}
|
@@ -19,7 +19,7 @@
|
|
19
19
|
|
20
20
|
namespace duckdb {
|
21
21
|
|
22
|
-
CommitState::CommitState(ClientContext &context, transaction_t commit_id, WriteAheadLog
|
22
|
+
CommitState::CommitState(ClientContext &context, transaction_t commit_id, optional_ptr<WriteAheadLog> log)
|
23
23
|
: log(log), commit_id(commit_id), current_table_info(nullptr), context(context) {
|
24
24
|
}
|
25
25
|
|
@@ -149,10 +149,10 @@ void CommitState::WriteCatalogEntry(CatalogEntry &entry, data_ptr_t dataptr) {
|
|
149
149
|
}
|
150
150
|
}
|
151
151
|
|
152
|
-
void CommitState::WriteDelete(DeleteInfo
|
152
|
+
void CommitState::WriteDelete(DeleteInfo &info) {
|
153
153
|
D_ASSERT(log);
|
154
154
|
// switch to the current table, if necessary
|
155
|
-
SwitchTable(info
|
155
|
+
SwitchTable(info.table->info.get(), UndoFlags::DELETE_TUPLE);
|
156
156
|
|
157
157
|
if (!delete_chunk) {
|
158
158
|
delete_chunk = make_uniq<DataChunk>();
|
@@ -160,17 +160,17 @@ void CommitState::WriteDelete(DeleteInfo *info) {
|
|
160
160
|
delete_chunk->Initialize(Allocator::DefaultAllocator(), delete_types);
|
161
161
|
}
|
162
162
|
auto rows = FlatVector::GetData<row_t>(delete_chunk->data[0]);
|
163
|
-
for (idx_t i = 0; i < info
|
164
|
-
rows[i] = info
|
163
|
+
for (idx_t i = 0; i < info.count; i++) {
|
164
|
+
rows[i] = info.base_row + info.rows[i];
|
165
165
|
}
|
166
|
-
delete_chunk->SetCardinality(info
|
166
|
+
delete_chunk->SetCardinality(info.count);
|
167
167
|
log->WriteDelete(*delete_chunk);
|
168
168
|
}
|
169
169
|
|
170
|
-
void CommitState::WriteUpdate(UpdateInfo
|
170
|
+
void CommitState::WriteUpdate(UpdateInfo &info) {
|
171
171
|
D_ASSERT(log);
|
172
172
|
// switch to the current table, if necessary
|
173
|
-
auto &column_data = info
|
173
|
+
auto &column_data = info.segment->column_data;
|
174
174
|
auto &table_info = column_data.GetTableInfo();
|
175
175
|
|
176
176
|
SwitchTable(&table_info, UndoFlags::UPDATE_TUPLE);
|
@@ -188,25 +188,25 @@ void CommitState::WriteUpdate(UpdateInfo *info) {
|
|
188
188
|
update_chunk->Initialize(Allocator::DefaultAllocator(), update_types);
|
189
189
|
|
190
190
|
// fetch the updated values from the base segment
|
191
|
-
info
|
191
|
+
info.segment->FetchCommitted(info.vector_index, update_chunk->data[0]);
|
192
192
|
|
193
193
|
// write the row ids into the chunk
|
194
194
|
auto row_ids = FlatVector::GetData<row_t>(update_chunk->data[1]);
|
195
|
-
idx_t start = column_data.start + info
|
196
|
-
for (idx_t i = 0; i < info
|
197
|
-
row_ids[info
|
195
|
+
idx_t start = column_data.start + info.vector_index * STANDARD_VECTOR_SIZE;
|
196
|
+
for (idx_t i = 0; i < info.N; i++) {
|
197
|
+
row_ids[info.tuples[i]] = start + info.tuples[i];
|
198
198
|
}
|
199
199
|
if (column_data.type.id() == LogicalTypeId::VALIDITY) {
|
200
200
|
// zero-initialize the booleans
|
201
201
|
// FIXME: this is only required because of NullValue<T> in Vector::Serialize...
|
202
202
|
auto booleans = FlatVector::GetData<bool>(update_chunk->data[0]);
|
203
|
-
for (idx_t i = 0; i < info
|
204
|
-
auto idx = info
|
203
|
+
for (idx_t i = 0; i < info.N; i++) {
|
204
|
+
auto idx = info.tuples[i];
|
205
205
|
booleans[idx] = false;
|
206
206
|
}
|
207
207
|
}
|
208
|
-
SelectionVector sel(info
|
209
|
-
update_chunk->Slice(sel, info
|
208
|
+
SelectionVector sel(info.tuples);
|
209
|
+
update_chunk->Slice(sel, info.N);
|
210
210
|
|
211
211
|
// construct the column index path
|
212
212
|
vector<column_t> column_indexes;
|
@@ -215,7 +215,7 @@ void CommitState::WriteUpdate(UpdateInfo *info) {
|
|
215
215
|
column_indexes.push_back(column_data_ptr->column_index);
|
216
216
|
column_data_ptr = column_data_ptr->parent;
|
217
217
|
}
|
218
|
-
column_indexes.push_back(info
|
218
|
+
column_indexes.push_back(info.column_index);
|
219
219
|
std::reverse(column_indexes.begin(), column_indexes.end());
|
220
220
|
|
221
221
|
log->WriteUpdate(*update_chunk, column_indexes);
|
@@ -260,7 +260,7 @@ void CommitState::CommitEntry(UndoFlags type, data_ptr_t data) {
|
|
260
260
|
// deletion:
|
261
261
|
auto info = (DeleteInfo *)data;
|
262
262
|
if (HAS_LOG && !info->table->info->IsTemporary()) {
|
263
|
-
WriteDelete(info);
|
263
|
+
WriteDelete(*info);
|
264
264
|
}
|
265
265
|
// mark the tuples as committed
|
266
266
|
info->vinfo->CommitDelete(commit_id, info->rows, info->count);
|
@@ -270,7 +270,7 @@ void CommitState::CommitEntry(UndoFlags type, data_ptr_t data) {
|
|
270
270
|
// update:
|
271
271
|
auto info = (UpdateInfo *)data;
|
272
272
|
if (HAS_LOG && !info->segment->column_data.GetTableInfo().IsTemporary()) {
|
273
|
-
WriteUpdate(info);
|
273
|
+
WriteUpdate(*info);
|
274
274
|
}
|
275
275
|
info->version_number = commit_id;
|
276
276
|
break;
|
@@ -51,14 +51,14 @@ LocalStorage &DuckTransaction::GetLocalStorage() {
|
|
51
51
|
return *storage;
|
52
52
|
}
|
53
53
|
|
54
|
-
void DuckTransaction::PushCatalogEntry(CatalogEntry
|
54
|
+
void DuckTransaction::PushCatalogEntry(CatalogEntry &entry, data_ptr_t extra_data, idx_t extra_data_size) {
|
55
55
|
idx_t alloc_size = sizeof(CatalogEntry *);
|
56
56
|
if (extra_data_size > 0) {
|
57
57
|
alloc_size += extra_data_size + sizeof(idx_t);
|
58
58
|
}
|
59
59
|
auto baseptr = undo_buffer.CreateEntry(UndoFlags::CATALOG_ENTRY, alloc_size);
|
60
60
|
// store the pointer to the catalog entry
|
61
|
-
Store<CatalogEntry *>(entry, baseptr);
|
61
|
+
Store<CatalogEntry *>(&entry, baseptr);
|
62
62
|
if (extra_data_size > 0) {
|
63
63
|
// copy the extra data behind the catalog entry pointer (if any)
|
64
64
|
baseptr += sizeof(CatalogEntry *);
|
@@ -70,19 +70,19 @@ void DuckTransaction::PushCatalogEntry(CatalogEntry *entry, data_ptr_t extra_dat
|
|
70
70
|
}
|
71
71
|
}
|
72
72
|
|
73
|
-
void DuckTransaction::PushDelete(DataTable
|
73
|
+
void DuckTransaction::PushDelete(DataTable &table, ChunkVectorInfo *vinfo, row_t rows[], idx_t count, idx_t base_row) {
|
74
74
|
auto delete_info =
|
75
75
|
(DeleteInfo *)undo_buffer.CreateEntry(UndoFlags::DELETE_TUPLE, sizeof(DeleteInfo) + sizeof(row_t) * count);
|
76
76
|
delete_info->vinfo = vinfo;
|
77
|
-
delete_info->table = table;
|
77
|
+
delete_info->table = &table;
|
78
78
|
delete_info->count = count;
|
79
79
|
delete_info->base_row = base_row;
|
80
80
|
memcpy(delete_info->rows, rows, sizeof(row_t) * count);
|
81
81
|
}
|
82
82
|
|
83
|
-
void DuckTransaction::PushAppend(DataTable
|
83
|
+
void DuckTransaction::PushAppend(DataTable &table, idx_t start_row, idx_t row_count) {
|
84
84
|
auto append_info = (AppendInfo *)undo_buffer.CreateEntry(UndoFlags::INSERT_TUPLE, sizeof(AppendInfo));
|
85
|
-
append_info->table = table;
|
85
|
+
append_info->table = &table;
|
86
86
|
append_info->start_row = start_row;
|
87
87
|
append_info->count = row_count;
|
88
88
|
}
|
@@ -116,7 +116,7 @@ string DuckTransaction::Commit(AttachedDatabase &db, transaction_t commit_id, bo
|
|
116
116
|
UndoBuffer::IteratorState iterator_state;
|
117
117
|
LocalStorage::CommitState commit_state;
|
118
118
|
unique_ptr<StorageCommitState> storage_commit_state;
|
119
|
-
WriteAheadLog
|
119
|
+
optional_ptr<WriteAheadLog> log;
|
120
120
|
if (!db.IsSystem()) {
|
121
121
|
auto &storage_manager = db.GetStorageManager();
|
122
122
|
log = storage_manager.GetWriteAheadLog();
|
@@ -35,7 +35,7 @@ void RollbackState::RollbackEntry(UndoFlags type, data_ptr_t data) {
|
|
35
35
|
}
|
36
36
|
case UndoFlags::UPDATE_TUPLE: {
|
37
37
|
auto info = (UpdateInfo *)data;
|
38
|
-
info->segment->RollbackUpdate(info);
|
38
|
+
info->segment->RollbackUpdate(*info);
|
39
39
|
break;
|
40
40
|
}
|
41
41
|
default: // LCOV_EXCL_START
|
@@ -128,7 +128,8 @@ void UndoBuffer::Cleanup() {
|
|
128
128
|
IterateEntries(iterator_state, [&](UndoFlags type, data_ptr_t data) { state.CleanupEntry(type, data); });
|
129
129
|
}
|
130
130
|
|
131
|
-
void UndoBuffer::Commit(UndoBuffer::IteratorState &iterator_state, WriteAheadLog
|
131
|
+
void UndoBuffer::Commit(UndoBuffer::IteratorState &iterator_state, optional_ptr<WriteAheadLog> log,
|
132
|
+
transaction_t commit_id) {
|
132
133
|
CommitState state(context, commit_id, log);
|
133
134
|
if (log) {
|
134
135
|
// commit WITH write ahead log
|
@@ -1,185 +0,0 @@
|
|
1
|
-
//===----------------------------------------------------------------------===//
|
2
|
-
// DuckDB
|
3
|
-
//
|
4
|
-
// duckdb/common/single_thread_ptr.hpp
|
5
|
-
//
|
6
|
-
//
|
7
|
-
//===----------------------------------------------------------------------===//
|
8
|
-
|
9
|
-
#pragma once
|
10
|
-
|
11
|
-
#include "duckdb/common/unique_ptr.hpp"
|
12
|
-
|
13
|
-
class RefCounter {
|
14
|
-
public:
|
15
|
-
uint32_t pn;
|
16
|
-
RefCounter() : pn(1) {
|
17
|
-
}
|
18
|
-
void inc() {
|
19
|
-
++pn;
|
20
|
-
}
|
21
|
-
void dec() {
|
22
|
-
--pn;
|
23
|
-
}
|
24
|
-
uint32_t getPn() const {
|
25
|
-
return pn;
|
26
|
-
}
|
27
|
-
virtual ~RefCounter() {
|
28
|
-
}
|
29
|
-
};
|
30
|
-
|
31
|
-
namespace duckdb {
|
32
|
-
template <typename T>
|
33
|
-
class single_thread_ptr {
|
34
|
-
public:
|
35
|
-
T *ptr; // contained pointer
|
36
|
-
RefCounter *ref_count; // reference counter
|
37
|
-
|
38
|
-
public:
|
39
|
-
// Default constructor, constructs an empty single_thread_ptr.
|
40
|
-
constexpr single_thread_ptr() : ptr(nullptr), ref_count(nullptr) {
|
41
|
-
}
|
42
|
-
// Construct empty single_thread_ptr.
|
43
|
-
constexpr single_thread_ptr(std::nullptr_t) : ptr(nullptr), ref_count(nullptr) {
|
44
|
-
}
|
45
|
-
// Construct a single_thread_ptr that wraps raw pointer.
|
46
|
-
|
47
|
-
single_thread_ptr(RefCounter *r, T *p) {
|
48
|
-
ptr = p;
|
49
|
-
ref_count = r;
|
50
|
-
}
|
51
|
-
|
52
|
-
template <class U>
|
53
|
-
single_thread_ptr(RefCounter *r, U *p) {
|
54
|
-
ptr = p;
|
55
|
-
ref_count = r;
|
56
|
-
}
|
57
|
-
|
58
|
-
// Copy constructor.
|
59
|
-
single_thread_ptr(const single_thread_ptr &sp) : ptr(nullptr), ref_count(nullptr) {
|
60
|
-
if (sp.ptr) {
|
61
|
-
ptr = sp.ptr;
|
62
|
-
ref_count = sp.ref_count;
|
63
|
-
ref_count->inc();
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
// Conversion constructor.
|
68
|
-
template <typename U>
|
69
|
-
single_thread_ptr(const single_thread_ptr<U> &sp) : ptr(nullptr), ref_count(nullptr) {
|
70
|
-
if (sp.ptr) {
|
71
|
-
ptr = sp.ptr;
|
72
|
-
ref_count = sp.ref_count;
|
73
|
-
ref_count->inc();
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
// move constructor.
|
78
|
-
single_thread_ptr(single_thread_ptr &&sp) noexcept : ptr {sp.ptr}, ref_count {sp.ref_count} {
|
79
|
-
sp.ptr = nullptr;
|
80
|
-
sp.ref_count = nullptr;
|
81
|
-
}
|
82
|
-
|
83
|
-
// move constructor.
|
84
|
-
template <class U>
|
85
|
-
single_thread_ptr(single_thread_ptr<U> &&sp) noexcept : ptr {sp.ptr}, ref_count {sp.ref_count} {
|
86
|
-
sp.ptr = nullptr;
|
87
|
-
sp.ref_count = nullptr;
|
88
|
-
}
|
89
|
-
|
90
|
-
// No effect if single_thread_ptr is empty or use_count() > 1, otherwise release the resources.
|
91
|
-
~single_thread_ptr() {
|
92
|
-
release();
|
93
|
-
}
|
94
|
-
|
95
|
-
void release() {
|
96
|
-
if (ptr && ref_count) {
|
97
|
-
ref_count->dec();
|
98
|
-
if ((ref_count->getPn()) == 0) {
|
99
|
-
delete ref_count;
|
100
|
-
}
|
101
|
-
}
|
102
|
-
ref_count = nullptr;
|
103
|
-
ptr = nullptr;
|
104
|
-
}
|
105
|
-
|
106
|
-
// Copy assignment.
|
107
|
-
single_thread_ptr &operator=(single_thread_ptr sp) noexcept {
|
108
|
-
std::swap(this->ptr, sp.ptr);
|
109
|
-
std::swap(this->ref_count, sp.ref_count);
|
110
|
-
return *this;
|
111
|
-
}
|
112
|
-
|
113
|
-
// Dereference pointer to managed object.
|
114
|
-
T &operator*() const noexcept {
|
115
|
-
return *ptr;
|
116
|
-
}
|
117
|
-
T *operator->() const noexcept {
|
118
|
-
return ptr;
|
119
|
-
}
|
120
|
-
|
121
|
-
// Return the contained pointer.
|
122
|
-
T *get() const noexcept {
|
123
|
-
return ptr;
|
124
|
-
}
|
125
|
-
|
126
|
-
// Return use count (use count == 0 if single_thread_ptr is empty).
|
127
|
-
long use_count() const noexcept {
|
128
|
-
if (ptr)
|
129
|
-
return ref_count->getPn();
|
130
|
-
else
|
131
|
-
return 0;
|
132
|
-
}
|
133
|
-
|
134
|
-
// Check if there is an associated managed object.
|
135
|
-
explicit operator bool() const noexcept {
|
136
|
-
return (ptr);
|
137
|
-
}
|
138
|
-
|
139
|
-
// Resets single_thread_ptr to empty.
|
140
|
-
void reset() noexcept {
|
141
|
-
release();
|
142
|
-
}
|
143
|
-
};
|
144
|
-
|
145
|
-
template <class T>
|
146
|
-
struct _object_and_block : public RefCounter {
|
147
|
-
T object;
|
148
|
-
|
149
|
-
template <class... Args>
|
150
|
-
explicit _object_and_block(Args &&... args) : object(std::forward<Args>(args)...) {
|
151
|
-
}
|
152
|
-
};
|
153
|
-
|
154
|
-
// Operator overloading.
|
155
|
-
template <typename T, typename U>
|
156
|
-
inline bool operator==(const single_thread_ptr<T> &sp1, const single_thread_ptr<U> &sp2) {
|
157
|
-
return sp1.get() == sp2.get();
|
158
|
-
}
|
159
|
-
|
160
|
-
template <typename T>
|
161
|
-
inline bool operator==(const single_thread_ptr<T> &sp, std::nullptr_t) noexcept {
|
162
|
-
return !sp;
|
163
|
-
}
|
164
|
-
|
165
|
-
template <typename T, typename U>
|
166
|
-
inline bool operator!=(const single_thread_ptr<T> &sp1, const single_thread_ptr<U> &sp2) {
|
167
|
-
return sp1.get() != sp2.get();
|
168
|
-
}
|
169
|
-
|
170
|
-
template <typename T>
|
171
|
-
inline bool operator!=(const single_thread_ptr<T> &sp, std::nullptr_t) noexcept {
|
172
|
-
return sp.get();
|
173
|
-
}
|
174
|
-
|
175
|
-
template <typename T>
|
176
|
-
inline bool operator!=(std::nullptr_t, const single_thread_ptr<T> &sp) noexcept {
|
177
|
-
return sp.get();
|
178
|
-
}
|
179
|
-
|
180
|
-
template <class T, class... Args>
|
181
|
-
single_thread_ptr<T> single_thread_make_shared(Args &&... args) {
|
182
|
-
auto tmp_object = new _object_and_block<T>(std::forward<Args>(args)...);
|
183
|
-
return single_thread_ptr<T>(tmp_object, &(tmp_object->object));
|
184
|
-
}
|
185
|
-
} // namespace duckdb
|