jackwener commented on code in PR #13353: URL: https://github.com/apache/doris/pull/13353#discussion_r994749989
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/ReorderJoin.java: ########## @@ -37,21 +56,296 @@ * SELECT * FROM t1 JOIN t3 ON t1.id=t3.id JOIN t2 ON t2.id=t3.id * </pre> * </p> - * TODO: This is tested by SSB queries currently, add more `unit` test for this rule - * when we have a plan building and comparing framework. + * Using the {@link MultiJoin} to complete this task. + * {Join cluster}: contain multiple join with filter inside. + * <ul> + * <li> {Join cluster} to MultiJoin</li> + * <li> MultiJoin to {Join cluster}</li> + * </ul> */ public class ReorderJoin extends OneRewriteRuleFactory { @Override public Rule build() { return logicalFilter(subTree(LogicalJoin.class, LogicalFilter.class)).thenApply(ctx -> { LogicalFilter<Plan> filter = ctx.root; - if (!ctx.cascadesContext.getConnectContext().getSessionVariable() - .isEnableNereidsReorderToEliminateCrossJoin()) { - return filter; - } - MultiJoin multiJoin = new MultiJoin(); - filter.accept(multiJoin, null); - return multiJoin.reorderJoinsAccordingToConditions().orElse(filter); + + MultiJoin multiJoin = (MultiJoin) joinToMultiJoin(filter); + Plan plan = multiJoinToJoin(multiJoin); + return plan; }).toRule(RuleType.REORDER_JOIN); } + + /** + * Recursively convert to + * {@link LogicalJoin} or + * {@link LogicalFilter}--{@link LogicalJoin} + * --> {@link MultiJoin} + */ + public Plan joinToMultiJoin(Plan plan) { Review Comment: shouldn't, it's not common function -- 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