This is an automated email from the ASF dual-hosted git repository.
zhangstar333 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 6873adb44a7 [Bug](exec) Fix min max push agg error read char column
(#60365)
6873adb44a7 is described below
commit 6873adb44a74780d5c1fc29163a0b3870422c168
Author: HappenLee <[email protected]>
AuthorDate: Tue Feb 3 15:08:35 2026 +0800
[Bug](exec) Fix min max push agg error read char column (#60365)
### What problem does this PR solve?
```
mysql> set disable_nereids_rules='';
Query OK, 0 rows affected (0.00 sec)
mysql> select length(min(b)) from t;
+----------------+
| length(min(b)) |
+----------------+
| 10 |
+----------------+
1 row in set (0.01 sec)
mysql> set disable_nereids_rules=ELIMINATE_NOT_NULL;
Query OK, 0 rows affected (0.01 sec)
mysql> select length(min(b)) from t;
+----------------+
| length(min(b)) |
+----------------+
| 3 |
+----------------+
1 row in set (0.02 sec)
```
---
be/src/olap/rowset/segment_v2/column_reader.cpp | 6 ++++++
be/src/pipeline/exec/cache_source_operator.h | 4 ++--
be/src/vec/common/string_ref.cpp | 11 +++++++++++
be/src/vec/common/string_ref.h | 1 +
.../data/query_p0/aggregate/support_type/max/max.out | 2 +-
.../data/query_p0/aggregate/support_type/min/min.out | 5 ++++-
.../suites/query_p0/aggregate/support_type/min/min.groovy | 5 ++++-
7 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/be/src/olap/rowset/segment_v2/column_reader.cpp
b/be/src/olap/rowset/segment_v2/column_reader.cpp
index ac90bf0bdbc..5ed96c0555d 100644
--- a/be/src/olap/rowset/segment_v2/column_reader.cpp
+++ b/be/src/olap/rowset/segment_v2/column_reader.cpp
@@ -463,6 +463,9 @@ Status ColumnReader::next_batch_of_zone_map(size_t* n,
vectorized::MutableColumn
} else {
if (is_string) {
auto sv = (StringRef*)max_value->cell_ptr();
+ if (type == FieldType::OLAP_FIELD_TYPE_CHAR) {
+ *sv = sv->trim_tail_padding_zero();
+ }
dst->insert_data(sv->data, sv->size);
} else {
dst->insert_many_fix_len_data(static_cast<const
char*>(max_value->cell_ptr()), 1);
@@ -475,6 +478,9 @@ Status ColumnReader::next_batch_of_zone_map(size_t* n,
vectorized::MutableColumn
} else {
if (is_string) {
auto sv = (StringRef*)min_value->cell_ptr();
+ if (type == FieldType::OLAP_FIELD_TYPE_CHAR) {
+ *sv = sv->trim_tail_padding_zero();
+ }
dst->insert_data_repeatedly(sv->data, sv->size, size);
} else {
// TODO: the work may cause performance problem, opt latter
diff --git a/be/src/pipeline/exec/cache_source_operator.h
b/be/src/pipeline/exec/cache_source_operator.h
index 49f0c376c47..984288b04f7 100644
--- a/be/src/pipeline/exec/cache_source_operator.h
+++ b/be/src/pipeline/exec/cache_source_operator.h
@@ -58,8 +58,8 @@ private:
int64_t _version = 0;
std::vector<vectorized::BlockUPtr> _local_cache_blocks;
std::vector<int> _slot_orders;
- size_t _current_query_cache_bytes = 0;
- size_t _current_query_cache_rows = 0;
+ int64_t _current_query_cache_bytes = 0;
+ int64_t _current_query_cache_rows = 0;
bool _need_insert_cache = true;
QueryCacheHandle _query_cache_handle;
diff --git a/be/src/vec/common/string_ref.cpp b/be/src/vec/common/string_ref.cpp
index 864d2454e64..bac052e741f 100644
--- a/be/src/vec/common/string_ref.cpp
+++ b/be/src/vec/common/string_ref.cpp
@@ -41,6 +41,17 @@ StringRef StringRef::trim() const {
return StringRef(data + begin, end - begin + 1);
}
+StringRef StringRef::trim_tail_padding_zero() const {
+ // Remove trailing padding zero.
+ int64_t end = size - 1;
+
+ while (end >= 0 && data[end] == '\0') {
+ --end;
+ }
+
+ return StringRef(data, end + 1);
+}
+
StringRef StringRef::trim_whitespace() const {
// Remove leading and trailing whitespace.
int64_t begin = 0;
diff --git a/be/src/vec/common/string_ref.h b/be/src/vec/common/string_ref.h
index 508399c4af9..27ab1137fc3 100644
--- a/be/src/vec/common/string_ref.h
+++ b/be/src/vec/common/string_ref.h
@@ -220,6 +220,7 @@ struct StringRef {
// Trims leading and trailing spaces.
StringRef trim() const;
+ StringRef trim_tail_padding_zero() const;
StringRef trim_whitespace() const;
StringRef trim_quote() const;
diff --git a/regression-test/data/query_p0/aggregate/support_type/max/max.out
b/regression-test/data/query_p0/aggregate/support_type/max/max.out
index 01e6a911dd0..4bcd72cd160 100644
--- a/regression-test/data/query_p0/aggregate/support_type/max/max.out
+++ b/regression-test/data/query_p0/aggregate/support_type/max/max.out
@@ -24,7 +24,7 @@ true
2.718281828
-- !max_char --
-char1�����
+char1
-- !max_varchar --
varchar1
diff --git a/regression-test/data/query_p0/aggregate/support_type/min/min.out
b/regression-test/data/query_p0/aggregate/support_type/min/min.out
index 11847e951e8..0c0893e375c 100644
--- a/regression-test/data/query_p0/aggregate/support_type/min/min.out
+++ b/regression-test/data/query_p0/aggregate/support_type/min/min.out
@@ -24,7 +24,10 @@ false
1.732050808
-- !min_char --
-char1�����
+char1
+
+-- !min_char_length_default --
+5
-- !min_varchar --
varchar1
diff --git
a/regression-test/suites/query_p0/aggregate/support_type/min/min.groovy
b/regression-test/suites/query_p0/aggregate/support_type/min/min.groovy
index b5fd8ff4b59..5b00298e274 100644
--- a/regression-test/suites/query_p0/aggregate/support_type/min/min.groovy
+++ b/regression-test/suites/query_p0/aggregate/support_type/min/min.groovy
@@ -97,6 +97,9 @@ suite("min") {
qt_min_double """select min(col_double) from d_table;"""
qt_min_char """select min(col_char) from d_table;"""
+ // Test length(min(col_char)) with different disable_nereids_rules settings
+ sql "set disable_nereids_rules='';"
+ qt_min_char_length_default """select length(min(col_char)) from d_table;"""
qt_min_varchar """select min(col_varchar) from d_table;"""
qt_min_string """select min(col_string) from d_table;"""
@@ -110,4 +113,4 @@ suite("min") {
qt_min_ipv4 """select min(col_ipv4) from d_table;"""
qt_min_ipv6 """select min(col_ipv6) from d_table;"""
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]