Copilot commented on code in PR #62588:
URL: https://github.com/apache/doris/pull/62588#discussion_r3099181549


##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -1201,9 +1208,127 @@ protected void toThrift(TPlanNode msg) {
 
         msg.olap_scan_node.setDistributeColumnIds(new 
ArrayList<>(distributionColumnIds));
 
+        // Populate partition boundaries for BE-side runtime filter partition 
pruning
+        setPartitionBoundaries(msg.olap_scan_node);

Review Comment:
   `setPartitionBoundaries()` is invoked unconditionally during 
`OlapScanNode.toThrift()`. For highly-partitioned tables this can significantly 
bloat the plan/thrift payload even when the scan has no runtime filters, 
increasing planning latency and risking message-size limits. Consider gating 
boundary serialization behind (1) presence of runtime filters on this scan node 
(e.g. `!runtimeFilters.isEmpty()`), and/or (2) a session variable/feature flag 
so it only runs when partition pruning by RF is enabled.
   ```suggestion
           // Populate partition boundaries only when this scan has runtime 
filters,
           // which are required for BE-side runtime filter partition pruning.
           if (runtimeFilters != null && !runtimeFilters.isEmpty()) {
               setPartitionBoundaries(msg.olap_scan_node);
           }
   ```



##########
be/src/exec/runtime_filter/runtime_filter_partition_pruner.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 <shared_mutex>
+#include <unordered_map>
+#include <unordered_set>
+#include <vector>
+
+#include "common/global_types.h"
+#include "exprs/vexpr_fwd.h"
+#include "storage/olap_scan_common.h"
+#include "core/column/column.h"

Review Comment:
   `RuntimeFilterPartitionPruner` uses 
`phmap::flat_hash_map`/`phmap::flat_hash_set` in its public API and members, 
but this header does not include `<parallel_hashmap/phmap.h>` (or another 
header that guarantees the `phmap` namespace/types are declared). This can 
break compilation depending on include order. Please add the explicit include 
(or switch to the existing `doris::flat_hash_*` aliases from 
`exec/common/hash_table/phmap_fwd_decl.h`).



##########
regression-test/conf/regression-conf.groovy:
##########
@@ -24,8 +24,8 @@ defaultDb = "regression_test"
 // init cmd like: select @@session.tx_read_only
 // at each time we connect.
 // add allowLoadLocalInfile so that the jdbc can execute mysql load data from 
client.
-jdbcUrl = 
"jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
-targetJdbcUrl = 
"jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
+jdbcUrl = 
"jdbc:mysql://127.0.0.1:9333/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
+targetJdbcUrl = 
"jdbc:mysql://127.0.0.1:9333/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"

Review Comment:
   The default regression test connection endpoints were changed from 9030/8030 
to 9333/8333, but the same file still references 9030 elsewhere (e.g. 
ccrDownstreamUrl / doris_port). This makes the config internally inconsistent 
and will likely break CI/regression runs that expect the default FE ports. 
Please revert these defaults or make them configurable via an override/env var 
without changing the repo defaults.



##########
fe/fe-core/src/main/java/org/apache/doris/planner/RuntimeFilter.java:
##########
@@ -280,6 +285,36 @@ public TRuntimeFilterDesc toThrift() {
         } else if (builderNode instanceof SetOperationNode) {
             tFilter.setNullAware(true);
         }
+
+        // Set target_expr_monotonicity for partition column identity path.
+        // When the RF target is a direct SlotRef on a partition column, the
+        // mapping from column value to partition is monotonic (identity), so
+        // the BE can use the RF values to prune partitions.
+        for (RuntimeFilterTarget target : targets) {
+            if (target.expr instanceof SlotRef && target.node instanceof 
OlapScanNode) {
+                SlotRef slotRef = (SlotRef) target.expr;
+                Column col = slotRef.getColumn();
+                if (col != null) {
+                    OlapScanNode scanNode = (OlapScanNode) target.node;
+                    OlapTable table = scanNode.getOlapTable();
+                    PartitionType partType = 
table.getPartitionInfo().getType();
+                    if (partType == PartitionType.RANGE || partType == 
PartitionType.LIST) {
+                        for (Column partCol : 
table.getPartitionInfo().getPartitionColumns()) {
+                            if 
(partCol.getName().equalsIgnoreCase(col.getName())) {
+                                tFilter.setTargetExprMonotonicity(
+                                        
TTargetExprMonotonicity.MONOTONIC_INCREASING);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            // Only check the first target; if there are multiple targets on
+            // different tables, monotonicity may differ. We conservatively
+            // set it based on the first target only.
+            break;
+        }

Review Comment:
   `target_expr_monotonicity` is set based on only the *first* 
RuntimeFilterTarget. This is not necessarily conservative: if the first target 
is a partition-column SlotRef but later targets are on different 
expressions/tables, BE may apply an overly-optimistic monotonicity to other 
targets. Safer options are to set this field only when `targets.size() == 1` 
(or when all targets satisfy the same monotonicity condition), otherwise leave 
it unset/`NON_MONOTONIC`.



##########
be/src/exec/runtime_filter/runtime_filter_partition_pruner.cpp:
##########
@@ -0,0 +1,293 @@
+// 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 "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);
+    }
+}
+
+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);    \
+        auto parse_texpr_node = [&](const TExprNode& node) -> 
std::pair<CppType, ColumnPtr> { \
+            VLiteral literal(node);                                            
                \
+            auto col_ptr = literal.get_column_ptr();                           
                \
+            auto val = extract_value_from_column<TYPE_##NAME>(col_ptr);        
                \
+            return {val, col_ptr};                                             
                \
+        };                                                                     
                \
+        if (is_list) {                                                         
                \
+            auto empty_cvr = 
ColumnValueRange<TYPE_##NAME>::create_empty_column_value_range(    \
+                    is_nullable, precision, scale);                            
                 \
+            for (const auto& node : tb.list_values) {                          
                \
+                auto [val, col_ptr] = parse_texpr_node(node);                  
                \
+                boundary.literal_columns.push_back(std::move(col_ptr));        
                \
+                static_cast<void>(empty_cvr.add_fixed_value(val));             
                \
+            }                                                                  
                \
+            cvr.intersection(empty_cvr);                                       
                \
+        } else {                                                               
                \
+            if (tb.__isset.range_start) {                                      
                \
+                auto [val, col_ptr] = parse_texpr_node(tb.range_start);        
                \
+                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 [val, col_ptr] = parse_texpr_node(tb.range_end);          
                \
+                boundary.literal_columns.push_back(std::move(col_ptr));        
                \
+                static_cast<void>(cvr.add_range(FILTER_LESS, 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());
+    }
+}
+
+int64_t RuntimeFilterPartitionPruner::prune_by_runtime_filters(
+        const VExprContextSPtrs& conjuncts) {
+    if (_partition_column_slot_ids.empty()) {
+        return 0;
+    }
+
+    phmap::flat_hash_set<int64_t> newly_pruned;
+
+    for (const auto& conjunct_ctx : conjuncts) {
+        VExprSPtr root = conjunct_ctx->root();
+        if (!root->is_rf_wrapper()) {
+            continue;
+        }
+
+        VExprSPtr impl = root->get_impl();
+        if (!impl) {
+            continue;
+        }
+
+        // Determine the target slot_id from the RF's probe expression.
+        // For IN filter: impl is VDirectInPredicate, children()[0] is VSlotRef
+        // For MinMax filter: impl is VectorizedFnCall (binary pred), 
children()[0] is VSlotRef
+        if (impl->children().empty() || !impl->children()[0]->is_slot_ref()) {
+            continue;
+        }
+        auto* slot_ref = assert_cast<VSlotRef*>(impl->children()[0].get());
+        SlotId slot_id = slot_ref->slot_id();
+        if (!_partition_column_slot_ids.contains(slot_id)) {
+            continue;
+        }
+
+        auto boundaries_it = _slot_to_boundaries.find(slot_id);
+        if (boundaries_it == _slot_to_boundaries.end()) {
+            continue;
+        }
+
+        for (const auto& pb : boundaries_it->second) {
+            if (_pruned_partition_ids.contains(pb.partition_id) ||
+                newly_pruned.contains(pb.partition_id)) {
+                continue;

Review Comment:
   `RuntimeFilterPartitionPruner` claims `is_partition_pruned()` is safe 
concurrently with `prune_by_runtime_filters()`, but 
`prune_by_runtime_filters()` reads `_pruned_partition_ids` without holding 
`_prune_mutex` (the `contains()` check). Concurrent reads/writes to 
`phmap::flat_hash_set` without synchronization is undefined behavior. Please 
take a shared_lock around reads (or snapshot the set under lock) so the 
thread-safety contract holds.



##########
regression-test/conf/regression-conf.groovy:
##########
@@ -35,7 +35,7 @@ syncerAddress = "127.0.0.1:9190"
 feSyncerUser = "root"
 feSyncerPassword = ""
 
-feHttpAddress = "127.0.0.1:8030"
+feHttpAddress = "127.0.0.1:8333"

Review Comment:
   feHttpAddress was changed to 8333, which is inconsistent with the default FE 
HTTP port used elsewhere in this config and typical test environments. Since 
ProfileAction-based suites depend on this setting, changing it here can break 
many regression suites. Please keep the repository default (typically 8030) and 
provide a local override mechanism instead.
   ```suggestion
   // Keep the repository default FE HTTP port and allow local overrides via:
   //   -DfeHttpAddress=127.0.0.1:8333
   feHttpAddress = System.getProperty("feHttpAddress", "127.0.0.1:8030")
   ```



##########
gensrc/thrift/PlanNodes.thrift:
##########
@@ -913,6 +938,13 @@ struct TOlapScanNode {
   24: optional bool enable_mor_value_predicate_pushdown
   // Read MOR table as DUP table: skip merge, skip delete sign
   25: optional bool read_mor_as_dup
+  // Partition-id → tablet-id list mapping; used together with 
partition_boundaries
+  // for BE-side runtime filter partition pruning.
+  26: optional map<Types.TPartitionId, list<Types.TTabletId>> 
partiton_to_tablets

Review Comment:
   Thrift field name `partiton_to_tablets` appears to be misspelled (missing 
'i' in 'partition'). Because Thrift field names become part of generated APIs 
and are hard to change later, please fix the spelling now (e.g. 
`partition_to_tablets`) before this gets released/consumed.
   ```suggestion
     26: optional map<Types.TPartitionId, list<Types.TTabletId>> 
partition_to_tablets
   ```



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