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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PartitionIncrementMaintainer.java:
##########
@@ -476,25 +498,41 @@ private boolean checkWindowPartition(Expression 
expression, PartitionIncrementCh
                     expression.collectToList(expressionTreeNode -> 
expressionTreeNode instanceof WindowExpression);
             for (Object windowExpressionObj : windowExpressions) {
                 WindowExpression windowExpression = (WindowExpression) 
windowExpressionObj;
-                List<Expression> partitionKeys = 
windowExpression.getPartitionKeys();
-                Set<Column> originalPartitionbyExprSet = new HashSet<>();
-                partitionKeys.forEach(groupExpr -> {
-                    if (groupExpr instanceof SlotReference && 
groupExpr.isColumnFromTable()) {
-                        originalPartitionbyExprSet.add(((SlotReference) 
groupExpr).getOriginalColumn().get());
-                    }
-                });
-                Set<SlotReference> contextPartitionColumnSet = 
getPartitionColumnsToCheck(context);
-                if (contextPartitionColumnSet.isEmpty()) {
-                    return false;
-                }
-                if (contextPartitionColumnSet.stream().noneMatch(
-                        partition -> 
originalPartitionbyExprSet.contains(partition.getOriginalColumn().get()))) {
+                if 
(!checkPartitionKeysContainPartitionToCheck(windowExpression.getPartitionKeys(),
 context)) {
                     return false;
                 }
             }
             return true;
         }
 
+        private boolean 
checkPartitionKeysContainPartitionToCheck(List<Expression> partitionKeys,
+                PartitionIncrementCheckContext context) {
+            Set<Column> originalPartitionByExprSet = new HashSet<>();
+            partitionKeys.forEach(partitionKey -> {
+                if (partitionKey instanceof SlotReference && 
partitionKey.isColumnFromTable()) {
+                    originalPartitionByExprSet.add(((SlotReference) 
partitionKey).getOriginalColumn().get());
+                }
+            });
+            Set<SlotReference> contextPartitionColumnSet = 
getPartitionColumnsToCheck(context);
+            if (contextPartitionColumnSet.isEmpty()) {
+                return false;
+            }
+            return contextPartitionColumnSet.stream().anyMatch(
+                    partition -> 
originalPartitionByExprSet.contains(partition.getOriginalColumn().get()));

Review Comment:
   [P1] Preserve table identity when matching partition keys
   
   A reduced reachable plan is:
   ```
   Project(l.p, rn)
     Filter(rn = 1)
       Window(row_number() OVER (PARTITION BY r.p ORDER BY l.score DESC))
         PartitionTopN(partitionKeys=[r.p], limit=1)
           CrossJoin(Scan l, Scan r)
   ```
   If `l.p` and `r.p` are identically defined, catalog `Column.equals` treats 
them as equal because it compares column attributes but not the owning table. 
Both new output gates therefore run for tracked `l.p`, yet this `contains` 
check accepts `r.p` as the partition key. `CreatePartitionTopNFromWindow` 
creates this shape for `rn = 1`; before this change the PartitionTopN was 
rejected as unsupported. A higher-scored `l` row in partition A can then 
displace the stored winner from partition B inside an `r.p` group, and 
refreshing only A leaves B's old row stale. Please use lineage-aware 
Slot/equality-class identity or include the owning table in the column 
comparison, and add a same-schema unrelated-table negative case.
   



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