englefly commented on code in PR #65853:
URL: https://github.com/apache/doris/pull/65853#discussion_r3635425816


##########
regression-test/suites/query_p0/runtime_filter/rf_partition_pruning.groovy:
##########
@@ -1570,7 +1570,67 @@ suite("rf_partition_pruning", "nonConcurrent") {
         "IN_OR_BLOOM_FILTER", 8, 6)
 
     // ============================================================
-    // Test 53: Switch off enable_runtime_filter_partition_prune -> no pruning
+    // Test 53: Sync MV aliases the base RANGE partition column.
+    // The RF target uses the rollup slot mv_k, while partition metadata is
+    // defined on base column k. FE must serialize the base boundaries with
+    // the MV target slot ID so BE can prune before creating scanners.
+    // ============================================================
+    sql "drop table if exists rf_prune_mv_alias_fact"
+    sql """
+        CREATE TABLE rf_prune_mv_alias_fact (
+            id BIGINT NOT NULL,
+            k INT NOT NULL,
+            v BIGINT NOT NULL
+        ) DUPLICATE KEY(id)
+        PARTITION BY RANGE(k) (
+            PARTITION p0 VALUES [(0),(10)),
+            PARTITION p1 VALUES [(10),(20)),
+            PARTITION p2 VALUES [(20),(30)),
+            PARTITION p3 VALUES [(30),(40))
+        )
+        DISTRIBUTED BY HASH(id) BUCKETS 2
+        PROPERTIES("replication_num" = "1")
+    """
+    sql """
+        INSERT INTO rf_prune_mv_alias_fact
+        SELECT number, number % 40, number * 3
+        FROM numbers("number" = "4000")
+    """
+
+    sql "drop table if exists rf_prune_mv_alias_dim"
+    sql """
+        CREATE TABLE rf_prune_mv_alias_dim (
+            scenario VARCHAR(16) NOT NULL,
+            k INT NOT NULL
+        ) DUPLICATE KEY(scenario, k)
+        DISTRIBUTED BY HASH(k) BUCKETS 2
+        PROPERTIES("replication_num" = "1")
+    """
+    sql """INSERT INTO rf_prune_mv_alias_dim VALUES ('one', 7), ('two', 7), 
('two', 27)"""
+
+    create_sync_mv(context.dbName, "rf_prune_mv_alias_fact", 
"rf_prune_mv_alias_detail", """
+        SELECT k AS mv_k, id AS mv_id, v AS mv_v
+        FROM rf_prune_mv_alias_fact
+    """)
+    sql "set enable_materialized_view_rewrite=true"
+    sql "set pre_materialized_view_rewrite_strategy='TRY_IN_RBO'"
+
+    order_qt_sync_mv_alias_minmax """

Review Comment:
    order_qt_sync_mv_alias_minmax + assertPruningProfile
   不能保证 裁剪的是mv, 如果裁剪是基表,也会有相同结果



##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -1408,22 +1413,61 @@ private void setPartitionBoundaries(TOlapScanNode 
olapScanNode) {
             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);
+            for (Map.Entry<Integer, Integer> entry : 
pruningSlotToPartitionColumnIndex.entrySet()) {
+                int slotId = entry.getKey();
+                int partitionColumnIndex = entry.getValue();
+                if (item instanceof RangePartitionItem) {
+                    Preconditions.checkState(partitionColumnIndex == 0);
+                    addRangeBoundary(boundaries, partitionId, 
(RangePartitionItem) item,
+                            partColumns.size(), slotId);
+                } else if (item instanceof ListPartitionItem) {
+                    addListBoundary(boundaries, partitionId, 
(ListPartitionItem) item,
+                            partitionColumnIndex, slotId);
+                }
             }
         }
         if (!boundaries.isEmpty()) {
             olapScanNode.setPartitionBoundaries(boundaries);
         }
     }
 
-    private void addRangeBoundaries(List<TPartitionBoundary> boundaries, long 
partitionId,
-            RangePartitionItem rangeItem, List<Column> partColumns,
-            Map<String, Integer> partColToSlotId) {
+    private int findPartitionColumnIndex(Column targetColumn, List<Column> 
partitionColumns) {
+        targetColumn = getBaseColumn(targetColumn);
+        if (targetColumn == null) {
+            return -1;
+        }
+        for (int i = 0; i < partitionColumns.size(); i++) {
+            Column partitionColumn = partitionColumns.get(i);
+            if (targetColumn == partitionColumn) {
+                return i;
+            }
+            int targetUniqueId = targetColumn.getUniqueId();

Review Comment:
   targetUniqueId == partitionUniqueId 和 targetColumn.equals(partitionColumn) 
是不是多余的兜底?



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