Skip to content

Commit

Permalink
1. Speed up compilation 2. Optimization of sum nullable column (apach…
Browse files Browse the repository at this point in the history
…e#21)

* fix profile cost too much cpu

* 1. Speed up compilation 2. Optimization of sum nullable column
  • Loading branch information
stdpain authored and HappenLee committed Aug 10, 2021
1 parent 73a840a commit 0833446
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 29 deletions.
10 changes: 4 additions & 6 deletions be/src/exec/olap_scan_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ void OlapScanNode::_init_counter(RuntimeState* state) {

// time of node to wait for batch/block queue
_olap_wait_batch_queue_timer = ADD_TIMER(_runtime_profile, "BatchQueueWaitTime");
// time of row cursor to convert batch/block
_row_cursor_convert_timer = ADD_TIMER(_runtime_profile, "RowCursorConvertTime");
}

Status OlapScanNode::prepare(RuntimeState* state) {
Expand Down Expand Up @@ -662,10 +660,10 @@ Status OlapScanNode::build_scan_key() {
}

Status OlapScanNode::get_hints(const TPaloScanRange& scan_range, int block_row_count,
bool is_begin_include, bool is_end_include,
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
RuntimeProfile* profile) {
bool is_begin_include, bool is_end_include,
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
RuntimeProfile* profile) {
auto tablet_id = scan_range.tablet_id;
int32_t schema_hash = strtoul(scan_range.schema_hash.c_str(), NULL, 10);
std::string err;
Expand Down
10 changes: 4 additions & 6 deletions be/src/exec/olap_scan_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "runtime/vectorized_row_batch.h"
#include "util/progress_updater.h"
#include "util/spinlock.h"

#include "vec/exec/volap_scanner.h"

namespace doris {
Expand Down Expand Up @@ -197,10 +196,10 @@ class OlapScanNode : public ScanNode {
int conj_idx, int child_idx);

static Status get_hints(const TPaloScanRange& scan_range, int block_row_count,
bool is_begin_include, bool is_end_include,
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
RuntimeProfile* profile);
bool is_begin_include, bool is_end_include,
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
RuntimeProfile* profile);

friend class OlapScanner;
friend class doris::vectorized::VOlapScanner;
Expand Down Expand Up @@ -367,7 +366,6 @@ class OlapScanNode : public ScanNode {
RuntimeProfile::Counter* _scanner_wait_worker_timer = nullptr;

RuntimeProfile::Counter* _olap_wait_batch_queue_timer = nullptr;
RuntimeProfile::Counter* _row_cursor_convert_timer = nullptr;
};

} // namespace doris
Expand Down
1 change: 0 additions & 1 deletion be/src/exec/olap_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ Status OlapScanner::get_batch(RuntimeState* state, RowBatch* batch, bool* eof) {
}

void OlapScanner::_convert_row_to_tuple(Tuple* tuple) {
SCOPED_TIMER(_parent->_row_cursor_convert_timer);
size_t slots_size = _query_slots.size();
for (int i = 0; i < slots_size; ++i) {
SlotDescriptor* slot_desc = _query_slots[i];
Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ set(VEC_FILES
exprs/vcast_expr.cpp
functions/abs.cpp
functions/comparison.cpp
functions/comparison_less.cpp
functions/comparison_equels.cpp
functions/comparison_greater.cpp
functions/function.cpp
functions/function_helpers.cpp
functions/functions_logical.cpp
Expand Down
20 changes: 20 additions & 0 deletions be/src/vec/aggregate_functions/aggregate_function_null.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ class AggregateFunctionNullUnary final
this->nested_function->add(this->nestedPlace(place), &nested_column, row_num, arena);
}
}

void addBatchSinglePlace(size_t batch_size, AggregateDataPtr place, const IColumn** columns,
Arena* arena) const override {
const ColumnNullable* column = assert_cast<const ColumnNullable*>(columns[0]);
bool has_null = column->has_null();

if (has_null) {
for (size_t i = 0; i < batch_size; ++i) {
if (!column->isNullAt(i)) {
this->setFlag(place);
this->add(place, columns, i, arena);
}
}
} else {
this->setFlag(place);
const IColumn* nested_column = &column->getNestedColumn();
this->nested_function->addBatchSinglePlace(batch_size, this->nestedPlace(place),
&nested_column, arena);
}
}
};

template <bool result_is_nullable>
Expand Down
15 changes: 14 additions & 1 deletion be/src/vec/columns/column_nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
ColumnPtr permute(const Permutation& perm, size_t limit) const override;
// ColumnPtr index(const IColumn & indexes, size_t limit) const override;
int compareAt(size_t n, size_t m, const IColumn& rhs_, int null_direction_hint) const override;
void getPermutation(bool reverse, size_t limit, int null_direction_hint, Permutation & res) const override;
void getPermutation(bool reverse, size_t limit, int null_direction_hint,
Permutation& res) const override;
void reserve(size_t n) override;
size_t byteSize() const override;
size_t allocatedBytes() const override;
Expand Down Expand Up @@ -157,6 +158,18 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
/// Check that size of null map equals to size of nested column.
void checkConsistency() const;

bool has_null() const {
auto begin = getNullMapData().begin();
auto end = getNullMapData().end();
while (begin < end) {
if (*begin != 0) {
return *begin;
}
++begin;
}
return false;
}

private:
WrappedPtr nested_column;
WrappedPtr null_map;
Expand Down
3 changes: 1 addition & 2 deletions be/src/vec/exec/volap_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Status VOlapScanner::get_block(RuntimeState* state, vectorized::Block* block, bo
slot_desc->col_name()));
}
VLOG_ROW << "VOlapScanner output rows: " << block->rows();

if (_vconjunct_ctx != nullptr) {
int result_column_id = -1;
_vconjunct_ctx->execute(block, &result_column_id);
Expand All @@ -99,7 +99,6 @@ Status VOlapScanner::get_block(RuntimeState* state, vectorized::Block* block, bo
}

void VOlapScanner::_convert_row_to_block(std::vector<vectorized::MutableColumnPtr>* columns) {
SCOPED_TIMER(_parent->_row_cursor_convert_timer);
size_t slots_size = _query_slots.size();
for (int i = 0; i < slots_size; ++i) {
SlotDescriptor* slot_desc = _query_slots[i];
Expand Down
19 changes: 6 additions & 13 deletions be/src/vec/functions/comparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@
// specific language governing permissions and limitations
// under the License.

#include "vec/functions/functions_comparison.h"
#include "vec/functions/simple_function_factory.h"

namespace doris::vectorized {
using FunctionGreater = FunctionComparison<GreaterOp, NameGreater>;
using FunctionGreaterOrEquals = FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>;
using FunctionLess = FunctionComparison<LessOp, NameLess>;
using FunctionLessOrEquals = FunctionComparison<LessOrEqualsOp, NameLessOrEquals>;
using FunctionEquals = FunctionComparison<EqualsOp, NameEquals>;
using FunctionNotEquals = FunctionComparison<NotEqualsOp, NameNotEquals>;
void registerFunctionComparisonEquals(SimpleFunctionFactory& factory);
void registerFunctionComparisonGreater(SimpleFunctionFactory& factory);
void registerFunctionComparisonLess(SimpleFunctionFactory& factory);

void registerFunctionComparison(SimpleFunctionFactory& factory) {
factory.registerFunction<FunctionGreater>();
factory.registerFunction<FunctionGreaterOrEquals>();
factory.registerFunction<FunctionLess>();
factory.registerFunction<FunctionLessOrEquals>();
factory.registerFunction<FunctionEquals>();
factory.registerFunction<FunctionNotEquals>();
registerFunctionComparisonEquals(factory);
registerFunctionComparisonGreater(factory);
registerFunctionComparisonLess(factory);
}
} // namespace doris::vectorized
29 changes: 29 additions & 0 deletions be/src/vec/functions/comparison_equels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 "vec/functions/functions_comparison.h"
#include "vec/functions/simple_function_factory.h"

namespace doris::vectorized {
using FunctionEquals = FunctionComparison<EqualsOp, NameEquals>;
using FunctionNotEquals = FunctionComparison<NotEqualsOp, NameNotEquals>;

void registerFunctionComparisonEquals(SimpleFunctionFactory& factory) {
factory.registerFunction<FunctionEquals>();
factory.registerFunction<FunctionNotEquals>();
}
} // namespace doris::vectorized
29 changes: 29 additions & 0 deletions be/src/vec/functions/comparison_greater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 "vec/functions/functions_comparison.h"
#include "vec/functions/simple_function_factory.h"

namespace doris::vectorized {
using FunctionGreater = FunctionComparison<GreaterOp, NameGreater>;
using FunctionGreaterOrEquals = FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>;

void registerFunctionComparisonGreater(SimpleFunctionFactory& factory) {
factory.registerFunction<FunctionGreater>();
factory.registerFunction<FunctionGreaterOrEquals>();
}
} // namespace doris::vectorized
29 changes: 29 additions & 0 deletions be/src/vec/functions/comparison_less.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 "vec/functions/functions_comparison.h"
#include "vec/functions/simple_function_factory.h"

namespace doris::vectorized {
using FunctionLess = FunctionComparison<LessOp, NameLess>;
using FunctionLessOrEquals = FunctionComparison<LessOrEqualsOp, NameLessOrEquals>;

void registerFunctionComparisonLess(SimpleFunctionFactory& factory) {
factory.registerFunction<FunctionLess>();
factory.registerFunction<FunctionLessOrEquals>();
}
} // namespace doris::vectorized

0 comments on commit 0833446

Please sign in to comment.