morrySnow commented on code in PR #61176:
URL: https://github.com/apache/doris/pull/61176#discussion_r3056207266


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropConstraintCommand.java:
##########
@@ -72,8 +79,26 @@ public void run(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
                     + "falling back to name-based lookup: {}", name, 
e.getMessage());
             tableNameInfo = extractTableNameFromPlan(ctx);
         }
-        Env.getCurrentEnv().getConstraintManager().dropConstraint(
-                tableNameInfo, name, false);
+        Constraint constraint = 
Env.getCurrentEnv().getConstraintManager().getConstraint(tableNameInfo, name);
+        if (constraint == null) {
+            throw new AnalysisException(
+                    String.format("Unknown constraint %s on table %s.", name, 
tableNameInfo));
+        }
+        List<BaseTableInfo> baseTables = new ArrayList<>();
+        baseTables.add(new BaseTableInfo(tableNameInfo));
+        if (constraint instanceof ForeignKeyConstraint) {
+            TableNameInfo referencedTableInfo = ((ForeignKeyConstraint) 
constraint).getReferencedTableName();
+            if (referencedTableInfo != null) {
+                baseTables.add(new BaseTableInfo(referencedTableInfo));
+            }
+        } else if (constraint instanceof PrimaryKeyConstraint) {
+            for (TableNameInfo fk : ((PrimaryKeyConstraint) 
constraint).getForeignTableInfos()) {
+                baseTables.add(new BaseTableInfo(fk));
+            }
+        }
+        List<MTMV> dependentMtmvs = 
MTMVUtil.getDependentMtmvsByBaseTables(baseTables);
+        
Env.getCurrentEnv().getConstraintManager().dropConstraint(tableNameInfo, name, 
false);
+        dependentMtmvs.forEach(MTMV::invalidateRewriteCache);

Review Comment:
   how affect cache on follower fe? i think you should do this cache invalid 
action in replay xxxx? 



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