yujun777 commented on code in PR #68648:
URL: https://github.com/apache/doris/pull/68648#discussion_r4371477590


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -377,8 +383,23 @@ protected List<Plan> doRewrite(StructInfo queryStructInfo, 
CascadesContext casca
                 }
                 boolean needRemoveMvPartitions = 
!invalidPartitions.key().isEmpty();
                 boolean needBaseTableUnion = 
!invalidPartitions.value().isEmpty();
+                // An uncovered base partition is read beside the MV 
partitions that stay, and it can carry a
+                // key one of them already holds: a merged LIST component's MV 
partition is recorded with
+                // several keys of the MV's partition column. The aggregate 
compensation unions the MV's answer
+                // with the base table's, so such a group comes out twice 
instead of once. Answered from the
+                // base table instead of splitting the group. Groupings that 
cannot keep the two branches apart
+                // for other reasons are declined by canUnionRewrite below.
+                if (queryPlan.anyMatch(LogicalAggregate.class::isInstance)
+                        && needBaseTableUnion && 
!uncoveredNarrowedBasePartitions.isEmpty()) {

Review Comment:
   Fixed in ddf7a814ecd. Rejection now depends on the query's grouping: 
`PartitionCompensator` records the overlapping uncovered partitions per table, 
and the aggregate rule accepts them when every grouping set (or the plain 
group-by list) groups each partition column of the table by itself, or through 
an equality the query holds. The base rule keeps declining, since a plan of its 
shape cannot tell.
   
   Coverage uses exactly the LIST(d,k) fixture: `group_split_full_key_mv` 
(`PARTITION BY(d) AS SELECT d,k,SUM(v) s ... GROUP BY d,k`, 2 YEAR window) with 
`p_kept={(2020-01-01,1),(2038-01-01,1)}`, `p_bridge={(2038-01-01,2)}`, 
`p_old={(2020-01-01,2)}`. The explain asserts the UNION plan with the MV 
chosen, and `order_qt` asserts the ordered rows (2020-01-01,1,2) and 
(2020-01-01,2,1). The sibling d-only query on the same table still asserts no 
UNION, so the group-split rejection is preserved.
   
   Verified with PartitionCompensatorTest, MvExplorationSuiteTest, 
PartitionColumnTraceTest, and the `test_mtmv_base_partition_read_scope`, 
`partition_mv_rewrite`, `multi_trace_partition_mv_rewrite`, 
`materialized_view_grouping_sets` and `union_all_compensate` suites.



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