400141 {
400142 auto &buffer_manager = BufferManager::GetBufferManager(checkpoint_data.GetDatabase());
400143 auto handle = buffer_manager.Pin(current_segment->block);
400144 D_ASSERT(current_dictionary.end == info.GetBlockSize());
400145
400146
400147 auto compressed_selection_buffer_size =
400148 BitpackingPrimitives::GetRequiredSize(current_segment->count, current_width);
400149 auto index_buffer_size = index_buffer.size() *
sizeof(
uint32_t);
400151 index_buffer_size + current_dictionary.size;
400152
400153
400154 auto base_ptr = handle.Ptr();
400155 auto header_ptr = reinterpret_cast<dictionary_compression_header_t *>(base_ptr);
400157 auto index_buffer_offset = compressed_selection_buffer_offset + compressed_selection_buffer_size;
400158
400159
400160 BitpackingPrimitives::PackBuffer<sel_t, false>(base_ptr + compressed_selection_buffer_offset,
400161 (
sel_t *)(selection_buffer.data()), current_segment->count,
400162 current_width);
400163
400164
400165 memcpy(base_ptr + index_buffer_offset, index_buffer.data(), index_buffer_size);
400166
400167
400168 Store<uint32_t>(NumericCast<uint32_t>(index_buffer_offset), data_ptr_cast(&header_ptr->index_buffer_offset));
400169 Store<uint32_t>(NumericCast<uint32_t>(index_buffer.size()), data_ptr_cast(&header_ptr->index_buffer_count));
400170 Store<uint32_t>((uint32_t)current_width, data_ptr_cast(&header_ptr->bitpacking_width));
400171
400172 D_ASSERT(current_width == BitpackingPrimitives::MinimumBitWidth(index_buffer.size() - 1));
400173 D_ASSERT(DictionaryCompression::HasEnoughSpace(current_segment->count, index_buffer.size(), current_dictionary.size,
400174 current_width, info.GetBlockSize()));
400175 D_ASSERT((uint64_t)*max_element(std::begin(selection_buffer), std::end(selection_buffer)) ==
400176 index_buffer.size() - 1);
400177
400178
400179 if (total_size >= info.GetCompactionFlushLimit()) {
400180 return info.GetBlockSize();
400181 }
400182
400183
400184 auto move_amount = info.GetBlockSize() - total_size;
400185
400186
400187 auto new_dictionary_offset = index_buffer_offset + index_buffer_size;
400188 memmove(base_ptr + new_dictionary_offset, base_ptr + current_dictionary.end - current_dictionary.size,
400189 current_dictionary.size);
400190 current_dictionary.end -= move_amount;
400191 D_ASSERT(current_dictionary.end == total_size);
400192
400193
400194 DictionaryCompression::SetDictionary(*current_segment, handle, current_dictionary);
400195 return total_size;
400196}
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251
static constexpr uint16_t DICTIONARY_HEADER_SIZE
Dictionary header size at the beginning of the string segment (offset + length).
Definition duckdb.cpp:399725