BiteTheDDDDt commented on code in PR #58636:
URL: https://github.com/apache/doris/pull/58636#discussion_r2684551164
##########
be/src/vec/exprs/vexpr.cpp:
##########
@@ -1039,5 +1039,60 @@ bool VExpr::ann_dist_is_fulfilled() const {
return _virtual_column_is_fulfilled;
}
+Status VExpr::execute_filter(VExprContext* context, const Block* block,
+ uint8_t* __restrict result_filter_data, size_t
rows, bool accept_null,
+ bool* can_filter_all) const {
+ ColumnPtr filter_column;
+ RETURN_IF_ERROR(execute_column(context, block, rows, filter_column));
+ if (const auto* const_column =
check_and_get_column<ColumnConst>(*filter_column)) {
+ // const(nullable) or const(bool)
+ const bool result = accept_null
+ ? (const_column->is_null_at(0) ||
const_column->get_bool(0))
+ : (!const_column->is_null_at(0) &&
const_column->get_bool(0));
+ if (!result) {
+ // filter all
+ *can_filter_all = true;
+ memset(result_filter_data, 0, rows);
+ return Status::OK();
+ }
+ } else if (const auto* nullable_column =
check_and_get_column<ColumnNullable>(*filter_column)) {
+ // nullable(bool)
+ const ColumnPtr& nested_column =
nullable_column->get_nested_column_ptr();
+ const IColumn::Filter& filter = assert_cast<const
ColumnUInt8&>(*nested_column).get_data();
+ const auto* __restrict filter_data = filter.data();
+ const auto* __restrict null_map_data =
nullable_column->get_null_map_data().data();
+
+ if (accept_null) {
+ for (size_t i = 0; i < rows; ++i) {
+ result_filter_data[i] &= (null_map_data[i]) || filter_data[i];
+ }
+ } else {
+ for (size_t i = 0; i < rows; ++i) {
+ result_filter_data[i] &= (!null_map_data[i]) & filter_data[i];
+ }
+ }
+
+ if ((memchr(result_filter_data, 0x1, rows) == nullptr)) {
+ *can_filter_all = true;
+ return Status::OK();
+ }
+ } else {
+ // bool
+ const IColumn::Filter& filter = assert_cast<const
ColumnUInt8&>(*filter_column).get_data();
+ const auto* __restrict filter_data = filter.data();
+
+ for (size_t i = 0; i < rows; ++i) {
+ result_filter_data[i] &= filter_data[i];
+ }
+
+ if (memchr(result_filter_data, 0x1, rows) == nullptr) {
Review Comment:
ditto
##########
be/src/runtime_filter/runtime_filter_selectivity.h:
##########
@@ -0,0 +1,91 @@
+// 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 "common/config.h"
+#include "common/logging.h"
+
+namespace doris {
+
+// Used to track the selectivity of runtime filters
+// If the selectivity of a runtime filter is very low, it is considered
ineffective and can be ignored
+// Considering that the selectivity of runtime filters may change with data
variations
+// A dynamic selectivity tracking mechanism is needed
+// Note: this is not a thread-safe class
+
+class RuntimeFilterSelectivity {
+public:
+ RuntimeFilterSelectivity() = default;
+
+ RuntimeFilterSelectivity(const RuntimeFilterSelectivity&&) = delete;
+ void update_judge_counter() {
+ if ((_judge_counter++) >= config::runtime_filter_sampling_frequency) {
+ reset_judge_selectivity();
+ }
+ }
+
+ void update_judge_selectivity(int filter_id, uint64_t filter_rows,
uint64_t input_rows,
+ double ignore_thredhold) {
+ if (!_always_true) {
+ _judge_filter_rows += filter_rows;
+ _judge_input_rows += input_rows;
+ judge_selectivity(ignore_thredhold, _judge_filter_rows,
_judge_input_rows,
+ _always_true);
+ }
+
+ VLOG_ROW << fmt::format(
+ "Runtime filter[{}] selectivity update: filter_rows: {},
input_rows: {}, filter "
+ "rate: {}, "
+ "ignore_thredhold: {}, counter: {} , always_true: {}",
Review Comment:
need update
--
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]