englefly commented on code in PR #26672: URL: https://github.com/apache/doris/pull/26672#discussion_r1390579620
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java: ########## @@ -207,44 +214,97 @@ public List<Rule> buildRules() { applyPlan = subqueryToApply( subqueryExprs.stream().collect(ImmutableList.toImmutableList()), - leftChildPlan, context.getSubqueryToMarkJoinSlot(), + relatedInfoList.get(i) == RelatedInfo.RelatedToLeft ? leftChildPlan : rightChildPlan, + context.getSubqueryToMarkJoinSlot(), ctx.cascadesContext, Optional.of(conjunct), false); - leftChildPlan = applyPlan; + if (relatedInfoList.get(i) == RelatedInfo.RelatedToLeft) { + leftChildPlan = applyPlan; + } else { + rightChildPlan = applyPlan; + } newConjuncts.add(conjunct); } List<Expression> simpleConjuncts = joinConjuncts.get(false); if (simpleConjuncts != null) { newConjuncts.addAll(simpleConjuncts); } Plan newJoin = join.withConjunctsChildren(join.getHashJoinConjuncts(), - newConjuncts.build(), applyPlan, join.right()); + newConjuncts.build(), leftChildPlan, rightChildPlan); return newJoin; })) ); } - private static boolean isValidSubqueryConjunct(Expression expression, Plan leftChild) { - // the subquery must be uncorrelated subquery or only correlated to the left child - // currently only support the following 4 simple scenarios - // 1. col ComparisonPredicate subquery - // 2. col in (subquery) - // 3. exists (subquery) - // 4. col1 ComparisonPredicate subquery or xxx (no more subquery) - List<Slot> slots = leftChild.getOutput(); - if (expression instanceof ComparisonPredicate && expression.child(1) instanceof ScalarSubquery) { - ScalarSubquery subquery = (ScalarSubquery) expression.child(1); - return slots.containsAll(subquery.getCorrelateSlots()); - } else if (expression instanceof InSubquery) { - return slots.containsAll(((InSubquery) expression).getCorrelateSlots()); - } else if (expression instanceof Exists) { - return slots.containsAll(((Exists) expression).getCorrelateSlots()); - } else { + private static boolean isValidSubqueryConjunct(Expression expression) { + // only support 1 subquery expr in the expression + // don't support expression like subquery1 or subquery2 + return expression.collectToList(SubqueryExpr.class::isInstance).size() == 1; + } + + private enum RelatedInfo { Review Comment: RelatedInfo 这个名字看不出是什么意思。correlatedType 是不是合适一些? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java: ########## @@ -207,44 +214,97 @@ public List<Rule> buildRules() { applyPlan = subqueryToApply( subqueryExprs.stream().collect(ImmutableList.toImmutableList()), - leftChildPlan, context.getSubqueryToMarkJoinSlot(), + relatedInfoList.get(i) == RelatedInfo.RelatedToLeft ? leftChildPlan : rightChildPlan, + context.getSubqueryToMarkJoinSlot(), ctx.cascadesContext, Optional.of(conjunct), false); - leftChildPlan = applyPlan; + if (relatedInfoList.get(i) == RelatedInfo.RelatedToLeft) { + leftChildPlan = applyPlan; + } else { + rightChildPlan = applyPlan; + } newConjuncts.add(conjunct); } List<Expression> simpleConjuncts = joinConjuncts.get(false); if (simpleConjuncts != null) { newConjuncts.addAll(simpleConjuncts); } Plan newJoin = join.withConjunctsChildren(join.getHashJoinConjuncts(), - newConjuncts.build(), applyPlan, join.right()); + newConjuncts.build(), leftChildPlan, rightChildPlan); return newJoin; })) ); } - private static boolean isValidSubqueryConjunct(Expression expression, Plan leftChild) { - // the subquery must be uncorrelated subquery or only correlated to the left child - // currently only support the following 4 simple scenarios - // 1. col ComparisonPredicate subquery - // 2. col in (subquery) - // 3. exists (subquery) - // 4. col1 ComparisonPredicate subquery or xxx (no more subquery) - List<Slot> slots = leftChild.getOutput(); - if (expression instanceof ComparisonPredicate && expression.child(1) instanceof ScalarSubquery) { - ScalarSubquery subquery = (ScalarSubquery) expression.child(1); - return slots.containsAll(subquery.getCorrelateSlots()); - } else if (expression instanceof InSubquery) { - return slots.containsAll(((InSubquery) expression).getCorrelateSlots()); - } else if (expression instanceof Exists) { - return slots.containsAll(((Exists) expression).getCorrelateSlots()); - } else { + private static boolean isValidSubqueryConjunct(Expression expression) { + // only support 1 subquery expr in the expression + // don't support expression like subquery1 or subquery2 + return expression.collectToList(SubqueryExpr.class::isInstance).size() == 1; + } + + private enum RelatedInfo { Review Comment: RelatedInfo 这个名字看不出是什么意思。correlatedType 是不是合适一些? -- 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