[fix](Nereids): memo skipProject() shouldn't skip NotEliminated project (#20051)
This commit is contained in:
@ -33,7 +33,6 @@ import org.apache.doris.nereids.jobs.batch.CascadesOptimizer;
|
||||
import org.apache.doris.nereids.jobs.batch.NereidsRewriter;
|
||||
import org.apache.doris.nereids.jobs.cascades.DeriveStatsJob;
|
||||
import org.apache.doris.nereids.jobs.joinorder.JoinOrderJob;
|
||||
import org.apache.doris.nereids.memo.CopyInResult;
|
||||
import org.apache.doris.nereids.memo.Group;
|
||||
import org.apache.doris.nereids.memo.GroupExpression;
|
||||
import org.apache.doris.nereids.memo.Memo;
|
||||
@ -48,7 +47,6 @@ import org.apache.doris.nereids.trees.plans.AbstractPlan;
|
||||
import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
|
||||
import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan;
|
||||
import org.apache.doris.planner.PlanFragment;
|
||||
import org.apache.doris.planner.Planner;
|
||||
@ -57,8 +55,6 @@ import org.apache.doris.planner.ScanNode;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
@ -310,25 +306,12 @@ public class NereidsPlanner extends Planner {
|
||||
cascadesContext.getJobScheduler().executeJobPool(cascadesContext);
|
||||
}
|
||||
|
||||
// DependsRules: EnsureProjectOnTopJoin.class
|
||||
private void dpHypOptimize() {
|
||||
Group root = getRoot();
|
||||
boolean changeRoot = false;
|
||||
if (root.isInnerJoinGroup()) {
|
||||
// If the root group is join group, DPHyp can change the root group.
|
||||
// To keep the root group is not changed, we add a project operator above join
|
||||
List<NamedExpression> outputs = ImmutableList.copyOf(root.getLogicalExpression().getPlan().getOutput());
|
||||
LogicalPlan plan = new LogicalProject<>(outputs, root.getLogicalExpression().getPlan());
|
||||
CopyInResult copyInResult = cascadesContext.getMemo().copyIn(plan, null, true);
|
||||
root = copyInResult.correspondingExpression.getOwnerGroup();
|
||||
Preconditions.checkArgument(copyInResult.generateNewExpression,
|
||||
"the top project node can't be generated for dpHypOptimize");
|
||||
changeRoot = true;
|
||||
}
|
||||
// Due to EnsureProjectOnTopJoin, root group can't be Join Group, so DPHyp doesn't change the root group
|
||||
cascadesContext.pushJob(new JoinOrderJob(root, cascadesContext.getCurrentJobContext()));
|
||||
cascadesContext.getJobScheduler().executeJobPool(cascadesContext);
|
||||
if (changeRoot) {
|
||||
cascadesContext.getMemo().setRoot(root.getLogicalExpression().child(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -164,10 +164,6 @@ public class GroupExpression {
|
||||
ruleMasks.set(rule.getRuleType().ordinal());
|
||||
}
|
||||
|
||||
public void setApplied(RuleType ruleType) {
|
||||
ruleMasks.set(ruleType.ordinal());
|
||||
}
|
||||
|
||||
public void propagateApplied(GroupExpression toGroupExpression) {
|
||||
toGroupExpression.ruleMasks.or(ruleMasks);
|
||||
}
|
||||
|
||||
@ -111,7 +111,8 @@ public class Memo {
|
||||
}
|
||||
|
||||
private Plan skipProject(Plan plan, Group targetGroup) {
|
||||
if (plan instanceof LogicalProject) {
|
||||
// Some top project can't be eliminated
|
||||
if (plan instanceof LogicalProject && ((LogicalProject<?>) plan).canEliminate()) {
|
||||
LogicalProject<Plan> logicalProject = (LogicalProject<Plan>) plan;
|
||||
if (targetGroup != root) {
|
||||
if (logicalProject.getOutputSet().equals(logicalProject.child().getOutputSet())) {
|
||||
@ -126,6 +127,17 @@ public class Memo {
|
||||
return plan;
|
||||
}
|
||||
|
||||
private Plan skipProjectGetChild(Plan plan) {
|
||||
if (plan instanceof LogicalProject) {
|
||||
LogicalProject<Plan> logicalProject = (LogicalProject<Plan>) plan;
|
||||
Plan child = logicalProject.child();
|
||||
if (logicalProject.getOutputSet().equals(child.getOutputSet())) {
|
||||
return skipProjectGetChild(child);
|
||||
}
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add plan to Memo.
|
||||
*
|
||||
@ -198,10 +210,6 @@ public class Memo {
|
||||
return copyOut(root, false);
|
||||
}
|
||||
|
||||
public Plan copyOut(boolean includeGroupExpression) {
|
||||
return copyOut(root, includeGroupExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* copyOut the group.
|
||||
* @param group the group what want to copyOut
|
||||
@ -335,17 +343,6 @@ public class Memo {
|
||||
}
|
||||
}
|
||||
|
||||
private Plan skipProjectGetChild(Plan plan) {
|
||||
if (plan instanceof LogicalProject) {
|
||||
LogicalProject<Plan> logicalProject = (LogicalProject<Plan>) plan;
|
||||
Plan child = logicalProject.child();
|
||||
if (logicalProject.getOutputSet().equals(child.getOutputSet())) {
|
||||
return skipProjectGetChild(child);
|
||||
}
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* add the plan into the target group
|
||||
* @param plan the plan which want added
|
||||
|
||||
Reference in New Issue
Block a user