440122 {
440123
440124 auto write_lock =
lock.GetExclusiveLock();
440125
440126 UnifiedVectorFormat update_format;
440127 update_p.ToUnifiedFormat(count, update_format);
440128
440129
440130 SelectionVector sel;
440131 {
440133 count = statistics_update_function(
this,
stats, update_format, count, sel);
440134 }
440135 if (count == 0) {
440136 return;
440137 }
440138
440139
440140
440141
440142
440143 count = SortSelectionVector(sel, count, ids);
440144 D_ASSERT(count > 0);
440145
440146
440147
440148 auto first_id = ids[sel.get_index(0)];
440149 idx_t vector_index = (UnsafeNumericCast<idx_t>(first_id) - row_group_start) / STANDARD_VECTOR_SIZE;
440150 idx_t vector_offset = row_group_start + vector_index * STANDARD_VECTOR_SIZE;
440151
440152 if (!
root || vector_index >=
root->info.size() || !
root->info[vector_index].IsSet()) {
440153
440154
440155
440156
440157 count = get_effective_updates(update_format, ids, count, sel, base_data, vector_offset);
440158 if (count == 0) {
440159 return;
440160 }
440161 }
440162
440163 InitializeUpdateInfo(vector_index);
440164
440165 D_ASSERT(
idx_t(first_id) >= row_group_start);
440166
440167 if (
root->info[vector_index].IsSet()) {
440168
440169
440170 auto root_pointer =
root->info[vector_index];
440171 auto root_pin = root_pointer.Pin();
440172 auto &base_info = UpdateInfo::Get(root_pin);
440173
440174 UndoBufferReference node_ref;
440175 CheckForConflicts(base_info.next, transaction, ids, sel, count, UnsafeNumericCast<row_t>(vector_offset),
440176 node_ref);
440177
440178
440179 unsafe_unique_array<char> update_info_data;
440180 optional_ptr<UpdateInfo> node;
440181 if (!node_ref.IsSet()) {
440182
440183 if (transaction.transaction) {
440184 auto &dtransaction = transaction.transaction->Cast<DuckTransaction>();
440185 node_ref = dtransaction.CreateUpdateInfo(
type_size, data_table, count, row_group_start);
440186 node = &UpdateInfo::Get(node_ref);
440187 } else {
440188 node =
440189 CreateEmptyUpdateInfo(transaction, data_table,
type_size, count, update_info_data, row_group_start);
440190 }
440191 node->segment = this;
440192 node->vector_index = vector_index;
440193 node->N = 0;
440194 node->column_index = column_index;
440195
440196
440197 node->next = base_info.next;
440198 if (node->next.IsSet()) {
440199 auto next_pin = node->next.Pin();
440200 auto &next_info = UpdateInfo::Get(next_pin);
440201 next_info.prev = node_ref.GetBufferPointer();
440202 }
440203 node->prev = root_pointer;
440204 base_info.next = transaction.transaction ? node_ref.GetBufferPointer() : UndoBufferPointer();
440205 } else {
440206
440207 node = &UpdateInfo::Get(node_ref);
440208 }
440209 base_info.Verify();
440210 node->Verify();
440211
440212
440213 merge_update_function(base_info, base_data, *node, update_format, ids, count, sel, row_group_start);
440214
440215 base_info.Verify();
440216 node->Verify();
440217 } else {
440218
440219
440221 auto handle =
root->allocator.Allocate(alloc_size);
440222 auto &update_info = UpdateInfo::Get(handle);
440224 update_info.column_index = column_index;
440225
440226 InitializeUpdateInfo(update_info, ids, sel, count, vector_index, vector_offset);
440227
440228
440229 unsafe_unique_array<char> update_info_data;
440230 UndoBufferReference node_ref;
440231 optional_ptr<UpdateInfo> transaction_node;
440232 if (transaction.transaction) {
440233 node_ref = transaction.transaction->CreateUpdateInfo(
type_size, data_table, count, row_group_start);
440234 transaction_node = &UpdateInfo::Get(node_ref);
440235 } else {
440236 transaction_node =
440237 CreateEmptyUpdateInfo(transaction, data_table,
type_size, count, update_info_data, row_group_start);
440238 }
440239
440240 InitializeUpdateInfo(*transaction_node, ids, sel, count, vector_index, vector_offset);
440241
440242
440243 initialize_update_function(*transaction_node, base_data, update_info, update_format, sel);
440244
440245 update_info.next = transaction.transaction ? node_ref.GetBufferPointer() : UndoBufferPointer();
440246 update_info.prev = UndoBufferPointer();
440247 transaction_node->next = UndoBufferPointer();
440248 transaction_node->prev = handle.GetBufferPointer();
440249 transaction_node->column_index = column_index;
440250
440251 transaction_node->Verify();
440252 update_info.Verify();
440253
440254 root->info[vector_index] = handle.GetBufferPointer();
440255 }
440256}
mutex stats_lock
Stats lock.
Definition duckdb.cpp:428734
static void Initialize(UpdateInfo &info, DataTable &data_table, transaction_t transaction_id, idx_t row_group_start)
Initialize an UpdateInfo struct that has been allocated using GetAllocSize (i.e. has extra space afte...
Definition duckdb.cpp:438946
static idx_t GetAllocSize(idx_t type_size)
Returns the total allocation size for an UpdateInfo entry, together with space for the tuple data.
Definition duckdb.cpp:438942