Skip to content

Commit

Permalink
Fix: vector::reserve takes up a lot of memory (#2764)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyehcf authored Jan 11, 2022
1 parent 29480b8 commit f163676
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 50 deletions.
1 change: 0 additions & 1 deletion be/src/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ set(EXEC_FILES
pipeline/aggregate/repeat/repeat_operator.cpp
pipeline/analysis/analytic_sink_operator.cpp
pipeline/analysis/analytic_source_operator.cpp
pipeline/analysis/analytor_factory.cpp
pipeline/table_function_operator.cpp
pipeline/assert_num_rows_operator.cpp
pipeline/set/union_passthrough_operator.cpp
Expand Down
1 change: 0 additions & 1 deletion be/src/exec/pipeline/analysis/analytic_sink_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#pragma once

#include "exec/pipeline/analysis/analytor_factory.h"
#include "exec/pipeline/operator.h"
#include "exec/vectorized/analytor.h"

Expand Down
1 change: 0 additions & 1 deletion be/src/exec/pipeline/analysis/analytic_source_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <utility>

#include "exec/pipeline/analysis/analytor_factory.h"
#include "exec/pipeline/source_operator.h"
#include "exec/vectorized/analytor.h"

Expand Down
14 changes: 0 additions & 14 deletions be/src/exec/pipeline/analysis/analytor_factory.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions be/src/exec/pipeline/analysis/analytor_factory.h

This file was deleted.

9 changes: 6 additions & 3 deletions be/src/exec/vectorized/analytor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ Status Analytor::prepare(RuntimeState* state, ObjectPool* pool, RuntimeProfile*
_agg_expr_ctxs[i][j]->root()->type(), _agg_expr_ctxs[i][j]->root()->is_nullable(),
_agg_expr_ctxs[i][j]->root()->is_constant(), 0);
}
_agg_intput_columns[i][j]->reserve(state->chunk_size() * BUFFER_CHUNK_NUMBER);
}

DCHECK(_agg_functions[i] != nullptr);
Expand Down Expand Up @@ -203,7 +202,6 @@ Status Analytor::prepare(RuntimeState* state, ObjectPool* pool, RuntimeProfile*
_partition_columns[i] = vectorized::ColumnHelper::create_column(
_partition_ctxs[i]->root()->type(), _partition_ctxs[i]->root()->is_nullable() | has_outer_join_child,
_partition_ctxs[i]->root()->is_constant(), 0);
_partition_columns[i]->reserve(state->chunk_size() * BUFFER_CHUNK_NUMBER);
}

RETURN_IF_ERROR(Expr::create_expr_trees(_pool, analytic_node.order_by_exprs, &_order_ctxs));
Expand All @@ -212,7 +210,6 @@ Status Analytor::prepare(RuntimeState* state, ObjectPool* pool, RuntimeProfile*
_order_columns[i] = vectorized::ColumnHelper::create_column(
_order_ctxs[i]->root()->type(), _order_ctxs[i]->root()->is_nullable() | has_outer_join_child,
_order_ctxs[i]->root()->is_constant(), 0);
_order_columns[i]->reserve(state->chunk_size() * BUFFER_CHUNK_NUMBER);
}

SCOPED_TIMER(_runtime_profile->total_time_counter());
Expand Down Expand Up @@ -551,4 +548,10 @@ int64_t Analytor::_find_first_not_equal(vectorized::Column* column, int64_t star
return end - 1;
}

AnalytorPtr AnalytorFactory::create(int i) {
if (!_analytors[i]) {
_analytors[i] = std::make_shared<Analytor>(_tnode, _child_row_desc, _result_tuple_desc);
}
return _analytors[i];
}
} // namespace starrocks
21 changes: 15 additions & 6 deletions be/src/exec/vectorized/analytor.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ class Analytor final : public pipeline::ContextWithDependency {
static constexpr int32_t BUFFER_CHUNK_NUMBER = 1;
#endif

#ifdef NDEBUG
static constexpr size_t memory_check_batch_size = 65535;
#else
static constexpr size_t memory_check_batch_size = 1;
#endif

private:
RuntimeState* _state = nullptr;
bool _is_closed = false;
Expand Down Expand Up @@ -233,4 +227,19 @@ class ManagedFunctionStates {
Analytor* _agg_node;
};

class AnalytorFactory;
using AnalytorFactoryPtr = std::shared_ptr<AnalytorFactory>;
class AnalytorFactory {
public:
AnalytorFactory(size_t dop, const TPlanNode& tnode, const RowDescriptor& child_row_desc,
const TupleDescriptor* result_tuple_desc)
: _analytors(dop), _tnode(tnode), _child_row_desc(child_row_desc), _result_tuple_desc(result_tuple_desc) {}
AnalytorPtr create(int i);

private:
Analytors _analytors;
const TPlanNode& _tnode;
const RowDescriptor& _child_row_desc;
const TupleDescriptor* _result_tuple_desc;
};
} // namespace starrocks

0 comments on commit f163676

Please sign in to comment.