[enhance](Nereids) make getExplorationRule static (#19278)

make getExplorationRule static to avoid new ArrayList() multiple times.
This commit is contained in:
jakevin
2023-05-05 19:58:24 +08:00
committed by GitHub
parent 5c8ecfbf9c
commit 159344792f
7 changed files with 31 additions and 50 deletions

View File

@ -278,7 +278,6 @@ public class NereidsPlanner extends Planner {
CopyInResult copyInResult = cascadesContext.getMemo().copyIn(plan, null, false);
root = copyInResult.correspondingExpression.getOwnerGroup();
}
cascadesContext.getStatementContext().setDpHyp(true);
cascadesContext.pushJob(new JoinOrderJob(root, cascadesContext.getCurrentJobContext()));
cascadesContext.getJobScheduler().executeJobPool(cascadesContext);
}
@ -289,10 +288,11 @@ public class NereidsPlanner extends Planner {
* try to find best plan under the guidance of statistic information and cost model.
*/
private void optimize() {
if (!statementContext.getConnectContext().getSessionVariable().isDisableJoinReorder()
&& statementContext.getConnectContext().getSessionVariable().isEnableDPHypOptimizer()
&& statementContext.getMaxNAryInnerJoin() > statementContext.getConnectContext()
.getSessionVariable().getMaxTableCountUseCascadesJoinReorder()) {
boolean isDpHyp = statementContext.getConnectContext().getSessionVariable().enableDPHypOptimizer
|| statementContext.getMaxNAryInnerJoin() > statementContext.getConnectContext()
.getSessionVariable().getMaxTableCountUseCascadesJoinReorder();
cascadesContext.getStatementContext().setDpHyp(isDpHyp);
if (!statementContext.getConnectContext().getSessionVariable().isDisableJoinReorder() && isDpHyp) {
dpHypOptimize();
}
new CascadesOptimizer(cascadesContext).execute();

View File

@ -103,10 +103,6 @@ public class StatementContext {
isDpHyp = dpHyp;
}
public StatementBase getParsedStatement() {
return parsedStatement;
}
public ExprId getNextExprId() {
return exprIdGenerator.getNextId();
}

View File

@ -29,8 +29,8 @@ import java.util.List;
*/
public class Node {
private final int index;
private Group group;
private List<Edge> edges = new ArrayList<>();
private final Group group;
private final List<Edge> edges = new ArrayList<>();
public Node(int index, Group group) {
this.group = group;
@ -41,10 +41,6 @@ public class Node {
return edges;
}
public void replaceGroupWith(Group group) {
this.group = group;
}
public int getIndex() {
return index;
}

View File

@ -30,8 +30,8 @@ import java.util.List;
/**
* This class enumerate all subgraph of HyperGraph. CSG means connected subgraph
* and CMP means complement subgraph. More details are in Dynamic Programming
* Strikes Back and Build Query Optimizer.
* and CMP means complement subgraph.
* More details are in Paper: Dynamic Programming Strikes Back and Build Query Optimizer.
*/
public class SubgraphEnumerator {
//The receiver receives the csg and cmp and record them, named DPTable in paper

View File

@ -77,14 +77,6 @@ public class PlanReceiver implements AbstractReceiver {
HyperGraph hyperGraph;
final Set<Slot> finalOutputs;
public PlanReceiver() {
throw new RuntimeException("");
}
public PlanReceiver(int limit) {
throw new RuntimeException("");
}
public PlanReceiver(JobContext jobContext, int limit, HyperGraph hyperGraph, Set<Slot> outputs) {
this.jobContext = jobContext;
this.limit = limit;
@ -179,7 +171,7 @@ public class PlanReceiver implements AbstractReceiver {
BitSet usedEdgesBitmap = new BitSet();
usedEdgesBitmap.or(usdEdges.get(left));
usedEdgesBitmap.or(usdEdges.get(right));
edges.stream().forEach(edge -> usedEdgesBitmap.set(edge.getIndex()));
edges.forEach(edge -> usedEdgesBitmap.set(edge.getIndex()));
long allReferenceNodes = getAllReferenceNodes(usedEdgesBitmap);
// check all edges

View File

@ -81,7 +81,6 @@ import org.apache.doris.nereids.rules.rewrite.logical.PushdownProjectThroughLimi
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import java.util.ArrayList;
import java.util.List;
/**
@ -168,27 +167,33 @@ public class RuleSet {
.add(OuterJoinAssocProject.INSTANCE)
.build();
public static final List<Rule> otherReorderRules = ImmutableList.<Rule>builder()
.addAll(OTHER_REORDER_RULES)
.addAll(EXPLORATION_RULES)
.build();
public static final List<Rule> ZIG_ZAG_TREE_JOIN_REORDER_RULES = ImmutableList.<Rule>builder()
.addAll(ZIG_ZAG_TREE_JOIN_REORDER)
.addAll(OTHER_REORDER_RULES)
.addAll(EXPLORATION_RULES)
.build();
public static final List<Rule> BUSHY_TREE_JOIN_REORDER_RULES = ImmutableList.<Rule>builder()
.addAll(BUSHY_TREE_JOIN_REORDER)
.addAll(OTHER_REORDER_RULES)
.addAll(EXPLORATION_RULES)
.build();
public List<Rule> getOtherReorderRules() {
List<Rule> rules = new ArrayList<>();
rules.addAll(OTHER_REORDER_RULES);
rules.addAll(EXPLORATION_RULES);
return rules;
return otherReorderRules;
}
public List<Rule> getZigZagTreeJoinReorder() {
List<Rule> rules = new ArrayList<>();
rules.addAll(ZIG_ZAG_TREE_JOIN_REORDER);
rules.addAll(OTHER_REORDER_RULES);
rules.addAll(EXPLORATION_RULES);
return rules;
return ZIG_ZAG_TREE_JOIN_REORDER_RULES;
}
public List<Rule> getBushyTreeJoinReorder() {
List<Rule> rules = new ArrayList<>();
rules.addAll(BUSHY_TREE_JOIN_REORDER);
rules.addAll(OTHER_REORDER_RULES);
rules.addAll(EXPLORATION_RULES);
return rules;
return BUSHY_TREE_JOIN_REORDER_RULES;
}
public List<Rule> getImplementationRules() {

View File

@ -612,7 +612,7 @@ public class SessionVariable implements Serializable, Writable {
private boolean checkOverflowForDecimal = false;
@VariableMgr.VarAttr(name = ENABLE_DPHYP_OPTIMIZER)
private boolean enableDPHypOptimizer = false;
public boolean enableDPHypOptimizer = false;
/**
* This variable is used to select n-th optimized plan in memo.
@ -1550,18 +1550,10 @@ public class SessionVariable implements Serializable, Writable {
this.enableNereidsPlanner = enableNereidsPlanner;
}
public boolean isEnableDPHypOptimizer() {
return isEnableNereidsPlanner() && enableDPHypOptimizer;
}
public int getNthOptimizedPlan() {
return nthOptimizedPlan;
}
public void setEnableDphypOptimizer(boolean enableDPHypOptimizer) {
this.enableDPHypOptimizer = enableDPHypOptimizer;
}
public Set<String> getDisableNereidsRules() {
return Arrays.stream(disableNereidsRules.split(",[\\s]*"))
.map(rule -> rule.toUpperCase(Locale.ROOT))