Skip to content

Commit 0833446

Browse files
stdpainHappenLee
authored andcommitted
1. Speed up compilation 2. Optimization of sum nullable column (apache#21)
* fix profile cost too much cpu * 1. Speed up compilation 2. Optimization of sum nullable column
1 parent 73a840a commit 0833446

11 files changed

+139
-29
lines changed

be/src/exec/olap_scan_node.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ void OlapScanNode::_init_counter(RuntimeState* state) {
160160

161161
// time of node to wait for batch/block queue
162162
_olap_wait_batch_queue_timer = ADD_TIMER(_runtime_profile, "BatchQueueWaitTime");
163-
// time of row cursor to convert batch/block
164-
_row_cursor_convert_timer = ADD_TIMER(_runtime_profile, "RowCursorConvertTime");
165163
}
166164

167165
Status OlapScanNode::prepare(RuntimeState* state) {
@@ -662,10 +660,10 @@ Status OlapScanNode::build_scan_key() {
662660
}
663661

664662
Status OlapScanNode::get_hints(const TPaloScanRange& scan_range, int block_row_count,
665-
bool is_begin_include, bool is_end_include,
666-
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
667-
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
668-
RuntimeProfile* profile) {
663+
bool is_begin_include, bool is_end_include,
664+
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
665+
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
666+
RuntimeProfile* profile) {
669667
auto tablet_id = scan_range.tablet_id;
670668
int32_t schema_hash = strtoul(scan_range.schema_hash.c_str(), NULL, 10);
671669
std::string err;

be/src/exec/olap_scan_node.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "runtime/vectorized_row_batch.h"
3535
#include "util/progress_updater.h"
3636
#include "util/spinlock.h"
37-
3837
#include "vec/exec/volap_scanner.h"
3938

4039
namespace doris {
@@ -197,10 +196,10 @@ class OlapScanNode : public ScanNode {
197196
int conj_idx, int child_idx);
198197

199198
static Status get_hints(const TPaloScanRange& scan_range, int block_row_count,
200-
bool is_begin_include, bool is_end_include,
201-
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
202-
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
203-
RuntimeProfile* profile);
199+
bool is_begin_include, bool is_end_include,
200+
const std::vector<std::unique_ptr<OlapScanRange>>& scan_key_range,
201+
std::vector<std::unique_ptr<OlapScanRange>>* sub_scan_range,
202+
RuntimeProfile* profile);
204203

205204
friend class OlapScanner;
206205
friend class doris::vectorized::VOlapScanner;
@@ -367,7 +366,6 @@ class OlapScanNode : public ScanNode {
367366
RuntimeProfile::Counter* _scanner_wait_worker_timer = nullptr;
368367

369368
RuntimeProfile::Counter* _olap_wait_batch_queue_timer = nullptr;
370-
RuntimeProfile::Counter* _row_cursor_convert_timer = nullptr;
371369
};
372370

373371
} // namespace doris

be/src/exec/olap_scanner.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ Status OlapScanner::get_batch(RuntimeState* state, RowBatch* batch, bool* eof) {
424424
}
425425

426426
void OlapScanner::_convert_row_to_tuple(Tuple* tuple) {
427-
SCOPED_TIMER(_parent->_row_cursor_convert_timer);
428427
size_t slots_size = _query_slots.size();
429428
for (int i = 0; i < slots_size; ++i) {
430429
SlotDescriptor* slot_desc = _query_slots[i];

be/src/vec/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ set(VEC_FILES
6969
exprs/vcast_expr.cpp
7070
functions/abs.cpp
7171
functions/comparison.cpp
72+
functions/comparison_less.cpp
73+
functions/comparison_equels.cpp
74+
functions/comparison_greater.cpp
7275
functions/function.cpp
7376
functions/function_helpers.cpp
7477
functions/functions_logical.cpp

be/src/vec/aggregate_functions/aggregate_function_null.h

+20
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,26 @@ class AggregateFunctionNullUnary final
180180
this->nested_function->add(this->nestedPlace(place), &nested_column, row_num, arena);
181181
}
182182
}
183+
184+
void addBatchSinglePlace(size_t batch_size, AggregateDataPtr place, const IColumn** columns,
185+
Arena* arena) const override {
186+
const ColumnNullable* column = assert_cast<const ColumnNullable*>(columns[0]);
187+
bool has_null = column->has_null();
188+
189+
if (has_null) {
190+
for (size_t i = 0; i < batch_size; ++i) {
191+
if (!column->isNullAt(i)) {
192+
this->setFlag(place);
193+
this->add(place, columns, i, arena);
194+
}
195+
}
196+
} else {
197+
this->setFlag(place);
198+
const IColumn* nested_column = &column->getNestedColumn();
199+
this->nested_function->addBatchSinglePlace(batch_size, this->nestedPlace(place),
200+
&nested_column, arena);
201+
}
202+
}
183203
};
184204

185205
template <bool result_is_nullable>

be/src/vec/columns/column_nullable.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
9494
ColumnPtr permute(const Permutation& perm, size_t limit) const override;
9595
// ColumnPtr index(const IColumn & indexes, size_t limit) const override;
9696
int compareAt(size_t n, size_t m, const IColumn& rhs_, int null_direction_hint) const override;
97-
void getPermutation(bool reverse, size_t limit, int null_direction_hint, Permutation & res) const override;
97+
void getPermutation(bool reverse, size_t limit, int null_direction_hint,
98+
Permutation& res) const override;
9899
void reserve(size_t n) override;
99100
size_t byteSize() const override;
100101
size_t allocatedBytes() const override;
@@ -157,6 +158,18 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
157158
/// Check that size of null map equals to size of nested column.
158159
void checkConsistency() const;
159160

161+
bool has_null() const {
162+
auto begin = getNullMapData().begin();
163+
auto end = getNullMapData().end();
164+
while (begin < end) {
165+
if (*begin != 0) {
166+
return *begin;
167+
}
168+
++begin;
169+
}
170+
return false;
171+
}
172+
160173
private:
161174
WrappedPtr nested_column;
162175
WrappedPtr null_map;

be/src/vec/exec/volap_scanner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Status VOlapScanner::get_block(RuntimeState* state, vectorized::Block* block, bo
8787
slot_desc->col_name()));
8888
}
8989
VLOG_ROW << "VOlapScanner output rows: " << block->rows();
90-
90+
9191
if (_vconjunct_ctx != nullptr) {
9292
int result_column_id = -1;
9393
_vconjunct_ctx->execute(block, &result_column_id);
@@ -99,7 +99,6 @@ Status VOlapScanner::get_block(RuntimeState* state, vectorized::Block* block, bo
9999
}
100100

101101
void VOlapScanner::_convert_row_to_block(std::vector<vectorized::MutableColumnPtr>* columns) {
102-
SCOPED_TIMER(_parent->_row_cursor_convert_timer);
103102
size_t slots_size = _query_slots.size();
104103
for (int i = 0; i < slots_size; ++i) {
105104
SlotDescriptor* slot_desc = _query_slots[i];

be/src/vec/functions/comparison.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,16 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "vec/functions/functions_comparison.h"
1918
#include "vec/functions/simple_function_factory.h"
2019

2120
namespace doris::vectorized {
22-
using FunctionGreater = FunctionComparison<GreaterOp, NameGreater>;
23-
using FunctionGreaterOrEquals = FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>;
24-
using FunctionLess = FunctionComparison<LessOp, NameLess>;
25-
using FunctionLessOrEquals = FunctionComparison<LessOrEqualsOp, NameLessOrEquals>;
26-
using FunctionEquals = FunctionComparison<EqualsOp, NameEquals>;
27-
using FunctionNotEquals = FunctionComparison<NotEqualsOp, NameNotEquals>;
21+
void registerFunctionComparisonEquals(SimpleFunctionFactory& factory);
22+
void registerFunctionComparisonGreater(SimpleFunctionFactory& factory);
23+
void registerFunctionComparisonLess(SimpleFunctionFactory& factory);
2824

2925
void registerFunctionComparison(SimpleFunctionFactory& factory) {
30-
factory.registerFunction<FunctionGreater>();
31-
factory.registerFunction<FunctionGreaterOrEquals>();
32-
factory.registerFunction<FunctionLess>();
33-
factory.registerFunction<FunctionLessOrEquals>();
34-
factory.registerFunction<FunctionEquals>();
35-
factory.registerFunction<FunctionNotEquals>();
26+
registerFunctionComparisonEquals(factory);
27+
registerFunctionComparisonGreater(factory);
28+
registerFunctionComparisonLess(factory);
3629
}
3730
} // namespace doris::vectorized
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include "vec/functions/functions_comparison.h"
19+
#include "vec/functions/simple_function_factory.h"
20+
21+
namespace doris::vectorized {
22+
using FunctionEquals = FunctionComparison<EqualsOp, NameEquals>;
23+
using FunctionNotEquals = FunctionComparison<NotEqualsOp, NameNotEquals>;
24+
25+
void registerFunctionComparisonEquals(SimpleFunctionFactory& factory) {
26+
factory.registerFunction<FunctionEquals>();
27+
factory.registerFunction<FunctionNotEquals>();
28+
}
29+
} // namespace doris::vectorized
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include "vec/functions/functions_comparison.h"
19+
#include "vec/functions/simple_function_factory.h"
20+
21+
namespace doris::vectorized {
22+
using FunctionGreater = FunctionComparison<GreaterOp, NameGreater>;
23+
using FunctionGreaterOrEquals = FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>;
24+
25+
void registerFunctionComparisonGreater(SimpleFunctionFactory& factory) {
26+
factory.registerFunction<FunctionGreater>();
27+
factory.registerFunction<FunctionGreaterOrEquals>();
28+
}
29+
} // namespace doris::vectorized
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include "vec/functions/functions_comparison.h"
19+
#include "vec/functions/simple_function_factory.h"
20+
21+
namespace doris::vectorized {
22+
using FunctionLess = FunctionComparison<LessOp, NameLess>;
23+
using FunctionLessOrEquals = FunctionComparison<LessOrEqualsOp, NameLessOrEquals>;
24+
25+
void registerFunctionComparisonLess(SimpleFunctionFactory& factory) {
26+
factory.registerFunction<FunctionLess>();
27+
factory.registerFunction<FunctionLessOrEquals>();
28+
}
29+
} // namespace doris::vectorized

0 commit comments

Comments
 (0)