xiaokang commented on code in PR #33890: URL: https://github.com/apache/doris/pull/33890#discussion_r1597340669
########## be/src/vec/columns/column_object.cpp: ########## @@ -808,6 +876,33 @@ const ColumnObject::Subcolumn* ColumnObject::get_subcolumn(const PathInData& key return &node->data; } +const ColumnObject::Subcolumn* ColumnObject::get_subcolumn_with_cache(const PathInData& key, + size_t key_index) const { + // Optimization by caching the order of fields (which is almost always the same) + // and a quick check to match the next expected field, instead of searching the hash table. + if (_prev_positions.size() > key_index && _prev_positions[key_index].second != nullptr && + key == _prev_positions[key_index].first) { + return _prev_positions[key_index].second; + } + const auto* subcolumn = get_subcolumn(key); + if (key_index >= _prev_positions.size()) { + _prev_positions.resize(key_index + 1); + } + if (subcolumn != nullptr) { + _prev_positions[key_index] = std::make_pair(key, subcolumn); + } + return subcolumn; +} + +ColumnObject::Subcolumn* ColumnObject::get_subcolumn(const PathInData& key, size_t key_index) { Review Comment: Where is this new function used? ########## be/src/vec/columns/column_object.cpp: ########## @@ -220,20 +281,30 @@ class FieldVisitorToScalarType : public StaticVisitor<size_t> { }; } // namespace -void get_field_info(const Field& field, FieldInfo* info) { - FieldVisitorToScalarType to_scalar_type_visitor; + +template <typename Visitor> +void get_field_info_impl(const Field& field, FieldInfo* info) { + Visitor to_scalar_type_visitor; apply_visitor(to_scalar_type_visitor, field); - DataTypePtr type = nullptr; - to_scalar_type_visitor.get_scalar_type(&type); + TypeIndex type_id; + to_scalar_type_visitor.get_scalar_type(&type_id); // array item's dimension may missmatch, eg. [1, 2, [1, 2, 3]] *info = { - type, + type_id, to_scalar_type_visitor.contain_nulls(), to_scalar_type_visitor.need_convert_field(), apply_visitor(FieldVisitorToNumberOfDimensions(), field), }; } +void get_field_info(const Field& field, FieldInfo* info) { + if (field.is_complex_field()) { + get_field_info_impl<FieldVisitorToScalarType>(field, info); + } else { + get_field_info_impl<SimpleFieldVisitorToScalarType>(field, info); Review Comment: Is there any opt for SimpleFieldVisitorToScalarType? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org