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


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRewriteUtil.java:
##########
@@ -166,25 +231,46 @@ private static Set<String> 
getMtmvPartitionsByRelatedPartitions(MTMV mtmv, MTMVR
             }
             Set<String> pctPartitions = entry.getValue();
             for (String pctPartition : pctPartitions) {
-                String mvPartition = relatedToMv.get(Pair.of(tableIf, 
pctPartition));
-                if (mvPartition != null) {
-                    res.add(mvPartition);
+                Set<String> mvPartitions = relatedToMv.get(Pair.of(tableIf, 
pctPartition));
+                if (mvPartitions == null) {
+                    // A partition the query reads that no MV partition is 
mapped from -- one the partition
+                    // mapping left out, an expired base partition for 
instance -- is one the MV's rows say
+                    // nothing about. With the union rewrite on it is taken 
out of the MV plan and read from
+                    // the base table, so the MV partitions the other base 
partitions map to still answer the
+                    // query and this one is passed over. Without it the MV 
alone would answer, so no partition
+                    // is answered for at all: the MV is not a candidate for 
this query and the query is
+                    // answered from the base table.
+                    if (unionRewrite) {

Review Comment:
   Fixed in a1b36ca15ab. The two decisions are apart now: a table with a 
query-used partition the mapping does not name is read for those partitions 
from the base table -- for a table the mapping does not mention at all, that is 
every partition the query uses of it -- and the plan's MV partitions are taken 
out, with the whole of the query's partitions read from the base, only when the 
MV's refresh snapshot records one of them, which is the case that would count 
its rows twice. So a table the mapping leaves out whole is answered from the 
base rather than from the MV alone.
   
   Covered by 
`PartitionCompensatorTest#testCalcInvalidPartitionsCompensatesATableTheMappingDoesNotMention`
 (a table absent from the mapping, no snapshot: its query-used partitions are 
read from the base while the other table reads only the ones the mapping does 
not name) and, end to end, by the new `uncovered_pct` case in 
`mtmv_p0/test_mtmv_base_partition_read_scope` -- your A/B shape, a two-table 
LIST(d,k) MV partitioned by `a.d` under a 2 YEAR window and grace, with the 
query on `a.d` and `b.k = 2` -- whose recorded answer holds the k = 2 group. 
The recorded-intersection branch is kept for the narrowed-window duplicates, 
and the existing two-related-tables case still reads each table's own uncovered 
partitions.
   



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