We can uncompress during fetching, we need the length of the string inside the dictionary
399251 {
399252 baseptr = handle->Ptr() + segment.GetBlockOffset();
399253
399254
399255 auto header_ptr =
reinterpret_cast<dict_fsst_compression_header_t *
>(
baseptr);
399256 mode = header_ptr->mode;
399257 if (mode >= DictFSSTMode::COUNT) {
399258 throw FatalException("This block was written with a mode that is not recognized by this version, highest "
399259 "available mode %d, found mode: %d",
399260 static_cast<uint8_t>(DictFSSTMode::COUNT),
static_cast<uint8_t>(mode));
399261 }
399262
399263 dict_count = header_ptr->dict_count;
399264 auto symbol_table_size = header_ptr->symbol_table_size;
399265 dictionary_size = header_ptr->dict_size;
399266
399267 dictionary_indices_width =
399268 (bitpacking_width_t)(Load<uint8_t>(data_ptr_cast(&header_ptr->dictionary_indices_width)));
399269 string_lengths_width = (bitpacking_width_t)(Load<uint8_t>(data_ptr_cast(&header_ptr->string_lengths_width)));
399270
399271 auto string_lengths_space = BitpackingPrimitives::GetRequiredSize(dict_count, string_lengths_width);
399272 auto dictionary_indices_space =
399273 BitpackingPrimitives::GetRequiredSize(segment.count.load(), dictionary_indices_width);
399274
399276 auto symbol_table_dest =
AlignValue<idx_t>(dictionary_dest + dictionary_size);
399277 auto string_lengths_dest =
AlignValue<idx_t>(symbol_table_dest + symbol_table_size);
399278 auto dictionary_indices_dest =
AlignValue<idx_t>(string_lengths_dest + string_lengths_space);
399279
399280 const auto total_space = segment.GetBlockOffset() + dictionary_indices_dest + dictionary_indices_space;
399281 if (total_space > segment.GetBlockSize()) {
399282 throw IOException(
399283 "Failed to scan dictionary string - index was out of range. Database file appears to be corrupted.");
399284 }
399285 dict_ptr = data_ptr_cast(
baseptr + dictionary_dest);
399286 dictionary_indices_ptr = data_ptr_cast(
baseptr + dictionary_indices_dest);
399287 string_lengths_ptr = data_ptr_cast(
baseptr + string_lengths_dest);
399288
399289 switch (mode) {
399290 case DictFSSTMode::FSST_ONLY:
399291 case DictFSSTMode::DICT_FSST: {
399292 decoder = new duckdb_fsst_decoder_t;
399293 auto ret = duckdb_fsst_import(
reinterpret_cast<duckdb_fsst_decoder_t *
>(decoder),
baseptr + symbol_table_dest);
399294 (void)(ret);
399295 D_ASSERT(ret != 0);
399296 break;
399297 }
399298 default:
399299 break;
399300 }
399301
399303 BitpackingPrimitives::UnPackBuffer<uint32_t>(data_ptr_cast(string_lengths.data()),
399304 data_ptr_cast(string_lengths_ptr), dict_count, string_lengths_width);
399305 if (!initialize_dictionary || mode == DictFSSTMode::FSST_ONLY) {
399306
399307 return;
399308 }
399309
399310 dictionary = DictionaryVector::CreateReusableDictionary(segment.type, dict_count);
399311 auto dict_child_data = FlatVector::GetData<string_t>(dictionary->data);
399312 auto &validity = FlatVector::Validity(dictionary->data);
399313 D_ASSERT(dict_count >= 1);
399314 validity.SetInvalid(0);
399315
399316 auto &dict_data = dictionary->data;
399318 for (uint32_t i = 0; i < dict_count; i++) {
399320 auto string_len = string_lengths[i];
399321 dict_child_data[i] = FetchStringFromDict(dict_data, offset, i);
399322 offset += string_len;
399323 }
399324}
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
data_ptr_t baseptr
Start of the block (pointing to the dictionary_header).
Definition duckdb.cpp:399195
static constexpr uint16_t DICTIONARY_HEADER_SIZE
Dictionary header size at the beginning of the string segment (offset + length).
Definition duckdb.cpp:397835