This is an automated email from the ASF dual-hosted git repository.

yiguolei 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 cac317430f [Bug](aggregation) fix core dump on 2nd phase aggregate 
(#11843)
cac317430f is described below

commit cac317430f31801a433042aa84c57b6cccbdf720
Author: Pxl <pxl...@qq.com>
AuthorDate: Thu Aug 18 14:42:34 2022 +0800

    [Bug](aggregation) fix core dump on 2nd phase aggregate (#11843)
---
 be/src/vec/exec/vaggregation_node.cpp               |  5 +----
 be/src/vec/exec/vaggregation_node.h                 | 21 +++++++++++++--------
 .../data/query_p0/aggregate/aggregate.out           | 21 +++++++++++++++++++++
 .../suites/query/keyword/test_keyword.groovy        |  2 +-
 .../suites/query_p0/aggregate/aggregate.groovy      |  3 +++
 5 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/be/src/vec/exec/vaggregation_node.cpp 
b/be/src/vec/exec/vaggregation_node.cpp
index fee5832754..d43ae88e8b 100644
--- a/be/src/vec/exec/vaggregation_node.cpp
+++ b/be/src/vec/exec/vaggregation_node.cpp
@@ -610,11 +610,8 @@ Status AggregationNode::_merge_without_key(Block* block) {
     std::unique_ptr<char[]> deserialize_buffer(new 
char[_total_size_of_aggregate_states]);
     int rows = block->rows();
     for (int i = 0; i < _aggregate_evaluators.size(); ++i) {
-        DCHECK(_aggregate_evaluators[i]->input_exprs_ctxs().size() == 1 &&
-               
_aggregate_evaluators[i]->input_exprs_ctxs()[0]->root()->is_slot_ref());
-        int col_id =
-                
((VSlotRef*)_aggregate_evaluators[i]->input_exprs_ctxs()[0]->root())->column_id();
         if (_aggregate_evaluators[i]->is_merge()) {
+            int col_id = _get_slot_column_id(_aggregate_evaluators[i]);
             auto column = block->get_by_position(col_id).column;
             if (column->is_nullable()) {
                 column = 
((ColumnNullable*)column.get())->get_nested_column_ptr();
diff --git a/be/src/vec/exec/vaggregation_node.h 
b/be/src/vec/exec/vaggregation_node.h
index 7702102e6a..6960c89c4f 100644
--- a/be/src/vec/exec/vaggregation_node.h
+++ b/be/src/vec/exec/vaggregation_node.h
@@ -761,6 +761,17 @@ private:
         return Status::OK();
     }
 
+    // We should call this function only at 1st phase.
+    // 1st phase: is_merge=true, only have one SlotRef.
+    // 2nd phase: is_merge=false, maybe have multiple exprs.
+    int _get_slot_column_id(const AggFnEvaluator* evaluator) {
+        auto ctxs = evaluator->input_exprs_ctxs();
+        CHECK(ctxs.size() == 1 && ctxs[0]->root()->is_slot_ref())
+                << "input_exprs_ctxs is invalid, input_exprs_ctx[0]="
+                << ctxs[0]->root()->debug_string();
+        return ((VSlotRef*)ctxs[0]->root())->column_id();
+    }
+
     template <bool limit>
     Status _merge_with_serialized_key_helper(Block* block) {
         SCOPED_TIMER(_merge_timer);
@@ -781,11 +792,8 @@ private:
             _find_in_hash_table(places.data(), key_columns, rows);
 
             for (int i = 0; i < _aggregate_evaluators.size(); ++i) {
-                DCHECK(_aggregate_evaluators[i]->input_exprs_ctxs().size() == 
1 &&
-                       
_aggregate_evaluators[i]->input_exprs_ctxs()[0]->root()->is_slot_ref());
-                int col_id = 
((VSlotRef*)_aggregate_evaluators[i]->input_exprs_ctxs()[0]->root())
-                                     ->column_id();
                 if (_aggregate_evaluators[i]->is_merge()) {
+                    int col_id = _get_slot_column_id(_aggregate_evaluators[i]);
                     auto column = block->get_by_position(col_id).column;
                     if (column->is_nullable()) {
                         column = 
((ColumnNullable*)column.get())->get_nested_column_ptr();
@@ -811,11 +819,8 @@ private:
             _emplace_into_hash_table(places.data(), key_columns, rows);
 
             for (int i = 0; i < _aggregate_evaluators.size(); ++i) {
-                DCHECK(_aggregate_evaluators[i]->input_exprs_ctxs().size() == 
1 &&
-                       
_aggregate_evaluators[i]->input_exprs_ctxs()[0]->root()->is_slot_ref());
-                int col_id = 
((VSlotRef*)_aggregate_evaluators[i]->input_exprs_ctxs()[0]->root())
-                                     ->column_id();
                 if (_aggregate_evaluators[i]->is_merge()) {
+                    int col_id = _get_slot_column_id(_aggregate_evaluators[i]);
                     auto column = block->get_by_position(col_id).column;
                     if (column->is_nullable()) {
                         column = 
((ColumnNullable*)column.get())->get_nested_column_ptr();
diff --git a/regression-test/data/query_p0/aggregate/aggregate.out 
b/regression-test/data/query_p0/aggregate/aggregate.out
index 58946a04d9..bd983f4295 100644
--- a/regression-test/data/query_p0/aggregate/aggregate.out
+++ b/regression-test/data/query_p0/aggregate/aggregate.out
@@ -608,3 +608,24 @@ TESTING    AGAIN
 32767  lifsno  -2147483647
 32767  yanavnd 3021
 
+-- !aggregate_2phase_0 --
+8.0    1227.5333333333333
+
+-- !aggregate_2phase_1 --
+\N     0       \N      1
+1      1       11011902        1
+2      1       11011903        1
+3      1       11011905        1
+4      1       -11011907       1
+5      1       -11011903       1
+6      1       123456  1
+7      1       7210457 1
+8      1       11011920        1
+9      1       11011902        1
+10     1       9223372036854775807     1
+11     1       -9223372036854775807    1
+12     1       9223372036854775807     1
+13     1       -9223372036854775807    1
+14     1       11011902        1
+15     1       11011920        1
+
diff --git a/regression-test/suites/query/keyword/test_keyword.groovy 
b/regression-test/suites/query/keyword/test_keyword.groovy
index a94874fe37..930529b0d3 100644
--- a/regression-test/suites/query/keyword/test_keyword.groovy
+++ b/regression-test/suites/query/keyword/test_keyword.groovy
@@ -47,7 +47,7 @@ suite("test_keyword", "query,p0") {
     qt_distinct22 "select count(distinct k1) from ${tableName1} having 
count(k1)>60000"
     qt_distinct23 "select count(distinct k1) from ${tableName1} having 
count(k1)>70000"
     qt_distinct24 "select count(*), COUNT(distinct 1) from ${tableName1} where 
false"
-    // qt_distinct25 "select avg(distinct k1), avg(k1) from ${tableName1}"
+    qt_distinct25 "select avg(distinct k1), avg(k1) from ${tableName1}"
     qt_distinct26 "select count(*) from (select count(distinct k1) from 
${tableName1} group by k2) v \
                    order by count(*)"
 
diff --git a/regression-test/suites/query_p0/aggregate/aggregate.groovy 
b/regression-test/suites/query_p0/aggregate/aggregate.groovy
index 564364fc52..10b7c8b165 100644
--- a/regression-test/suites/query_p0/aggregate/aggregate.groovy
+++ b/regression-test/suites/query_p0/aggregate/aggregate.groovy
@@ -212,4 +212,7 @@ suite("aggregate") {
              (select ${k1}, ${k3}, sum(${k2}) as mysum from baseall 
              group by ${k1}, ${k3}) t2 where t1.${k1}=t2.${k1} and 
t1.${k3}=t2.${k3}
              order by t1.${k1}, t1.${k3}, t2.mysum"""
+
+    qt_aggregate_2phase_0"""select avg(distinct k1),avg(k2) from baseall"""
+    qt_aggregate_2phase_1"""select k1,count(distinct k2,k3),min(k4),count(*) 
from baseall group by k1 order by k1"""
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to