morningman commented on a change in pull request #4958:
URL: https://github.com/apache/incubator-doris/pull/4958#discussion_r531829637



##########
File path: be/src/olap/collect_iterator.cpp
##########
@@ -0,0 +1,328 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "olap/collect_iterator.h"
+
+#include "olap/reader.h"
+#include "olap/row.h"
+#include "olap/row_block.h"
+#include "olap/row_cursor.h"
+
+namespace doris {
+
+CollectIterator::~CollectIterator() {
+    for (auto child : _children) {
+        if (child != nullptr) {
+            delete child;
+            child = nullptr;
+        }
+    }
+}
+
+void CollectIterator::init(Reader* reader) {
+    _reader = reader;
+    // when aggregate is enabled or key_type is DUP_KEYS, we don't merge
+    // multiple data to aggregate for performance in user fetch
+    if (_reader->_reader_type == READER_QUERY &&
+        (_reader->_aggregation || _reader->_tablet->keys_type() == 
KeysType::DUP_KEYS)) {
+        _merge = false;
+    }
+}
+
+OLAPStatus CollectIterator::add_child(RowsetReaderSharedPtr rs_reader) {
+    std::unique_ptr<LevelIterator> child(new Level0Iterator(rs_reader, 
_reader));
+    RETURN_NOT_OK(child->init());
+    if (child->current_row() == nullptr) {
+        return OLAP_SUCCESS;
+    }
+
+    LevelIterator* child_ptr = child.release();
+    _children.push_back(child_ptr);
+    _rs_readers.push_back(rs_reader);
+    return OLAP_SUCCESS;
+}
+
+// Build a merge heap. If _merge is true, a rowset with the max rownum
+// status will be used as the base rowset, and the other rowsets will be 
merged first and
+// then merged with the base rowset.
+void CollectIterator::build_heap() {
+    DCHECK(_rs_readers.size() == _children.size());
+    _reverse = _reader->_tablet->tablet_schema().keys_type() == 
KeysType::UNIQUE_KEYS;
+    if (_children.empty()) {
+        _inner_iter.reset(nullptr);
+        return;
+    } else if (_merge) {
+        DCHECK(!_rs_readers.empty());
+        // find base rowset(max rownum),
+        RowsetReaderSharedPtr base_reader = _rs_readers[0];
+        int base_reader_idx = 0;
+        for (size_t i = 1; i < _rs_readers.size(); ++i) {

Review comment:
       We can first check the size of `_children`, then decide whether to find 
the base rowset.
   
   And there is a memory leak of `cumu_iter`




----------------------------------------------------------------
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.

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

Reply via email to