github-actions[bot] commented on code in PR #65837:
URL: https://github.com/apache/doris/pull/65837#discussion_r3776356276
##########
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:
[P2] Apply late filters once more before opening a prepared scanner. If an
RF becomes READY after the line-186 check while `prepare()` is running, this
path still calls `open()` before polling it. For `OlapScanner`, open runs
`BlockReader::init()`, including its eager first-row read, so every
already-admitted scanner whose tablet is now pruned still pays reader
initialization before this check turns it into EOS. The new test creates this
exact timing but inherits the cheap base open and counts only
`_get_block_impl()`, so it cannot detect the production cost. Please poll/apply
and recheck after prepare and before open, retain the post-open check for
arrivals during open, and assert that pruned scanners never enter the
reader-open path.
##########
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:
[P2] Avoid materializing every eliminated tablet in two untracked hash sets.
A one-value filter over the configured 20,000-partition x 768-bucket limits can
put about 15.34 million IDs in `newly_pruned`, then copy them into
`_pruned_tablet_ids` while the temporary is still alive. Raw keys alone exceed
117 MiB per set (over 234 MiB peak before flat-hash overhead), and both use the
default allocator. This recreates a query/process OOM risk after the earlier
metadata-vector fix; tablets already eliminated by partition pruning can also
be recorded here. Please retain compact selected-bucket state for lookup, or at
least use query-accounted storage and merge without two dense sets alive, skip
already-pruned ranges, and add high-range-count coverage.
--
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]