@@ -138,7 +138,7 @@ Status VFileScanner::prepare(RuntimeState* state, const VExprContextSPtrs& conju
138
138
ADD_TIMER_WITH_LEVEL (_local_state->scanner_profile (), " FileScannerPreFilterTimer" , 1 );
139
139
_convert_to_output_block_timer = ADD_TIMER_WITH_LEVEL (_local_state->scanner_profile (),
140
140
" FileScannerConvertOuputBlockTime" , 1 );
141
- _runtime_filter_partition_pruning_timer = ADD_TIMER_WITH_LEVEL (
141
+ _runtime_filter_partition_prune_timer = ADD_TIMER_WITH_LEVEL (
142
142
_local_state->scanner_profile (), " FileScannerRuntimeFilterPartitionPruningTime" , 1 );
143
143
_empty_file_counter =
144
144
ADD_COUNTER_WITH_LEVEL (_local_state->scanner_profile (), " EmptyFileNum" , TUnit::UNIT, 1 );
@@ -188,7 +188,7 @@ Status VFileScanner::prepare(RuntimeState* state, const VExprContextSPtrs& conju
188
188
}
189
189
190
190
// 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) {
192
192
if (expr->is_slot_ref ()) {
193
193
auto * slot_ref = static_cast <VSlotRef*>(expr.get ());
194
194
return _partition_slot_index_map.find (slot_ref->slot_id ()) !=
@@ -198,38 +198,38 @@ bool VFileScanner::_check_partition_pruning_expr(const VExprSPtr& expr) {
198
198
return true ;
199
199
}
200
200
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);
202
202
});
203
203
}
204
204
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 ();
210
207
for (auto & conjunct : _conjuncts) {
211
208
auto impl = conjunct->root ()->get_impl ();
212
209
// If impl is not null, which means this a conjuncts from runtime filter.
213
210
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);
216
213
}
217
214
}
215
+ }
216
+
217
+ void VFileScanner::_init_runtime_filter_partition_prune_block () {
218
218
// init block with empty column
219
219
for (auto const * slot_desc : _real_tuple_desc->slots ()) {
220
220
if (!slot_desc->need_materialize ()) {
221
221
// should be ignored from reading
222
222
continue ;
223
223
}
224
- _runtime_filter_partition_pruning_block .insert (
224
+ _runtime_filter_partition_prune_block .insert (
225
225
ColumnWithTypeAndName (slot_desc->get_empty_mutable_column (),
226
226
slot_desc->get_data_type_ptr (), slot_desc->col_name ()));
227
227
}
228
228
}
229
229
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 ()) {
233
233
return Status::OK ();
234
234
}
235
235
size_t partition_value_column_size = 1 ;
@@ -248,8 +248,8 @@ Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter
248
248
parititon_slot_id_to_column[partition_slot_desc->id ()] = std::move (partition_value_column);
249
249
}
250
250
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.
253
253
size_t index = 0 ;
254
254
bool first_column_filled = false ;
255
255
for (auto const * slot_desc : _real_tuple_desc->slots ()) {
@@ -262,14 +262,14 @@ Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter
262
262
auto data_type = slot_desc->get_data_type_ptr ();
263
263
auto partition_value_column = std::move (parititon_slot_id_to_column[slot_desc->id ()]);
264
264
if (data_type->is_nullable ()) {
265
- _runtime_filter_partition_pruning_block .insert (
265
+ _runtime_filter_partition_prune_block .insert (
266
266
index , ColumnWithTypeAndName (
267
267
ColumnNullable::create (
268
268
std::move (partition_value_column),
269
269
ColumnUInt8::create (partition_value_column_size, 0 )),
270
270
data_type, slot_desc->col_name ()));
271
271
} else {
272
- _runtime_filter_partition_pruning_block .insert (
272
+ _runtime_filter_partition_prune_block .insert (
273
273
index , ColumnWithTypeAndName (std::move (partition_value_column), data_type,
274
274
slot_desc->col_name ()));
275
275
}
@@ -284,12 +284,12 @@ Status VFileScanner::_process_runtime_filters_partition_pruning(bool& can_filter
284
284
if (!first_column_filled) {
285
285
// VExprContext.execute has an optimization, the filtering is executed when block->rows() > 0
286
286
// 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 (
288
288
partition_value_column_size);
289
289
}
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 ,
293
293
&result_filter, &can_filter_all));
294
294
return Status::OK ();
295
295
}
@@ -357,7 +357,11 @@ Status VFileScanner::open(RuntimeState* state) {
357
357
RETURN_IF_ERROR (_split_source->get_next (&_first_scan_range, &_current_range));
358
358
if (_first_scan_range) {
359
359
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
+ }
361
365
} else {
362
366
// there's no scan range in split source. stop scanner directly.
363
367
_scanner_eof = true ;
@@ -876,18 +880,23 @@ Status VFileScanner::_get_next_reader() {
876
880
if (!_partition_slot_descs.empty ()) {
877
881
// we need get partition columns first for runtime filter partition pruning
878
882
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
- }
883
883
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
+ }
891
900
}
892
901
}
893
902
0 commit comments