github-actions[bot] commented on code in PR #62589:
URL: https://github.com/apache/doris/pull/62589#discussion_r3108771902


##########
regression-test/data/query_p0/runtime_filter/rf_partition_pruning.out:
##########
@@ -0,0 +1,106 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !range_int_in --
+1      10      a
+3      50      c
+5      90      e
+
+-- !range_int_minmax --
+1      10      a
+3      50      c
+5      90      e
+
+-- !range_date_in --
+1      2024-01-15      jan
+2      2024-02-20      feb
+3      2024-03-10      mar
+
+-- !range_date_minmax --
+1      2024-01-15      jan
+2      2024-02-20      feb
+3      2024-03-10      mar
+
+-- !list_str_in --
+1      Beijing a
+2      Beijing b
+3      Beijing c
+
+-- !list_int_in --
+1      1       a
+2      1       b
+5      3       e
+6      3       f
+
+-- !no_pruning --
+13     250     m
+18     350     r
+3      50      c
+8      150     h
+
+-- !range_int_agg --
+3      10      90
+
+-- !list_str_agg --
+Beijing        3
+
+-- !list_int_multi --
+3      2       c
+4      2       d
+7      4       g
+8      4       h
+
+-- !bigint_range_in --
+1      100     v0a
+11     250100  v5a
+12     275000  v5b
+2      25000   v0b
+
+-- !bigint_range_minmax --
+1      100     v0a
+11     250100  v5a
+12     275000  v5b
+2      25000   v0b
+
+-- !datetime_range_in --
+1      2024-02-15T10:00        jan
+
+-- !datetime_range_minmax --
+1      2024-02-15T10:00        jan
+
+-- !list_50_in --
+10     10      cat10
+25     25      cat25
+3      3       cat3
+40     40      cat40
+50     50      cat50
+
+-- !neg_range_in --
+7      -50     g
+8      -10     h
+
+-- !neg_range_minmax --
+7      -50     g
+8      -10     h
+
+-- !desc_dim_in --
+1      10      a
+3      50      c
+5      90      e
+
+-- !desc_dim_minmax --
+1      10      a
+3      50      c
+5      90      e
+
+-- !combined_rf --
+1      10      a
+3      50      c
+5      90      e
+
+-- !span_in --
+13     250     m
+3      50      c
+
+-- !span_minmax --
+13     250     m
+3      50      c
+

Review Comment:
   The suite now defines five more ordered result checks, but this golden file 
still stops at `span_minmax`. The missing sections are `list_only_null_pruned`, 
`list_only_null_minmax`, `list_mixed_value_kept`, `list_mixed_nullsafe`, and 
`range_multi_first_col`, so `run-regression-test.sh -d query_p0 -s 
rf_partition_pruning` will fail at the first new `order_qt_*` case.



##########
regression-test/suites/query_p0/runtime_filter/rf_partition_pruning.groovy:
##########
@@ -0,0 +1,1120 @@
+// 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.
+
+import org.apache.doris.regression.action.ProfileAction
+
+// Marked nonConcurrent: this suite asserts on FE query-profile counters
+// (TotalPartitionsForRFPruning / PartitionsPrunedByRuntimeFilter). Even
+// though each query embeds a unique UUID token to look up its own profile,
+// the FE profile list is bounded (max_query_profile_num) and shared across
+// sessions, so heavy parallel traffic could evict our profile before the
+// poller finds it. Running serially keeps the assertions deterministic.
+suite("rf_partition_pruning", "nonConcurrent") {
+    sql "set enable_runtime_filter_prune=true;"
+
+    // ---- Profile utilities ----
+    def profileAction = new ProfileAction(context)
+
+    def getProfileByToken = { String token ->

Review Comment:
   This helper still turns `profile was not visible yet` into 
`total=0/pruned=0`: if the profile list does not contain the token within `15 * 
500ms`, `getProfileByToken()` returns `""` and `extractCounterSum()` quietly 
reads that as zero. On a slow or loaded FE that makes the suite fail even 
though pruning worked. Please fail explicitly when the profile is still 
missing, or keep polling until it appears / the query is known to be gone.



##########
be/src/exec/runtime_filter/runtime_filter_partition_pruner.cpp:
##########
@@ -0,0 +1,392 @@
+// 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_partition_pruner.h"
+
+#include <gen_cpp/PlanNodes_types.h>
+
+#include <optional>
+#include <utility>
+
+#include "exprs/bloom_filter_func.h"
+#include "exprs/hybrid_set.h"
+#include "exprs/vexpr.h"
+#include "exprs/vexpr_context.h"
+#include "exprs/vliteral.h"
+#include "exprs/vslot_ref.h"
+#include "runtime/descriptors.h"
+
+namespace doris {
+
+// Helper to extract a typed value from a ColumnPtr's first row.
+// Must be a template function so that `if constexpr` properly discards
+// the inapplicable branch during instantiation.
+template <PrimitiveType PT>
+static typename PrimitiveTypeTraits<PT>::CppType 
extract_value_from_column(const ColumnPtr& col) {
+    using CppType = typename PrimitiveTypeTraits<PT>::CppType;
+    auto data = col->get_data_at(0);
+    if constexpr (is_string_type(PT)) {
+        return CppType(data.data, data.size);
+    } else {
+        return *reinterpret_cast<const CppType*>(data.data);
+    }
+}
+
+// 
NOLINTBEGIN(readability-function-cognitive-complexity,readability-function-size)
+// Complexity is inflated by macro expansion for each PrimitiveType case.
+void RuntimeFilterPartitionPruner::parse_boundaries(
+        const std::vector<TPartitionBoundary>& boundaries,
+        const phmap::flat_hash_map<int, SlotDescriptor*>& slot_descs) {
+    for (const auto& tb : boundaries) {
+        if (!tb.__isset.partition_id || !tb.__isset.slot_id) {
+            continue;
+        }
+        SlotId slot_id = tb.slot_id;
+
+        auto slot_it = slot_descs.find(slot_id);
+        if (slot_it == slot_descs.end()) {
+            continue;
+        }
+        SlotDescriptor* slot = slot_it->second;
+        PrimitiveType ptype = slot->type()->get_primitive_type();
+        int precision = cast_set<int>(slot->type()->get_precision());
+        int scale = cast_set<int>(slot->type()->get_scale());
+        bool is_nullable = slot->is_nullable();
+
+        ParsedBoundary boundary;
+        boundary.partition_id = tb.partition_id;
+        boundary.slot_id = slot_id;
+        boundary.is_nullable = is_nullable;
+
+        bool parsed_ok = false;
+
+#define BUILD_BOUNDARY_CVR(NAME)                                               
                \
+    case TYPE_##NAME: {                                                        
                \
+        using CppType = typename PrimitiveTypeTraits<TYPE_##NAME>::CppType;    
                \
+        bool is_list = tb.__isset.list_values && !tb.list_values.empty();      
                \
+        bool is_range = tb.__isset.range_start || tb.__isset.range_end;        
                \
+        if (!is_list && !is_range) break;                                      
                \
+        ColumnValueRange<TYPE_##NAME> cvr(slot->col_name(), is_nullable, 
precision, scale);    \
+        /* Returns nullopt if `node` is a NULL literal; the caller then sets 
contain_null  */  \
+        /* on the CVR instead of trying to extract a typed value (which would 
dereference  */  \
+        /* a null data pointer for the non-string branch).                     
            */  \
+        auto parse_texpr_node =                                                
                \
+                [&](const TExprNode& node) -> std::optional<std::pair<CppType, 
ColumnPtr>> {   \
+            if (node.node_type == TExprNodeType::NULL_LITERAL) {               
                \
+                return std::nullopt;                                           
                \
+            }                                                                  
                \
+            VLiteral literal(node);                                            
                \
+            auto col_ptr = literal.get_column_ptr();                           
                \
+            auto val = extract_value_from_column<TYPE_##NAME>(col_ptr);        
                \
+            return std::make_optional(std::pair<CppType, ColumnPtr> {val, 
col_ptr});           \
+        };                                                                     
                \
+        if (is_list) {                                                         
                \
+            auto empty_cvr = 
ColumnValueRange<TYPE_##NAME>::create_empty_column_value_range(   \
+                    is_nullable, precision, scale);                            
                \
+            bool list_has_null = false;                                        
                \
+            bool list_has_value = false;                                       
                \
+            for (const auto& node : tb.list_values) {                          
                \
+                auto parsed = parse_texpr_node(node);                          
                \
+                if (!parsed) {                                                 
                \
+                    list_has_null = true;                                      
                \
+                    continue;                                                  
                \
+                }                                                              
                \
+                auto& [val, col_ptr] = *parsed;                                
                \
+                boundary.literal_columns.push_back(std::move(col_ptr));        
                \
+                static_cast<void>(empty_cvr.add_fixed_value(val));             
                \
+                list_has_value = true;                                         
                \
+            }                                                                  
                \
+            if (list_has_value) {                                              
                \
+                cvr.intersection(empty_cvr);                                   
                \
+            }                                                                  
                \
+            if (list_has_null && is_nullable) {                                
                \
+                /* Track NULL membership on ParsedBoundary; calling          
*/                \
+                /* cvr.set_contain_null(true) here would invoke              
*/                \
+                /* set_empty_value_range() and discard the concrete fixed    
*/                \
+                /* values we just inserted, turning {NULL, v} into a         
*/                \
+                /* NULL-only boundary.                                       
*/                \
+                boundary.contains_null = true;                                 
                \
+                if (!list_has_value) {                                         
                \
+                    boundary.only_null = true;                                 
                \
+                }                                                              
                \
+            }                                                                  
                \
+        } else {                                                               
                \
+            if (tb.__isset.range_start) {                                      
                \
+                auto parsed = parse_texpr_node(tb.range_start);                
                \
+                if (parsed) {                                                  
                \
+                    auto& [val, col_ptr] = *parsed;                            
                \
+                    boundary.literal_columns.push_back(std::move(col_ptr));    
                \
+                    static_cast<void>(cvr.add_range(FILTER_LARGER_OR_EQUAL, 
val));             \
+                }                                                              
                \
+            }                                                                  
                \
+            if (tb.__isset.range_end) {                                        
                \
+                auto parsed = parse_texpr_node(tb.range_end);                  
                \
+                if (parsed) {                                                  
                \
+                    auto& [val, col_ptr] = *parsed;                            
                \
+                    boundary.literal_columns.push_back(std::move(col_ptr));    
                \
+                    /* Multi-column RANGE projection emits a CLOSED upper 
bound (see       */  \
+                    /* TPartitionBoundary.range_end_inclusive comment); 
single-column RANGE */ \
+                    /* keeps the natural OPEN upper bound matching Doris 
semantics.         */ \
+                    SQLFilterOp upper_op =                                     
                \
+                            (tb.__isset.range_end_inclusive && 
tb.range_end_inclusive)         \
+                                    ? FILTER_LESS_OR_EQUAL                     
                \
+                                    : FILTER_LESS;                             
                \
+                    static_cast<void>(cvr.add_range(upper_op, val));           
                \
+                }                                                              
                \
+            }                                                                  
                \
+        }                                                                      
                \
+        boundary.boundary_cvr = std::move(cvr);                                
                \
+        parsed_ok = true;                                                      
                \
+        break;                                                                 
                \
+    }
+
+        switch (ptype) {
+            BUILD_BOUNDARY_CVR(TINYINT)
+            BUILD_BOUNDARY_CVR(SMALLINT)
+            BUILD_BOUNDARY_CVR(INT)
+            BUILD_BOUNDARY_CVR(BIGINT)
+            BUILD_BOUNDARY_CVR(LARGEINT)
+            BUILD_BOUNDARY_CVR(FLOAT)
+            BUILD_BOUNDARY_CVR(DOUBLE)
+            BUILD_BOUNDARY_CVR(CHAR)
+            BUILD_BOUNDARY_CVR(DATE)
+            BUILD_BOUNDARY_CVR(DATETIME)
+            BUILD_BOUNDARY_CVR(DATEV2)
+            BUILD_BOUNDARY_CVR(DATETIMEV2)
+            BUILD_BOUNDARY_CVR(TIMESTAMPTZ)
+            BUILD_BOUNDARY_CVR(VARCHAR)
+            BUILD_BOUNDARY_CVR(STRING)
+            BUILD_BOUNDARY_CVR(DECIMAL32)
+            BUILD_BOUNDARY_CVR(DECIMAL64)
+            BUILD_BOUNDARY_CVR(DECIMAL128I)
+            BUILD_BOUNDARY_CVR(DECIMAL256)
+            BUILD_BOUNDARY_CVR(DECIMALV2)
+            BUILD_BOUNDARY_CVR(BOOLEAN)
+            BUILD_BOUNDARY_CVR(IPV4)
+            BUILD_BOUNDARY_CVR(IPV6)
+        default:
+            break;
+        }
+#undef BUILD_BOUNDARY_CVR
+
+        if (parsed_ok) {
+            _partition_column_slot_ids.insert(slot_id);
+            _slot_to_boundaries[slot_id].push_back(std::move(boundary));
+        }
+    }
+
+    // Count distinct partition IDs across all boundaries.
+    if (!_partition_column_slot_ids.empty()) {
+        phmap::flat_hash_set<int64_t> all_partition_ids;
+        for (const auto& [_, slot_boundaries] : _slot_to_boundaries) {
+            for (const auto& pb : slot_boundaries) {
+                all_partition_ids.insert(pb.partition_id);
+            }
+        }
+        _total_partition_count = 
static_cast<int64_t>(all_partition_ids.size());
+    }
+}
+// 
NOLINTEND(readability-function-cognitive-complexity,readability-function-size)
+
+static SQLFilterOp convert_opcode_to_filter_op(TExprOpcode::type op) {
+    switch (op) {
+    case TExprOpcode::LE:
+        return FILTER_LESS_OR_EQUAL;
+    case TExprOpcode::LT:
+        return FILTER_LESS;
+    case TExprOpcode::GE:
+        return FILTER_LARGER_OR_EQUAL;
+    case TExprOpcode::GT:
+        return FILTER_LARGER;
+    default:
+        return FILTER_IN; // sentinel: caller should skip
+    }
+}
+
+void RuntimeFilterPartitionPruner::_try_prune_by_single_rf(
+        const VExprSPtr& impl, SlotId slot_id, phmap::flat_hash_set<int64_t>& 
newly_pruned) {
+    auto boundaries_it = _slot_to_boundaries.find(slot_id);
+    if (boundaries_it == _slot_to_boundaries.end()) {
+        return;
+    }
+
+    // Pre-compute whether the RF "matches NULL" -- i.e. whether the RF would
+    // accept a row whose probe value is NULL. The signal differs by RF impl:
+    //   * IN filter      → HybridSet::contain_null()
+    //   * Bloom filter   → BloomFilterFuncBase::contain_null()
+    //   * MinMax filter  → encoded via the BinaryPredicate node_type:
+    //                      NULL_AWARE_BINARY_PRED means the build side had a
+    //                      NULL key and a null-safe equal join asked NULL to
+    //                      match NULL; plain BINARY_PRED never matches NULL.
+    // FilterBase::contain_null() already folds in `_null_aware`, so we only
+    // get a true result when the build side is actually null-aware AND
+    // produced a NULL value.
+    bool rf_contains_null = false;
+    if (auto hybrid_set = impl->get_set_func()) {
+        rf_contains_null = hybrid_set->contain_null();
+    } else if (impl->node_type() == TExprNodeType::BLOOM_PRED) {
+        auto bloom = impl->get_bloom_filter_func();
+        rf_contains_null = bloom && bloom->contain_null();
+    } else if (impl->node_type() == TExprNodeType::NULL_AWARE_BINARY_PRED) {
+        // Min/Max RF built on a null-safe equal join. The literal child holds
+        // the min or max bound; the NULL semantic is conveyed by the node
+        // type itself (see create_vbin_predicate in runtime_filter/utils.cpp).
+        rf_contains_null = true;
+    }
+
+    for (const auto& pb : boundaries_it->second) {
+        if (_pruned_partition_ids.contains(pb.partition_id) ||
+            newly_pruned.contains(pb.partition_id)) {
+            continue;
+        }
+
+        // NULL handling:
+        //   A partition row whose key is NULL matches the RF iff 
`rf_contains_null`.
+        //   - only_null partition (rows are exclusively NULL): prunable iff 
!rf_contains_null.
+        //   - mixed (NULL + concrete values): if rf_contains_null, NULL rows 
alone
+        //     prevent pruning. Otherwise NULL rows can never match, so we 
ignore
+        //     the NULL portion and let the regular non-NULL intersection 
decide.
+        if (pb.only_null) {
+            if (!rf_contains_null) {
+                newly_pruned.insert(pb.partition_id);
+            }
+            continue;
+        }
+        if (pb.contains_null && rf_contains_null) {
+            continue;
+        }
+
+        std::visit(
+                [&](const auto& boundary_cvr) {
+                    using CvrType = std::decay_t<decltype(boundary_cvr)>;
+                    using CppType = typename CvrType::CppType;
+
+                    auto hybrid_set = impl->get_set_func();

Review Comment:
   `VBloomPredicate` falls through this pruning logic today. In the real Bloom 
case (`runtime_filter_type='BLOOM_FILTER'`, or `IN_OR_BLOOM_FILTER` after the 
wrapper switches past `runtime_filter_max_in_num`), 
`impl->node_type()==BLOOM_PRED`, `get_set_func()==nullptr`, and we never enter 
the MinMax branch either. The result is that the new OLAP partition-pruning 
path becomes a no-op for Bloom RFs, so LIST-partition scans lose pruning 
entirely once the filter stops being an IN set.



-- 
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]

Reply via email to