github-actions[bot] commented on code in PR #69854:
URL: https://github.com/apache/doris/pull/69854#discussion_r4430597044
##########
be/src/exec/operator/olap_scan_operator.cpp:
##########
@@ -526,8 +527,38 @@ static Status
validate_residual_scan_conjuncts(RuntimeState* state,
return Status::OK();
}
+static bool expr_reads_slot(const VExprSPtr& expr, int slot_id) {
+ DORIS_CHECK(expr != nullptr);
+ if (expr->is_slot_ref() && assert_cast<const
VSlotRef*>(expr.get())->slot_id() == slot_id) {
+ return true;
+ }
+ return std::ranges::any_of(expr->children(), [slot_id](const auto& child) {
+ return expr_reads_slot(child, slot_id);
+ });
+}
+
+bool OlapScanLocalState::_conjuncts_read_delete_sign() const {
+ const auto& p = _parent->cast<OlapScanOperatorX>();
+ const auto& slots = p._output_tuple_desc->slots();
+ const auto delete_sign = std::ranges::find_if(
+ slots, [](const SlotDescriptor* slot) { return slot->col_name() ==
DELETE_SIGN; });
+ // A conjunct on the delete sign reads its slot, so the scan outputs it.
+ if (delete_sign == slots.end()) {
+ return false;
+ }
+ const int slot_id = (*delete_sign)->id();
+ auto reads_delete_sign = [slot_id](const VExprContextSPtr& conjunct) {
+ return conjunct->root() != nullptr &&
expr_reads_slot(conjunct->root(), slot_id);
+ };
Review Comment:
[P1] Distinguish the default delete-sign filter from user predicates. With
show_hidden_columns=true, `WHERE __DORIS_DELETE_SIGN__ = 1` reaches this scan
conjunct, so `_conjuncts_read_delete_sign()` returns true and
`collect_hidden_docs()` removes all delete-sign rows from BM25 doc/token
statistics even though those rows pass the predicate and are scored. This
changes avgdl/idf and can change ORDER BY score()/LIMIT results. Detect the
FE-generated `= 0` filter or carry its semantics explicitly, and add coverage
for nonzero predicates.
##########
be/src/storage/index/inverted/common/norm_length_sums.h:
##########
@@ -0,0 +1,117 @@
+// 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.
+
+#pragma once
+
+#include <cstdint>
+#include <functional>
+#include <mutex>
+#include <span>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "common/status.h"
+#include "util/hash_util.hpp"
+
+namespace doris::segment_v2 {
+
+// The sums of norm lengths that merge-on-write BM25 statistics need of an
index, kept with the
+// index's reader in the searcher cache, so they live and are evicted with it.
The index never
+// changes, so the sums are computed once and every later query reads no
norms. They take a few
+// dozen bytes per field.
+class NormLengthSums {
+public:
+ // The sum of the lengths the norms of the non-NULL documents of `field`
stand for, computed
+ // by `compute` the first time.
+ Status non_null_norm_length_sum(const std::wstring& field,
+ const std::function<Status(uint64_t*)>&
compute,
+ uint64_t* out) {
+ {
+ std::lock_guard lock(_mutex);
+ if (auto it = _non_null_sums.find(field); it !=
_non_null_sums.end()) {
+ *out = it->second;
+ return Status::OK();
+ }
+ }
+ // Computed outside the lock, which other queries of the index take to
read their sums.
+ // Two queries may both compute a sum the index does not hold yet;
both get the same.
+ RETURN_IF_ERROR(compute(out));
Review Comment:
[P2] Avoid duplicate first-use norm scans. This path unlocks `_mutex` before
`compute(out)`, and the hidden-row method does the same, so concurrent BM25
queries can all miss the same field/set and each run
`source.sum_norm_lengths()` plus NULL-row decoding before racing to cache the
result. Large segments and query bursts therefore multiply full norm I/O, CPU,
and temporary buffers. Use per-key single-flight state or serialize the first
computation, and add a concurrent first-use test.
--
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]