@@ -84,11 +84,31 @@ idx_t CompressionFunctionSet::GetCompressionIndex(CompressionType type) {
8484}
8585
8686CompressionFunctionSet::CompressionFunctionSet () {
87- for (idx_t i = 0 ; i < PHYSICAL_TYPE_COUNT; i++) {
88- is_loaded[i] = false ;
89- }
9087 ResetDisabledMethods ();
9188 functions.resize (PHYSICAL_TYPE_COUNT);
89+
90+ static PhysicalType physical_types[PHYSICAL_TYPE_COUNT] = {
91+ PhysicalType::BOOL, PhysicalType::UINT8, PhysicalType::INT8, PhysicalType::UINT16, PhysicalType::INT16,
92+ PhysicalType::UINT32, PhysicalType::INT32, PhysicalType::UINT64, PhysicalType::INT64, PhysicalType::FLOAT,
93+ PhysicalType::DOUBLE, PhysicalType::INTERVAL, PhysicalType::LIST, PhysicalType::STRUCT, PhysicalType::ARRAY,
94+ PhysicalType::VARCHAR, PhysicalType::UINT128, PhysicalType::INT128, PhysicalType::BIT,
95+ };
96+ for (idx_t type_index = 0 ; type_index < PHYSICAL_TYPE_COUNT; type_index++) {
97+ const auto physical_type = physical_types[type_index];
98+ const auto index = GetCompressionIndex (physical_type);
99+ auto &function_list = functions[index];
100+
101+ for (idx_t method_index = 0 ; internal_compression_methods[method_index].get_function ; method_index++) {
102+ auto &method = internal_compression_methods[method_index];
103+ if (!method.supports_type (physical_type)) {
104+ // Not supported for this type.
105+ continue ;
106+ }
107+ // The type is supported.
108+ // We create the function and insert it into the set of available functions.
109+ function_list.push_back (method.get_function (physical_type));
110+ }
111+ }
92112}
93113
94114bool EmitCompressionFunction (CompressionType type) {
@@ -113,14 +133,12 @@ bool EmitCompressionFunction(CompressionType type) {
113133
114134vector<reference<const CompressionFunction>>
115135CompressionFunctionSet::GetCompressionFunctions (PhysicalType physical_type) {
116- LoadCompressionFunctions (physical_type);
117- auto index = GetCompressionIndex (physical_type);
136+ const auto index = GetCompressionIndex (physical_type);
118137 auto &function_list = functions[index];
119138 vector<reference<const CompressionFunction>> result;
120139 for (auto &entry : function_list) {
121- auto compression_index = GetCompressionIndex (entry.type );
140+ const auto compression_index = GetCompressionIndex (entry.type );
122141 if (is_disabled[compression_index]) {
123- // explicitly disabled
124142 continue ;
125143 }
126144 if (!EmitCompressionFunction (entry.type )) {
@@ -131,50 +149,22 @@ CompressionFunctionSet::GetCompressionFunctions(PhysicalType physical_type) {
131149 return result;
132150}
133151
134- CompressionFunctionSetLoadResult CompressionFunctionSet::LoadCompressionFunctions (PhysicalType physical_type) {
135- auto index = GetCompressionIndex (physical_type);
136- if (is_loaded[index]) {
137- return CompressionFunctionSetLoadResult::ALREADY_LOADED_BEFORE_LOCK;
138- }
139- // not loaded - try to load it
140- lock_guard<mutex> guard (lock);
141- // verify nobody loaded it in the mean-time
142- if (is_loaded[index]) {
143- return CompressionFunctionSetLoadResult::ALREADY_LOADED_AFTER_LOCK;
144- }
145- // actually perform the load
146- auto &function_list = functions[index];
147- for (idx_t i = 0 ; internal_compression_methods[i].get_function ; i++) {
148- auto &method = internal_compression_methods[i];
149- if (!method.supports_type (physical_type)) {
150- // not supported for this type
151- continue ;
152- }
153- // The type is supported. We create the function and insert it into the set of available functions.
154- function_list.push_back (method.get_function (physical_type));
155- }
156- is_loaded[index] = true ;
157- return CompressionFunctionSetLoadResult::LAZILY_LOADED;
158- }
159-
160- pair<CompressionFunctionSetLoadResult, optional_ptr<const CompressionFunction>>
152+ optional_ptr<const CompressionFunction>
161153CompressionFunctionSet::GetCompressionFunction (CompressionType type, const PhysicalType physical_type) {
162- const auto load_result = LoadCompressionFunctions (physical_type);
163-
164154 const auto index = GetCompressionIndex (physical_type);
165155 const auto &function_list = functions[index];
166156 for (auto &function : function_list) {
167157 if (function.type == type) {
168- return make_pair (load_result, &function) ;
158+ return &function;
169159 }
170160 }
171- return make_pair (load_result, nullptr ) ;
161+ return nullptr ;
172162}
173163
174164void CompressionFunctionSet::SetDisabledCompressionMethods (const vector<CompressionType> &methods) {
175165 ResetDisabledMethods ();
176166 for (auto &method : methods) {
177- auto idx = GetCompressionIndex (method);
167+ const auto idx = GetCompressionIndex (method);
178168 is_disabled[idx] = true ;
179169 }
180170}
@@ -193,55 +183,6 @@ vector<CompressionType> CompressionFunctionSet::GetDisabledCompressionMethods()
193183 return result;
194184}
195185
196- string CompressionFunctionSet::GetDebugInfo () const {
197- static PhysicalType physical_types[PHYSICAL_TYPE_COUNT] = {
198- PhysicalType::BOOL, PhysicalType::UINT8, PhysicalType::INT8, PhysicalType::UINT16, PhysicalType::INT16,
199- PhysicalType::UINT32, PhysicalType::INT32, PhysicalType::UINT64, PhysicalType::INT64, PhysicalType::FLOAT,
200- PhysicalType::DOUBLE, PhysicalType::INTERVAL, PhysicalType::LIST, PhysicalType::STRUCT, PhysicalType::ARRAY,
201- PhysicalType::VARCHAR, PhysicalType::UINT128, PhysicalType::INT128, PhysicalType::BIT,
202- };
203-
204- vector<string> compression_type_debug_infos;
205- for (idx_t i = 0 ; i < COMPRESSION_TYPE_COUNT; i++) {
206- compression_type_debug_infos.push_back (
207- StringUtil::Format (" %llu: {compression type: %s, is disabled: %llu}" , i,
208- EnumUtil::ToString (internal_compression_methods[i].type ), is_disabled[i].load ()));
209- }
210-
211- lock_guard<mutex> guard (lock);
212- vector<string> physical_type_debug_infos;
213- for (idx_t index = 0 ; index < PHYSICAL_TYPE_COUNT; index++) {
214- const auto &physical_type = physical_types[index];
215- D_ASSERT (GetCompressionIndex (physical_type) == index);
216-
217- idx_t out_of = 0 ;
218- for (idx_t i = 0 ; internal_compression_methods[i].get_function ; i++) {
219- auto &method = internal_compression_methods[i];
220- if (method.supports_type (physical_type)) {
221- out_of++;
222- }
223- }
224-
225- const auto &function_list = functions[index];
226- vector<string> function_list_debug_infos;
227- for (idx_t function_index = 0 ; function_index < function_list.size (); function_index++) {
228- auto &function = function_list[function_index];
229- function_list_debug_infos.push_back (StringUtil::Format (" %llu: {compression type: %s, physical type: %s}" ,
230- function_index, EnumUtil::ToString (function.type ),
231- EnumUtil::ToString (function.data_type )));
232- }
233-
234- physical_type_debug_infos.push_back (StringUtil::Format (
235- " %llu: {physical type: %s, loaded: %llu, loaded functions: %llu (out of: %llu)}\t\t %s" , index,
236- EnumUtil::ToString (physical_type), is_loaded[index].load (), function_list.size (), out_of,
237- function_list_debug_infos.empty () ? " " : " \n\t\t " + StringUtil::Join (function_list_debug_infos, " \n\t\t " )));
238- }
239-
240- return StringUtil::Format (" DEBUG INFO:\n - Compression types:\n\t %s\n\n - Physical types:\n\t %s" ,
241- StringUtil::Join (compression_type_debug_infos, " \n\t " ),
242- StringUtil::Join (physical_type_debug_infos, " \n\t " ));
243- }
244-
245186vector<CompressionType> DBConfig::GetDisabledCompressionMethods () const {
246187 return compression_functions->GetDisabledCompressionMethods ();
247188}
@@ -258,18 +199,17 @@ vector<reference<const CompressionFunction>> DBConfig::GetCompressionFunctions(c
258199
259200optional_ptr<const CompressionFunction> DBConfig::TryGetCompressionFunction (CompressionType type,
260201 const PhysicalType physical_type) const {
261- return compression_functions->GetCompressionFunction (type, physical_type). second ;
202+ return compression_functions->GetCompressionFunction (type, physical_type);
262203}
263204
264205reference<const CompressionFunction> DBConfig::GetCompressionFunction (CompressionType type,
265206 const PhysicalType physical_type) const {
266207 auto result = compression_functions->GetCompressionFunction (type, physical_type);
267- if (!result. second ) {
208+ if (!result) {
268209 throw InternalException (
269210 " Could not find compression function \" %s\" for physical type \" %s\" . Load result: %s. %s" ,
270- EnumUtil::ToString (type), EnumUtil::ToString (physical_type), EnumUtil::ToString (result.first ),
271- compression_functions->GetDebugInfo ());
211+ EnumUtil::ToString (type), EnumUtil::ToString (physical_type));
272212 }
273- return *result. second ;
213+ return *result;
274214}
275215} // namespace duckdb
0 commit comments