hello-stephen commented on code in PR #70289:
URL: https://github.com/apache/doris/pull/70289#discussion_r4737013650


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PartitionIncrementMaintainer.java:
##########
@@ -770,15 +777,22 @@ public static final class PartitionIncrementCheckContext {
         public PartitionIncrementCheckContext(NamedExpression 
mvPartitionColumn,
                 Expression mvPartitionExpression, Map<CTEId, Plan> 
producerCteIdToPlanMap,
                 Plan originalPlan,
-                CascadesContext cascadesContext) {
+                CascadesContext cascadesContext, 
Predicate<RelatedTableColumnInfo> partitionLineageCheck) {
             this.partitionAndRefExpressionMap.put(mvPartitionColumn, 
RelatedTableColumnInfo.of(
                     mvPartitionColumn, mvPartitionExpression, true, false));
             this.cascadesContext = cascadesContext;
             this.producerCteIdToPlanMap = producerCteIdToPlanMap;
             this.originalPlan = originalPlan;
+            this.partitionLineageCheck = partitionLineageCheck;
             this.expressionRewriteContext = new 
ExpressionRewriteContext(cascadesContext);
         }
 
+        public boolean hasCompatiblePartitionLineage() {
+            return partitionLineageCheck == null || 
partitionAndRefExpressionMap.values().stream()

Review Comment:
   [P1] Validate CTE lineages before collapsing their source slots
   
   This predicate can miss an incompatible lineage that was overwritten 
earlier. For a range-partitioned DUP source `s(dt DATETIME NOT NULL, v 
VARCHAR(10))`, create a view with:
   ```sql
   WITH c AS (
     SELECT date_trunc(dt, 'day') AS m,
            date_trunc(dt, 'day') AS d, v FROM s
   )
   SELECT a.d AS q, a.v FROM c a JOIN c b ON a.d = b.m
   ```
   Create an AUTO-refresh `PARTITION BY(q)` MV selecting `q,v` from that view, 
then ALTER the view so only `m` uses MONTH. The reduced source-inferred plan is:
   ```text
   Producer c: Project(m#2=MONTH(dt#0), d#3=DAY(dt#0), v#1) Scan(s)
   Project(q=a.d, a.v)
     Join(a.d=b.m)
       Consumer(c a)  Consumer(c b)
   ```
   `visitLogicalJoin` tracks both equal consumer slots. On the second producer 
visit, `checkPartition` expands `m` and `d` and repeatedly puts the same `dt` 
key; scan-first, m-before-d binding order leaves DAY last. The computed 
producer aliases lack catalog-column metadata, so this predicate checks only 
the surviving DAY entry. The source set also remains `{s.dt}`, allowing 
recovery where the old path rejects the missing output `dt`.
   
   A Jan20 source change through `b` can now change `q=Jan1`, while the stored 
DAY partition mapping checks Jan20; Jan1 can remain stale. Validate every 
lineage before the shared-slot overwrite, or retain separate consumer 
provenance until validation, and add this ALTER VIEW case. This trace is from 
source inspection; no runtime reproduction was run.



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