Skip to content

Commit 1e8e7af

Browse files
committed
fix logic for enable_runtime_filter_partition_prune and rename
1 parent 71eb85c commit 1e8e7af

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

be/src/vec/exec/scan/vfile_scanner.cpp

+43-34
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Status VFileScanner::prepare(RuntimeState* state, const VExprContextSPtrs& conju
138138
ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), "FileScannerPreFilterTimer", 1);
139139
_convert_to_output_block_timer = ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(),
140140
"FileScannerConvertOuputBlockTime", 1);
141-
_runtime_filter_partition_pruning_timer = ADD_TIMER_WITH_LEVEL(
141+
_runtime_filter_partition_prune_timer = ADD_TIMER_WITH_LEVEL(
142142
_local_state->scanner_profile(), "FileScannerRuntimeFilterPartitionPruningTime", 1);
143143
_empty_file_counter =
144144
ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), "EmptyFileNum", TUnit::UNIT, 1);
@@ -188,7 +188,7 @@ Status VFileScanner::prepare(RuntimeState* state, const VExprContextSPtrs& conju
188188
}
189189

190190
// check if the expr is a partition pruning expr
191-
bool VFileScanner::_check_partition_pruning_expr(const VExprSPtr& expr) {
191+
bool VFileScanner::_check_partition_prune_expr(const VExprSPtr& expr) {
192192
if (expr->is_slot_ref()) {
193193
auto* slot_ref = static_cast<VSlotRef*>(expr.get());
194194
return _partition_slot_index_map.find(slot_ref->slot_id()) !=
@@ -198,38 +198,38 @@ bool VFileScanner::_check_partition_pruning_expr(const VExprSPtr& expr) {
198198
return true;
199199
}
200200
return std::ranges::all_of(expr->children(), [this](const auto& child) {
201-
return _check_partition_pruning_expr(child);
201+
return _check_partition_prune_expr(child);
202202
});
203203
}
204204

205-
void VFileScanner::_init_runtime_filter_partition_pruning_ctxs() {
206-
if (_partition_slot_index_map.empty()) {
207-
return;
208-
}
209-
_runtime_filter_partition_pruning_ctxs.clear();
205+
void VFileScanner::_init_runtime_filter_partition_prune_ctxs() {
206+
_runtime_filter_partition_prune_ctxs.clear();
210207
for (auto& conjunct : _conjuncts) {
211208
auto impl = conjunct->root()->get_impl();
212209
// If impl is not null, which means this a conjuncts from runtime filter.
213210
auto expr = impl ? impl : conjunct->root();
214-
if (_check_partition_pruning_expr(expr)) {
215-
_runtime_filter_partition_pruning_ctxs.emplace_back(conjunct);
211+
if (_check_partition_prune_expr(expr)) {
212+
_runtime_filter_partition_prune_ctxs.emplace_back(conjunct);
216213
}
217214
}
215+
}
216+
217+
void VFileScanner::_init_runtime_filter_partition_prune_block() {
218218
// init block with empty column
219219
for (auto const* slot_desc : _real_tuple_desc->slots()) {
220220
if (!slot_desc->need_materialize()) {
221221
// should be ignored from reading
222222
continue;
223223
}
224-
_runtime_filter_partition_pruning_block.insert(
224+
_runtime_filter_partition_prune_block.insert(
225225
ColumnWithTypeAndName(slot_desc->get_empty_mutable_column(),
226226
slot_desc->get_data_type_ptr(), slot_desc->col_name()));
227227
}
228228
}
229229

230-
Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter_all) {
231-
SCOPED_TIMER(_runtime_filter_partition_pruning_timer);
232-
if (_runtime_filter_partition_pruning_ctxs.empty() || _partition_col_descs.empty()) {
230+
Status VFileScanner::_process_runtime_filters_partition_prune(bool& can_filter_all) {
231+
SCOPED_TIMER(_runtime_filter_partition_prune_timer);
232+
if (_runtime_filter_partition_prune_ctxs.empty() || _partition_col_descs.empty()) {
233233
return Status::OK();
234234
}
235235
size_t partition_value_column_size = 1;
@@ -248,8 +248,8 @@ Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter
248248
parititon_slot_id_to_column[partition_slot_desc->id()] = std::move(partition_value_column);
249249
}
250250

251-
// 2. Fill _runtime_filter_partition_pruning_block from the partition column, then execute conjuncts and filter block.
252-
// 2.1 Fill _runtime_filter_partition_pruning_block from the partition column to match the conjuncts executing.
251+
// 2. Fill _runtime_filter_partition_prune_block from the partition column, then execute conjuncts and filter block.
252+
// 2.1 Fill _runtime_filter_partition_prune_block from the partition column to match the conjuncts executing.
253253
size_t index = 0;
254254
bool first_column_filled = false;
255255
for (auto const* slot_desc : _real_tuple_desc->slots()) {
@@ -262,14 +262,14 @@ Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter
262262
auto data_type = slot_desc->get_data_type_ptr();
263263
auto partition_value_column = std::move(parititon_slot_id_to_column[slot_desc->id()]);
264264
if (data_type->is_nullable()) {
265-
_runtime_filter_partition_pruning_block.insert(
265+
_runtime_filter_partition_prune_block.insert(
266266
index, ColumnWithTypeAndName(
267267
ColumnNullable::create(
268268
std::move(partition_value_column),
269269
ColumnUInt8::create(partition_value_column_size, 0)),
270270
data_type, slot_desc->col_name()));
271271
} else {
272-
_runtime_filter_partition_pruning_block.insert(
272+
_runtime_filter_partition_prune_block.insert(
273273
index, ColumnWithTypeAndName(std::move(partition_value_column), data_type,
274274
slot_desc->col_name()));
275275
}
@@ -284,12 +284,12 @@ Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter
284284
if (!first_column_filled) {
285285
// VExprContext.execute has an optimization, the filtering is executed when block->rows() > 0
286286
// The following process may be tricky and time-consuming, but we have no other way.
287-
_runtime_filter_partition_pruning_block.get_by_position(0).column->assume_mutable()->resize(
287+
_runtime_filter_partition_prune_block.get_by_position(0).column->assume_mutable()->resize(
288288
partition_value_column_size);
289289
}
290-
IColumn::Filter result_filter(_runtime_filter_partition_pruning_block.rows(), 1);
291-
RETURN_IF_ERROR(VExprContext::execute_conjuncts(_runtime_filter_partition_pruning_ctxs, nullptr,
292-
&_runtime_filter_partition_pruning_block,
290+
IColumn::Filter result_filter(_runtime_filter_partition_prune_block.rows(), 1);
291+
RETURN_IF_ERROR(VExprContext::execute_conjuncts(_runtime_filter_partition_prune_ctxs, nullptr,
292+
&_runtime_filter_partition_prune_block,
293293
&result_filter, &can_filter_all));
294294
return Status::OK();
295295
}
@@ -357,7 +357,11 @@ Status VFileScanner::open(RuntimeState* state) {
357357
RETURN_IF_ERROR(_split_source->get_next(&_first_scan_range, &_current_range));
358358
if (_first_scan_range) {
359359
RETURN_IF_ERROR(_init_expr_ctxes());
360-
_init_runtime_filter_partition_pruning_ctxs();
360+
if (_state->query_options().enable_runtime_filter_partition_prune &&
361+
!_partition_slot_index_map.empty()) {
362+
_init_runtime_filter_partition_prune_ctxs();
363+
_init_runtime_filter_partition_prune_block();
364+
}
361365
} else {
362366
// there's no scan range in split source. stop scanner directly.
363367
_scanner_eof = true;
@@ -876,18 +880,23 @@ Status VFileScanner::_get_next_reader() {
876880
if (!_partition_slot_descs.empty()) {
877881
// we need get partition columns first for runtime filter partition pruning
878882
RETURN_IF_ERROR(_generate_parititon_columns());
879-
if (_push_down_conjuncts.size() < _conjuncts.size()) {
880-
// there are new runtime filters, need to re-init runtime filter partition pruning ctxs
881-
_init_runtime_filter_partition_pruning_ctxs();
882-
}
883883

884-
bool can_filter_all = false;
885-
RETURN_IF_ERROR(_process_runtime_filters_partition_pruning(can_filter_all));
886-
if (can_filter_all) {
887-
// this range can be filtered out by runtime filter partition pruning
888-
// so we need to skip this range
889-
COUNTER_UPDATE(_runtime_filter_partition_pruned_range_counter, 1);
890-
continue;
884+
if (_state->query_options().enable_runtime_filter_partition_prune) {
885+
// if enable_runtime_filter_partition_prune is true, we need to check whether this range can be filtered out
886+
// by runtime filter partition prune
887+
if (_push_down_conjuncts.size() < _conjuncts.size()) {
888+
// there are new runtime filters, need to re-init runtime filter partition pruning ctxs
889+
_init_runtime_filter_partition_prune_ctxs();
890+
}
891+
892+
bool can_filter_all = false;
893+
RETURN_IF_ERROR(_process_runtime_filters_partition_prune(can_filter_all));
894+
if (can_filter_all) {
895+
// this range can be filtered out by runtime filter partition pruning
896+
// so we need to skip this range
897+
COUNTER_UPDATE(_runtime_filter_partition_pruned_range_counter, 1);
898+
continue;
899+
}
891900
}
892901
}
893902

be/src/vec/exec/scan/vfile_scanner.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ class VFileScanner : public VScanner {
164164
Block _src_block;
165165

166166
VExprContextSPtrs _push_down_conjuncts;
167-
VExprContextSPtrs _runtime_filter_partition_pruning_ctxs;
168-
Block _runtime_filter_partition_pruning_block;
167+
VExprContextSPtrs _runtime_filter_partition_prune_ctxs;
168+
Block _runtime_filter_partition_prune_block;
169169

170170
std::unique_ptr<io::FileCacheStatistics> _file_cache_statistics;
171171
std::unique_ptr<io::IOContext> _io_ctx;
@@ -186,7 +186,7 @@ class VFileScanner : public VScanner {
186186
RuntimeProfile::Counter* _fill_missing_columns_timer = nullptr;
187187
RuntimeProfile::Counter* _pre_filter_timer = nullptr;
188188
RuntimeProfile::Counter* _convert_to_output_block_timer = nullptr;
189-
RuntimeProfile::Counter* _runtime_filter_partition_pruning_timer = nullptr;
189+
RuntimeProfile::Counter* _runtime_filter_partition_prune_timer = nullptr;
190190
RuntimeProfile::Counter* _empty_file_counter = nullptr;
191191
RuntimeProfile::Counter* _not_found_file_counter = nullptr;
192192
RuntimeProfile::Counter* _file_counter = nullptr;
@@ -220,9 +220,10 @@ class VFileScanner : public VScanner {
220220
void _truncate_char_or_varchar_column(Block* block, int idx, int len);
221221
Status _generate_parititon_columns();
222222
Status _generate_missing_columns();
223-
bool _check_partition_pruning_expr(const VExprSPtr& expr);
224-
void _init_runtime_filter_partition_pruning_ctxs();
225-
Status _process_runtime_filters_partition_pruning(bool& is_partition_pruning);
223+
bool _check_partition_prune_expr(const VExprSPtr& expr);
224+
void _init_runtime_filter_partition_prune_ctxs();
225+
void _init_runtime_filter_partition_prune_block();
226+
Status _process_runtime_filters_partition_prune(bool& is_partition_pruned);
226227
Status _process_conjuncts_for_dict_filter();
227228
Status _process_late_arrival_conjuncts();
228229
void _get_slot_ids(VExpr* expr, std::vector<int>* slot_ids);

0 commit comments

Comments
 (0)