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


##########
be/src/exec/operator/olap_scan_operator.cpp:
##########
@@ -91,6 +95,9 @@ Status OlapScanLocalState::init(RuntimeState* state, 
LocalStateInfo& info) {
 
     RETURN_IF_ERROR(Base::init(state, info));
     RETURN_IF_ERROR(_sync_cloud_tablets(state));

Review Comment:
   This new OLAP path bypasses the existing 
`enable_runtime_filter_partition_prune` session flag. `FileScanner` still gates 
runtime-filter partition pruning on 
`query_options().enable_runtime_filter_partition_prune`, but here we always 
parse partition boundaries and later run `_do_partition_pruning_by_rf()` 
unconditionally from `_process_conjuncts()` / `_on_runtime_filter_update()`. As 
a result, `SET enable_runtime_filter_partition_prune = false` no longer 
disables the optimization for OLAP scans, which is a user-visible behavior 
regression.



##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -1201,9 +1208,131 @@ protected void toThrift(TPlanNode msg) {
 
         msg.olap_scan_node.setDistributeColumnIds(new 
ArrayList<>(distributionColumnIds));
 
+        // Populate partition boundaries for BE-side runtime filter partition 
pruning.
+        // Only serialize when this scan node actually has runtime filters, to 
avoid
+        // bloating thrift for tables with many partitions but no RF consumers.
+        if (!runtimeFilters.isEmpty()) {
+            setPartitionBoundaries(msg.olap_scan_node);
+        }
+
         super.toThrift(msg);
     }
 
+    private void setPartitionBoundaries(TOlapScanNode olapScanNode) {
+        PartitionInfo partitionInfo = olapTable.getPartitionInfo();
+        PartitionType partType = partitionInfo.getType();
+        if (partType != PartitionType.RANGE && partType != PartitionType.LIST) 
{
+            return;
+        }
+        List<Column> partColumns = partitionInfo.getPartitionColumns();
+        if (partColumns.isEmpty()) {
+            return;
+        }
+
+        // Build partition column name → slot ID mapping
+        Map<String, Integer> partColToSlotId = Maps.newHashMap();
+        for (SlotDescriptor slot : desc.getSlots()) {
+            if (slot.getColumn() == null) {
+                continue;
+            }
+            for (Column partCol : partColumns) {
+                if 
(slot.getColumn().getName().equalsIgnoreCase(partCol.getName())) {
+                    partColToSlotId.put(partCol.getName(), 
slot.getId().asInt());
+                    break;
+                }
+            }
+        }
+        if (partColToSlotId.isEmpty()) {
+            return;
+        }
+
+        List<TPartitionBoundary> boundaries = new ArrayList<>();
+        for (Long partitionId : selectedPartitionIds) {
+            PartitionItem item = partitionInfo.getItem(partitionId);
+            if (item == null) {
+                continue;
+            }
+            if (item instanceof RangePartitionItem) {
+                addRangeBoundaries(boundaries, partitionId, 
(RangePartitionItem) item,
+                        partColumns, partColToSlotId);
+            } else if (item instanceof ListPartitionItem) {
+                addListBoundaries(boundaries, partitionId, (ListPartitionItem) 
item,
+                        partColumns, partColToSlotId);
+            }
+        }
+        if (!boundaries.isEmpty()) {
+            olapScanNode.setPartitionBoundaries(boundaries);
+        }
+    }
+
+    private void addRangeBoundaries(List<TPartitionBoundary> boundaries, long 
partitionId,
+            RangePartitionItem rangeItem, List<Column> partColumns,

Review Comment:
   This is not safe for multi-column RANGE partitions. Doris range partition 
membership is based on lexicographic `PartitionKey` comparison, not on an 
independent range over the first column. For example, a legal partition like 
`[(1, 1), (1, 5))` becomes a first-column boundary `[1, 1)`, so BE will see an 
empty interval and can prune the partition even when `k1 = 1` should still 
match rows inside it. Unless FE can serialize a provably correct projection, 
this optimization needs to be disabled for multi-column RANGE partitions.



##########
be/src/exec/runtime_filter/runtime_filter_partition_pruner.cpp:
##########
@@ -0,0 +1,306 @@
+// 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);
+    }
+}
+
+// 
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);   \
+        auto parse_texpr_node = [&](const TExprNode& node) -> 
std::pair<CppType, ColumnPtr> { \

Review Comment:
   FE now emits `NULL_LITERAL` entries for nullable LIST partitions 
(`OlapScanNode.addListBoundaries()`), but this parser assumes every boundary 
literal can be converted into a concrete `CppType`. For a `NULL_LITERAL`, 
`VLiteral` builds a `ColumnNullable`; `get_data_at(0)` returns `{nullptr, 0}`, 
so the non-string branch dereferences a null pointer and the string branch 
collapses NULL to `""`. That makes nullable LIST partitions unsafe here. We 
need to propagate NULL through `ColumnValueRange::contain_null()` (or skip NULL 
boundaries for now) instead of treating it as an ordinary fixed value.



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