This is an automated email from the ASF dual-hosted git repository. lihaopeng pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 66f3ef568e (functions) optimize const_column to full convert 66f3ef568e is described below commit 66f3ef568ebbf87e9b7464bee70bb254f75ad2c2 Author: ZhaoChangle <zhaochan...@selectdb.com> AuthorDate: Wed Mar 15 10:57:03 2023 +0800 (functions) optimize const_column to full convert --- be/src/vec/functions/comparison_equal_for_null.cpp | 1 + be/src/vec/functions/function_bitmap.cpp | 9 ++++----- be/src/vec/functions/function_bitmap_min_or_max.h | 3 +-- be/src/vec/functions/function_hex.cpp | 3 +-- be/src/vec/functions/function_reverse.h | 3 +-- be/src/vec/functions/function_timestamp.cpp | 5 ++--- be/src/vec/functions/function_totype.h | 3 +-- be/src/vec/functions/function_utility.cpp | 3 +-- be/src/vec/functions/functions_geo.cpp | 17 +++++++---------- .../aggregate_functions/test_aggregate_collect.out | 14 ++++++++++++++ .../aggregate_functions/test_aggregate_collect.groovy | 4 ++-- 11 files changed, 35 insertions(+), 30 deletions(-) diff --git a/be/src/vec/functions/comparison_equal_for_null.cpp b/be/src/vec/functions/comparison_equal_for_null.cpp index c7aa595925..e7e40be15b 100644 --- a/be/src/vec/functions/comparison_equal_for_null.cpp +++ b/be/src/vec/functions/comparison_equal_for_null.cpp @@ -22,6 +22,7 @@ #include "vec/utils/util.hpp" namespace doris::vectorized { +//TODO: add manual info to docs. class FunctionEqForNull : public IFunction { public: static constexpr auto name = "eq_for_null"; diff --git a/be/src/vec/functions/function_bitmap.cpp b/be/src/vec/functions/function_bitmap.cpp index 4350d3b256..6cb254fe3b 100644 --- a/be/src/vec/functions/function_bitmap.cpp +++ b/be/src/vec/functions/function_bitmap.cpp @@ -272,8 +272,7 @@ public: auto& null_map = res_null_map->get_data(); auto& res = res_data_column->get_data(); - ColumnPtr argument_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + ColumnPtr& argument_column = block.get_by_position(arguments[0]).column; if constexpr (std::is_same_v<typename Impl::ArgumentType, DataTypeString>) { const auto& str_column = static_cast<const ColumnString&>(*argument_column); const ColumnString::Chars& data = str_column.get_chars(); @@ -413,7 +412,7 @@ public: auto data_null_map = ColumnUInt8::create(input_rows_count, 0); auto& null_map = data_null_map->get_data(); - auto column = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + auto& column = block.get_by_position(arguments[0]).column; if (auto* nullable = check_and_get_column<const ColumnNullable>(*column)) { VectorizedUtils::update_null_map(null_map, nullable->get_null_map_data()); column = nullable->get_nested_column_ptr(); @@ -731,6 +730,7 @@ public: size_t get_number_of_arguments() const override { return 1; } bool use_default_implementation_for_nulls() const override { return true; } + bool use_default_implementation_for_constants() const override { return true; } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { @@ -744,8 +744,7 @@ public: dest_nested_column = dest_nested_nullable_col->get_nested_column_ptr(); auto& dest_nested_null_map = dest_nested_nullable_col->get_null_map_column().get_data(); - auto arg_col = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + auto& arg_col = block.get_by_position(arguments[0]).column; auto bitmap_col = assert_cast<const ColumnBitmap*>(arg_col.get()); const auto& bitmap_col_data = bitmap_col->get_data(); auto& nested_column_data = diff --git a/be/src/vec/functions/function_bitmap_min_or_max.h b/be/src/vec/functions/function_bitmap_min_or_max.h index 7b6d738f0c..788f8222a5 100644 --- a/be/src/vec/functions/function_bitmap_min_or_max.h +++ b/be/src/vec/functions/function_bitmap_min_or_max.h @@ -56,8 +56,7 @@ public: auto result_column = ColumnInt64::create(); auto result_null_map_column = ColumnUInt8::create(input_rows_count, 0); - ColumnPtr argument_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + ColumnPtr& argument_column = block.get_by_position(arguments[0]).column; if (auto* nullable = check_and_get_column<ColumnNullable>(*argument_column)) { // Danger: Here must dispose the null map data first! Because // argument_columns[i]=nullable->get_nested_column_ptr(); will release the mem diff --git a/be/src/vec/functions/function_hex.cpp b/be/src/vec/functions/function_hex.cpp index 4402706e86..4fd69581c3 100644 --- a/be/src/vec/functions/function_hex.cpp +++ b/be/src/vec/functions/function_hex.cpp @@ -46,8 +46,7 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { - ColumnPtr argument_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + ColumnPtr& argument_column = block.get_by_position(arguments[0]).column; auto result_data_column = ColumnString::create(); auto& result_data = result_data_column->get_chars(); diff --git a/be/src/vec/functions/function_reverse.h b/be/src/vec/functions/function_reverse.h index f60a390256..98bfb41d3a 100644 --- a/be/src/vec/functions/function_reverse.h +++ b/be/src/vec/functions/function_reverse.h @@ -45,8 +45,7 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { - ColumnPtr src_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + ColumnPtr& src_column = block.get_by_position(arguments[0]).column; if (const ColumnString* col_string = check_and_get_column<ColumnString>(src_column.get())) { auto col_res = ColumnString::create(); ReverseImpl::vector(col_string->get_chars(), col_string->get_offsets(), diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 397b9f4fac..af34c6911f 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -313,7 +313,7 @@ public: String get_name() const override { return name; } - bool use_default_implementation_for_constants() const override { return false; } + bool use_default_implementation_for_constants() const override { return true; } size_t get_number_of_arguments() const override { return 1; } @@ -327,8 +327,7 @@ public: size_t result, size_t input_rows_count) override { auto null_map = ColumnUInt8::create(input_rows_count, 0); - ColumnPtr argument_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + ColumnPtr& argument_column = block.get_by_position(arguments[0]).column; auto data_col = assert_cast<const ColumnVector<Int32>*>(argument_column.get()); ColumnPtr res_column; diff --git a/be/src/vec/functions/function_totype.h b/be/src/vec/functions/function_totype.h index 95cb34eaaa..bc16e066f8 100644 --- a/be/src/vec/functions/function_totype.h +++ b/be/src/vec/functions/function_totype.h @@ -423,8 +423,7 @@ public: size_t result, size_t input_rows_count) override { auto null_map = ColumnUInt8::create(input_rows_count, 0); - auto col_ptr = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + auto& col_ptr = block.get_by_position(arguments[0]).column; auto res = Impl::ColumnType::create(); if (const ColumnString* col = check_and_get_column<ColumnString>(col_ptr.get())) { diff --git a/be/src/vec/functions/function_utility.cpp b/be/src/vec/functions/function_utility.cpp index d21f25bcf6..886ed762c1 100644 --- a/be/src/vec/functions/function_utility.cpp +++ b/be/src/vec/functions/function_utility.cpp @@ -44,8 +44,7 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { - ColumnPtr argument_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + ColumnPtr& argument_column = block.get_by_position(arguments[0]).column; auto res_column = ColumnUInt8::create(); diff --git a/be/src/vec/functions/functions_geo.cpp b/be/src/vec/functions/functions_geo.cpp index d7fc9d0af4..bae8e162a4 100644 --- a/be/src/vec/functions/functions_geo.cpp +++ b/be/src/vec/functions/functions_geo.cpp @@ -78,10 +78,9 @@ struct StAsText { DCHECK_EQ(arguments.size(), 1); auto return_type = remove_nullable(block.get_data_type(result)); - auto input = block.get_by_position(arguments[0]).column; + auto& input = block.get_by_position(arguments[0]).column; auto size = input->size(); - auto col = input->convert_to_full_column_if_const(); MutableColumnPtr res = nullptr; auto null_type = std::reinterpret_pointer_cast<const DataTypeNullable>(return_type); @@ -89,7 +88,7 @@ struct StAsText { std::unique_ptr<GeoShape> shape; for (int row = 0; row < size; ++row) { - auto shape_value = col->get_data_at(row); + auto shape_value = input->get_data_at(row); shape.reset(GeoShape::from_encoded(shape_value.data, shape_value.size)); if (shape == nullptr) { @@ -113,10 +112,9 @@ struct StX { DCHECK_EQ(arguments.size(), 1); auto return_type = remove_nullable(block.get_data_type(result)); - auto input = block.get_by_position(arguments[0]).column; + auto& input = block.get_by_position(arguments[0]).column; auto size = input->size(); - auto col = input->convert_to_full_column_if_const(); MutableColumnPtr res = nullptr; auto null_type = std::reinterpret_pointer_cast<const DataTypeNullable>(return_type); @@ -124,7 +122,7 @@ struct StX { GeoPoint point; for (int row = 0; row < size; ++row) { - auto point_value = col->get_data_at(row); + auto point_value = input->get_data_at(row); auto pt = point.decode_from(point_value.data, point_value.size); if (!pt) { @@ -148,10 +146,9 @@ struct StY { DCHECK_EQ(arguments.size(), 1); auto return_type = remove_nullable(block.get_data_type(result)); - auto input = block.get_by_position(arguments[0]).column; + auto& input = block.get_by_position(arguments[0]).column; auto size = input->size(); - auto col = input->convert_to_full_column_if_const(); MutableColumnPtr res = nullptr; auto null_type = std::reinterpret_pointer_cast<const DataTypeNullable>(return_type); @@ -159,7 +156,7 @@ struct StY { GeoPoint point; for (int row = 0; row < size; ++row) { - auto point_value = col->get_data_at(row); + auto point_value = input->get_data_at(row); auto pt = point.decode_from(point_value.data, point_value.size); if (!pt) { @@ -352,7 +349,7 @@ struct StGeoFromText { size_t result) { DCHECK_EQ(arguments.size(), 1); auto return_type = remove_nullable(block.get_data_type(result)); - auto geo = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + auto& geo = block.get_by_position(arguments[0]).column; const auto size = geo->size(); auto null_type = std::reinterpret_pointer_cast<const DataTypeNullable>(return_type); diff --git a/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out index 4333dfa9ac..4bcd69e049 100644 --- a/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out +++ b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out @@ -5,6 +5,20 @@ -- !select -- 1 1 1 1 1 3 1 2 1 1 1 1 1 2 1 1 1 +-- !select -- +1 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N not null +1 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N not null +1 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N not null +1 false 10 20 30 4444444444444 55555555555 0.1 0.222 3333.33 c varchar1 string1 2022-12-01 2022-12-01 2022-12-01T22:23:23 2022-12-01T22:23:24.999999 not null +1 false 11 21 33 4444444444444 55555555555 0.1 0.222 3333.33 c varchar1 string1 2022-12-01 2022-12-01 2022-12-01T22:23:23 2022-12-01T22:23:24.999999 not null +1 true 11 12 13 1444444444444 1555555555 1.1 1.222 13333.33 d varchar2 string2 2022-12-02 2022-12-02 2022-12-02T22:23:23 2022-12-02T22:23:24.999999 not null +2 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N not null +2 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N not null +2 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N not null +2 false 10 20 30 944444444444 9555555555 9.1 9.222 93333.33 p varchar9 string9 2022-12-09 2022-12-09 2022-12-09T22:23:23 2022-12-09T22:23:24.999999 not null +2 false 21 22 23 2444444444444 255555555 2.1 2.222 23333.33 f varchar3 string3 2022-12-03 2022-12-03 2022-12-03T22:23:23 2022-12-03T22:23:24.999999 not null +2 true 31 32 33 3444444444444 3555555555 3.1 3.222 33333.33 l varchar3 string3 2022-12-03 2022-12-03 2022-12-03T22:23:23 2022-12-03T22:23:24.999999 not null + -- !select -- 1 1 1 1 1 3 1 2 1 1 1 1 1 2 1 1 1 diff --git a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy index f2b19a7e4a..972b04eeb4 100644 --- a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy +++ b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy @@ -402,8 +402,8 @@ suite("test_aggregate_collect") { '2022-12-09', '2022-12-09', '2022-12-09 22:23:23', '2022-12-09 22:23:24.999999', 'not null') """ - sql """ - SELECT * FROM ${tableName_11} + qt_select """ + SELECT * FROM ${tableName_11} ORDER BY c_id, c_tinyint, c_char; """ sql """ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org