This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new fa8df1b84db branch-3.0: [Fix](ShortCircuit) need to shrink char type when read column store #50975 (#51332) fa8df1b84db is described below commit fa8df1b84db37e82efafc78e8eb1ece8c55ee7e3 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Wed Jun 11 10:38:06 2025 +0800 branch-3.0: [Fix](ShortCircuit) need to shrink char type when read column store #50975 (#51332) Cherry-picked from #50975 --------- Co-authored-by: lihangyu <lihan...@selectdb.com> --- be/src/olap/tablet_schema.cpp | 19 +++++++++++ be/src/olap/tablet_schema.h | 1 + be/src/service/point_query_executor.cpp | 11 ++++-- be/test/olap/storage_types_test.cpp | 38 +++++++++++++++++++++ .../data/point_query_p0/test_point_query.out | Bin 9920 -> 9934 bytes .../suites/point_query_p0/test_point_query.groovy | 21 +++++++++++- 6 files changed, 86 insertions(+), 4 deletions(-) diff --git a/be/src/olap/tablet_schema.cpp b/be/src/olap/tablet_schema.cpp index 947d6452b67..43a2a034722 100644 --- a/be/src/olap/tablet_schema.cpp +++ b/be/src/olap/tablet_schema.cpp @@ -37,6 +37,7 @@ #include "common/status.h" #include "exec/tablet_info.h" #include "olap/inverted_index_parser.h" +#include "olap/olap_common.h" #include "olap/olap_define.h" #include "olap/tablet_column_object_pool.h" #include "olap/types.h" @@ -49,6 +50,8 @@ #include "vec/core/block.h" #include "vec/data_types/data_type.h" #include "vec/data_types/data_type_factory.hpp" +#include "vec/data_types/data_type_map.h" +#include "vec/data_types/data_type_struct.h" #include "vec/json/path_in_data.h" namespace doris { @@ -460,6 +463,22 @@ uint32_t TabletColumn::get_field_length_by_type(TPrimitiveType::type type, uint3 } } +bool TabletColumn::has_char_type() const { + switch (_type) { + case FieldType::OLAP_FIELD_TYPE_CHAR: { + return true; + } + case FieldType::OLAP_FIELD_TYPE_ARRAY: + case FieldType::OLAP_FIELD_TYPE_MAP: + case FieldType::OLAP_FIELD_TYPE_STRUCT: { + return std::any_of(_sub_columns.begin(), _sub_columns.end(), + [&](const auto& sub) -> bool { return sub->has_char_type(); }); + } + default: + return false; + } +} + TabletColumn::TabletColumn() : _aggregation(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE) {} TabletColumn::TabletColumn(FieldAggregationMethod agg, FieldType type) { diff --git a/be/src/olap/tablet_schema.h b/be/src/olap/tablet_schema.h index 41eb8ccd1e3..ce114bf80f5 100644 --- a/be/src/olap/tablet_schema.h +++ b/be/src/olap/tablet_schema.h @@ -131,6 +131,7 @@ public: int precision() const { return _precision; } int frac() const { return _frac; } inline bool visible() const { return _visible; } + bool has_char_type() const; void set_aggregation_method(FieldAggregationMethod agg) { _aggregation = agg; diff --git a/be/src/service/point_query_executor.cpp b/be/src/service/point_query_executor.cpp index ee03495ffbd..73b34f2df7b 100644 --- a/be/src/service/point_query_executor.cpp +++ b/be/src/service/point_query_executor.cpp @@ -502,9 +502,14 @@ Status PointQueryExecutor::_lookup_row_data() { vectorized::MutableColumnPtr column = _result_block->get_by_position(pos).column->assume_mutable(); std::unique_ptr<ColumnIterator> iter; - RETURN_IF_ERROR(segment->seek_and_read_by_rowid( - *_tablet->tablet_schema(), _reusable->tuple_desc()->slots()[pos], row_id, - column, _read_stats, iter)); + SlotDescriptor* slot = _reusable->tuple_desc()->slots()[pos]; + RETURN_IF_ERROR(segment->seek_and_read_by_rowid(*_tablet->tablet_schema(), slot, + row_id, column, _read_stats, iter)); + if (_tablet->tablet_schema() + ->column_by_uid(slot->col_unique_id()) + .has_char_type()) { + _result_block->get_by_position(pos).column = column->get_shrinked_column(); + } } } } diff --git a/be/test/olap/storage_types_test.cpp b/be/test/olap/storage_types_test.cpp index ab7b80a18f8..1eba8796c2d 100644 --- a/be/test/olap/storage_types_test.cpp +++ b/be/test/olap/storage_types_test.cpp @@ -239,4 +239,42 @@ TEST(ArrayTypeTest, copy_and_equal) { CollectionValue(char_array, 3, null_signs)); } +TEST(TypesTest, has_char_type) { + // Test basic types + TabletColumn char_column(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_CHAR); + EXPECT_TRUE(char_column.has_char_type()); + + TabletColumn int_column(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_INT); + EXPECT_FALSE(int_column.has_char_type()); + + // Test array type with char element + TabletColumn array_column(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_ARRAY); + TabletColumn array_element(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_CHAR); + array_column.add_sub_column(array_element); + EXPECT_TRUE(array_column.has_char_type()); + + // Test array type with non-char element + TabletColumn array_column2(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_ARRAY); + TabletColumn array_element2(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_INT); + array_column2.add_sub_column(array_element2); + EXPECT_FALSE(array_column2.has_char_type()); + + // Test nested array with char element + TabletColumn nested_array(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_ARRAY); + TabletColumn inner_array(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_ARRAY); + TabletColumn char_element(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, + FieldType::OLAP_FIELD_TYPE_CHAR); + inner_array.add_sub_column(char_element); + nested_array.add_sub_column(inner_array); + EXPECT_TRUE(nested_array.has_char_type()); +} + } // namespace doris diff --git a/regression-test/data/point_query_p0/test_point_query.out b/regression-test/data/point_query_p0/test_point_query.out index 75822c3cf88..8572ed52a68 100644 Binary files a/regression-test/data/point_query_p0/test_point_query.out and b/regression-test/data/point_query_p0/test_point_query.out differ diff --git a/regression-test/suites/point_query_p0/test_point_query.groovy b/regression-test/suites/point_query_p0/test_point_query.groovy index f2b22064d9c..fbf96d9f478 100644 --- a/regression-test/suites/point_query_p0/test_point_query.groovy +++ b/regression-test/suites/point_query_p0/test_point_query.groovy @@ -425,4 +425,23 @@ suite("test_point_query", "nonConcurrent") { assertNotEquals(result1, result2) } } -} \ No newline at end of file + // test shrink char type + sql "DROP TABLE IF EXISTS table_with_chars" + sql """ + CREATE TABLE `table_with_chars` ( + `col1` smallint NOT NULL, + `col2` int NOT NULL, + `loc3` char(10) NOT NULL, + `value` char(10) NOT NULL, + INDEX col3 (`loc3`) USING INVERTED, + INDEX col2 (`col2`) USING INVERTED ) + ENGINE=OLAP UNIQUE KEY(`col1`) + DISTRIBUTED BY HASH(`col1`) BUCKETS 1 + PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "bloom_filter_columns" = "col1", "row_store_columns" = "col1", "enable_mow_light_delete" = "false" ); + """ + sql "insert into table_with_chars values (-10, 20, 'aabc', 'value')" + sql "insert into table_with_chars values (10, 20, 'aabc', 'value');" + sql "insert into table_with_chars values (20, 30, 'aabc', 'value');" + sql "set enable_short_circuit_query = true" + qt_sql "select length(loc3) from table_with_chars where col1 = 10" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org