HappenLee commented on code in PR #65837:
URL: https://github.com/apache/doris/pull/65837#discussion_r3780876093
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/RuntimeFilterTranslator.java:
##########
@@ -393,6 +395,18 @@ private void
setPartitionPruningMetadata(org.apache.doris.planner.RuntimeFilter
scanNode.getId(), classification.getPartitionMonotonicity());
}
+ private void
setBucketPruningMetadata(org.apache.doris.planner.RuntimeFilter runtimeFilter,
Review Comment:
已在 11684adcaa2 修复。bucket 与 partition pruning 的生成已合并为
nereids.processor.post.RuntimeFilterPruneClassifier,并在
RuntimeFilterPushDownVisitor 创建最终 target 的 runtime filter
后立即调用。RuntimeFilterTranslator 不再负责分类或读取 session variable,只把 Nereids runtime
filter 上的不可变 target metadata 映射到 legacy scan node id,并为 legacy Thrift 快照
partition boundaries。
##########
be/src/exec/runtime_filter/runtime_filter_bucket_pruner.cpp:
##########
@@ -0,0 +1,149 @@
+// 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 "exec/runtime_filter/runtime_filter_bucket_pruner.h"
+
+#include <gen_cpp/PlanNodes_types.h>
+
+#include <algorithm>
+#include <memory>
+#include <mutex>
+
+#include "exprs/hybrid_set.h"
+#include "exprs/runtime_filter_expr.h"
+#include "exprs/vexpr.h"
+#include "exprs/vexpr_context.h"
+#include "exprs/vslot_ref.h"
+
+namespace doris {
+namespace {
+
+using SelectedBuckets = phmap::flat_hash_set<int32_t>;
+using SelectedBucketsByNum = phmap::flat_hash_map<int32_t, SelectedBuckets>;
+
+const SelectedBuckets& get_selected_buckets(int32_t bucket_num, const
DorisVector<uint32_t>& hashes,
+ SelectedBucketsByNum*
selected_buckets_by_num) {
+ auto [selected_it, inserted] =
selected_buckets_by_num->try_emplace(bucket_num);
+ if (inserted) {
+ auto& selected_buckets = selected_it->second;
+ selected_buckets.reserve(std::min(hashes.size(),
static_cast<size_t>(bucket_num)));
+ for (uint32_t hash : hashes) {
+ selected_buckets.insert(static_cast<int32_t>(hash %
static_cast<uint32_t>(bucket_num)));
+ }
+ }
+ return selected_it->second;
+}
+
+void collect_pruned_tablets(const
std::vector<std::unique_ptr<TPaloScanRange>>& ranges,
+ const DorisVector<uint32_t>& hashes,
+ phmap::flat_hash_set<int64_t>* newly_pruned) {
+ SelectedBucketsByNum selected_buckets_by_num;
+ for (const auto& range_ptr : ranges) {
+ DCHECK(range_ptr != nullptr);
+ const auto& range = *range_ptr;
+ if (newly_pruned->contains(range.tablet_id)) {
+ continue;
+ }
+ DCHECK(range.__isset.bucket_seq);
+ DCHECK(range.__isset.bucket_num);
+ DCHECK_GT(range.bucket_num, 0);
+ DCHECK_GE(range.bucket_seq, 0);
+ DCHECK_LT(range.bucket_seq, range.bucket_num);
+
+ const auto& selected_buckets =
+ get_selected_buckets(range.bucket_num, hashes,
&selected_buckets_by_num);
+ if (!selected_buckets.contains(range.bucket_seq)) {
+ newly_pruned->insert(range.tablet_id);
+ }
+ }
+}
+
+} // namespace
+
+Status RuntimeFilterBucketPruner::prune_by_runtime_filters(
+ const std::vector<std::unique_ptr<TPaloScanRange>>& ranges,
+ const VExprContextSPtrs& conjuncts, const
std::vector<TRuntimeFilterDesc>& rf_descs,
+ int scan_node_id, int max_in_num, int64_t* newly_pruned_count) {
+ *newly_pruned_count = 0;
+ if (ranges.empty()) {
+ return Status::OK();
+ }
+
+ phmap::flat_hash_set<int> eligible_filter_ids;
+ for (const auto& desc : rf_descs) {
+ if (desc.__isset.bucket_pruning_target_ids &&
+ desc.bucket_pruning_target_ids.contains(scan_node_id)) {
+ eligible_filter_ids.insert(desc.filter_id);
+ }
+ }
+ if (eligible_filter_ids.empty()) {
+ return Status::OK();
+ }
+
+ phmap::flat_hash_set<int64_t> newly_pruned;
Review Comment:
Already fixed in c4c9174a4e7 after the rebase. RuntimeFilterBucketPruner
retains compact selected-bucket sets keyed by bucket_num instead of
materializing pruned tablet IDs. Retained state is therefore bounded by bucket
counts rather than scan-range count, and the large-range tests cover the
compact representation.
##########
be/src/exec/scan/scanner_scheduler.cpp:
##########
@@ -208,8 +208,8 @@ void
ScannerScheduler::_scanner_scan(std::shared_ptr<ScannerContext> ctx,
}
}
- // After processing late RFs, check if this scanner's partition
was pruned.
- if (!eos && scanner->check_partition_pruned()) { eos = true; }
+ // After processing late RFs, check whether this scanner's scan
range was pruned.
+ if (!eos && scanner->is_pruned_by_runtime_filter()) { eos = true; }
Review Comment:
Already fixed in c4c9174a4e7 and 93cd52ca2d7 after the rebase.
ScannerScheduler polls and applies late runtime filters again after prepare and
before open, releases resources for scanners pruned at that point, and retains
the post-open check for arrivals during open. ScannerLateArrivalRfTest covers
the reader-open and resource-release lifecycle.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]