seawinde commented on code in PR #27922: URL: https://github.com/apache/doris/pull/27922#discussion_r1416996014
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java: ########## @@ -53,54 +61,80 @@ protected List<Plan> rewrite(Plan queryPlan, CascadesContext cascadesContext) { if (materializationContexts.isEmpty()) { return rewriteResults; } - StructInfo queryStructInfo = extractStructInfo(queryPlan, cascadesContext); - // Check query queryPlan + + List<StructInfo> queryStructInfos = extractStructInfo(queryPlan, cascadesContext); + // TODO Just Check query queryPlan firstly, support multi later. + StructInfo queryStructInfo = queryStructInfos.get(0); if (!checkPattern(queryStructInfo)) { return rewriteResults; } for (MaterializationContext materializationContext : materializationContexts) { - Plan mvPlan = materializationContext.getMvPlan(); - StructInfo viewStructInfo = extractStructInfo(mvPlan, cascadesContext); - if (!checkPattern(viewStructInfo)) { + // already rewrite, bail out + if (queryPlan.getGroupExpression().isPresent() + && materializationContext.alreadyRewrite( + queryPlan.getGroupExpression().get().getOwnerGroup().getGroupId())) { continue; } - if (!StructInfo.isGraphLogicalEquals(queryStructInfo.getHyperGraph(), viewStructInfo.getHyperGraph())) { + Plan mvPlan = materializationContext.getMtmv().getMvCache().getLogicalPlan(); + List<StructInfo> viewStructInfos = extractStructInfo(mvPlan, cascadesContext); + if (viewStructInfos.size() > 1) { + // view struct info should only have one + return rewriteResults; + } + StructInfo viewStructInfo = viewStructInfos.get(0); + if (!checkPattern(viewStructInfo)) { continue; } MatchMode matchMode = decideMatchMode(queryStructInfo.getRelations(), viewStructInfo.getRelations()); - if (MatchMode.NOT_MATCH == matchMode) { + if (MatchMode.COMPLETE != matchMode) { continue; } List<RelationMapping> queryToViewTableMappings = RelationMapping.generate(queryStructInfo.getRelations(), viewStructInfo.getRelations()); + if (queryToViewTableMappings == null) { + return rewriteResults; + } for (RelationMapping queryToViewTableMapping : queryToViewTableMappings) { + SlotMapping queryToViewSlotMapping = SlotMapping.generate(queryToViewTableMapping); + if (queryToViewSlotMapping == null) { + continue; + } + LogicalCompatibilityContext compatibilityContext = + LogicalCompatibilityContext.from(queryToViewTableMapping, queryToViewSlotMapping, + queryStructInfo, viewStructInfo); + // todo outer join compatibility check + if (!StructInfo.isGraphLogicalEquals(queryStructInfo, viewStructInfo, compatibilityContext)) { + continue; + } SplitPredicate compensatePredicates = predicatesCompensate(queryStructInfo, viewStructInfo, - queryToViewTableMapping); + queryToViewSlotMapping); // Can not compensate, bail out - if (compensatePredicates == null || compensatePredicates.isEmpty()) { + if (compensatePredicates.isEmpty()) { Review Comment: if the same, the compensatePredicates will be always true. call this method `org.apache.doris.nereids.rules.exploration.mv.Predicates.SplitPredicate#isAlwaysTrue` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org