use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class MergeHavingFilter method optimize.
/**
* merge having to where if it can be merged
*
* @param qtn
*/
public static void optimize(PlanNode qtn) {
if (qtn.getHavingFilter() != null) {
List<Item> subFilters = FilterUtils.splitFilter(qtn.getHavingFilter());
List<Item> canMergeSubs = new ArrayList<>();
for (Item subFilter : subFilters) {
if (!subFilter.isWithSumFunc()) {
canMergeSubs.add(subFilter);
}
}
subFilters.removeAll(canMergeSubs);
qtn.having(FilterUtils.and(subFilters));
qtn.setWhereFilter(FilterUtils.and(qtn.getWhereFilter(), FilterUtils.and(canMergeSubs)));
}
for (PlanNode child : qtn.getChildren()) optimize(child);
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class MyOptimizer method updateReferedTableNodes.
private static List<TableNode> updateReferedTableNodes(PlanNode node) {
List<TableNode> subTables = new ArrayList<>();
for (PlanNode childNode : node.getChildren()) {
List<TableNode> childSubTables = updateReferedTableNodes(childNode);
node.getReferedTableNodes().addAll(childSubTables);
subTables.addAll(childSubTables);
}
for (ItemSubQuery subQuery : node.getSubQueries()) {
List<TableNode> childSubTables = subQuery.getPlanNode().getReferedTableNodes();
node.getReferedTableNodes().addAll(childSubTables);
subTables.addAll(childSubTables);
}
return subTables;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class ERJoinChooser method makeJoinNode.
/**
* just makeJoinNode according with wishes
*
* @param units
* @return
*/
private PlanNode makeJoinNode(List<PlanNode> units) {
PlanNode ret = units.get(0);
for (int i = 1; i < units.size(); i++) {
PlanNode tni = units.get(i);
JoinNode joinNode = new JoinNode(ret, tni);
List<ItemFuncEqual> joinFilter = makeJoinFilter(joinNode, ret, tni, true);
joinNode.setJoinFilter(joinFilter);
ret = joinNode;
}
return ret;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class ERJoinChooser method innerJoinOptimizer.
/* ------------------- left join optimizer end -------------------- */
/**
* inner join's ER, rebuild inner joi's unit
*
* @return
*/
private JoinNode innerJoinOptimizer() {
initInnerJoinUnits(jn);
if (joinUnits.size() == 1) {
return jn;
}
visitJoinOns(jn);
initJoinKeyInfo();
while (trySelListIndex < selLists.size()) {
List<JoinKeyInfo> selList = selLists.get(trySelListIndex);
JoinNode erJoinNode = tryMakeERJoin(selList);
if (erJoinNode == null) {
trySelListIndex++;
} else {
// re scanning
this.makedERJnList.add(erJoinNode);
}
}
if (makedERJnList.isEmpty())
// no er join
return jn;
List<PlanNode> others = new ArrayList<>();
// make makedErJnList at the beginning,join with ER
others.addAll(makedERJnList);
others.addAll(joinUnits);
for (int i = 0; i < others.size(); i++) {
// make up the unit which cna;t optimized and global table
PlanNode tnewOther = others.get(i);
PlanNode newT0 = joinWithGlobal(tnewOther, globals);
others.set(i, newT0);
}
// only others and globals may have node and have been tried to ER JOIN
if (globals.size() > 0) {
PlanNode globalJoin = makeJoinNode(globals);
others.add(globalJoin);
}
// others' node is the join units which can not optimize, just merge them
JoinNode ret = (JoinNode) makeJoinNode(others);
ret.setOrderBys(jn.getOrderBys());
ret.setGroupBys(jn.getGroupBys());
ret.select(jn.getColumnsSelected());
ret.setLimitFrom(jn.getLimitFrom());
ret.setLimitTo(jn.getLimitTo());
ret.setOtherJoinOnFilter(FilterUtils.and(jn.getOtherJoinOnFilter(), FilterUtils.and(otherJoinOns)));
Item unFoundSelFilter = makeRestFilter();
if (unFoundSelFilter != null)
ret.setOtherJoinOnFilter(FilterUtils.and(ret.getOtherJoinOnFilter(), unFoundSelFilter));
// and the origin where and the remain condition in selLists
ret.having(jn.getHavingFilter());
ret.setWhereFilter(jn.getWhereFilter());
ret.setAlias(jn.getAlias());
ret.setSubQuery(jn.isSubQuery());
ret.setSql(jn.getSql());
ret.setUpFields();
return ret;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class ERJoinChooser method leftJoinOptimizer.
/* ------------------- left join optimizer start -------------------- */
/**
* left join's ER is different from inner join's
* ex:t1,t2 ,if t1 left join t2 on
* t1.id=t2.id can be pushed
* < we cna't change left join's structure>
*
* @return
*/
private JoinNode leftJoinOptimizer() {
PlanNode left = jn.getLeftNode();
PlanNode right = jn.getRightNode();
if (left.type() == PlanNode.PlanNodeType.JOIN) {
left = JoinERProcessor.optimize(left);
jn.setLeftNode(left);
}
if (right.type() == PlanNode.PlanNodeType.JOIN) {
right = JoinERProcessor.optimize(right);
jn.setRightNode(right);
}
for (ItemFuncEqual filter : jn.getJoinFilter()) {
ERTable leftER = getLeftOutJoinChildER(jn, left, filter.arguments().get(0));
ERTable rightER = getLeftOutJoinChildER(jn, right, filter.arguments().get(1));
if (isErRelation(leftER, rightER)) {
jn.getERkeys().add(leftER);
}
}
return jn;
}
Aggregations